His comments came in response to reports that China's military had banned Tesla cars from its facilities.
The military had raised security concerns about the data collected by cameras installed in the cars.
China is Tesla's largest market after the US, accounting for about a quarter of the firm's global sales in 2020.
On Saturday, Mr Musk said if a business did engage in spying on a foreign government, "the negative effects for that company would be extremely bad".
"There's a very strong incentive for us to be very confidential with any information," Mr Musk told an influential Chinese business forum via video link. "If Tesla used cars to spy in China or anywhere, we will get shut down."
There has long been unease about the presence of big American companies operating in China and vice versa.
Relations between China and the US - the world's biggest two economies - are at their most strained for years.
Earlier this week, officials from both countries traded angry words in the first high-level talks between the Chinese government and the administration of US President Joe Biden.
Mr Musk urged greater mutual trust between China and the US, where Tesla is based in California.
He sought to downplay concerns over companies sharing sensitive data with their home governments, referencing the case of the Chinese-owned video platform TikTok.
Last year, former President Donald Trump threatened to ban TikTok in the US over concerns that users' data could be handed over to the Chinese government.
"Even if there was spying, what would the other country learn and would it actually matter?," Mr Musk said.
Elon Musk's car firm won approval for its Shanghai factory in 2018, becoming the first foreign automaker to operate a wholly owned plant in China.
China is the world's largest car market and its government has been heavily promoting the adoption of electric vehicles. This demand helped Tesla make a profit of $721m (£519m) in 2020.