A federal judge gave Tesla CEO Elon Musk and the Securities and Exchange Commission two weeks to work out their differences, punting a request from the agency to hold him in contempt of court for allegedly violating an October securities fraud settlement. Musk told reporters he was "happy" and "impressed with the judge's analysis" as he left the hearing room in the U.S. District Court for the Southern District of New York on Thursday. U.S Judge Alison Nathan said she had "serious concerns that no matter what I decide here, this issue won't be resolved." Nathan ordered both parties to "take a deep breath, put on your reasonableness pants" and work out a solution. Musk was at the hearing on contempt charges requested by the SEC after he tweeted about the company's production forecasts on Feb 19. His settlement agreement prohibits him from using Twitter to make statements about Tesla's operations or financial position without company review and approval. Nathan told Musk and the SEC that contempt charges are serious business. Everyone must follow the law, she said, whether you are a "small potato" or a "big fish." Musk told reporters outside the courthouse that he would "most likely" be able to work out an agreement with the SEC over the next two weeks.

Elon Musk, chief executive officer of Tesla Inc., smiles while speaking to members of the media outside federal court in New York, U.S., on Thursday, April 4, 2019. Natan Dvir | Bloomberg | Getty Images

"I have great respect for the justice system and I think the judges in the American system are outstanding," Musk said before entering the courthouse in lower Manhattan. When CNBC's Phil LeBeau asked Musk if he felt the same about the SEC, the CEO laughed and walked away. SEC lawyers argued that Musk and his legal team offered a "series of shifting justifications" for his behavior on Twitter, citing 15 separate tweets they believe violated his settlement. They also accused Musk of "recklessly tweeting out material information that had no basis in fact" and caused confusion in the markets. "We don't think every tweet needs to be approved," SEC attorney Cheryl Crumpton told the court, citing conversations on social media with Tesla customers as OK. Statements much beyond that need to be cleared, she said. Reaffirming guidance could be material and needs approval, she said, adding that Tesla still "appears to be unwilling" to exercise control over Musk. Musk's lawyers said the judge's order was a gateway to a negotiation with the SEC. "He actually does what he is told," Musk's lead attorney John Hueston told the court. Musk sat in the center of the courtroom, flanked by three members of his legal team, periodically nodding in agreement with their arguments. Securities lawyers and other industry executives have said that Musk, who has already been removed as chairman, could also lose his post as CEO if he keeps pushing the SEC.

Elon Musk, chief executive officer of Tesla Inc., center, arrives at federal court in New York, on Thursday, April 4, 2019. Jeenah Moon | Bloomberg | Getty Images