Maria Butina is accused of conspiracy and failing to register as a foreign agent. (AP)

A federal judge on Monday blasted U.S. prosecutors and defense attorneys during a hearing in which the defense sought to have a Russian woman freed on bail pending trial on charges she was a foreign agent attempting to infiltrate the National Rifle Association and other American conservative groups .

In ordering continued detention for Maria Butina, 29, U.S. District Judge Tanya S. Chutkan said Butina remained a serious flight risk.

Chutkan also imposed a gag order after slamming prosecutors for their mistaken claim in court filings that Butina traded sex for access and her defense for repeated public statements that the judge said could bias potential jurors.

Butina has pleaded not guilty after being indicted July 17 on charges of conspiracy to act and failing to register as an agent of a foreign government. Her defense said she was merely networking to develop relationships with Americans. She is jailed in Alexandria, Va.

“I cannot envision any scenario where it is not possible . . . for Ms. Butina to walk out of jail, be put in a car with diplomatic tags and taken to an airport.,” Chutkan said. “Risk of flight — that is this court’s primary concern in reviewing this bail motion.”

Butina, in green prison garb, did not speak at the hearing.

Chutkan told both sides not to try the case in the news media.

In a measured tone before a packed but silent courtroom, Chutkan excoriated prosecutors with the U.S. attorney’s office of the District and the Justice Department’s national security division for opening the case with a “salacious” and “notorious” claim that Butina at least once offered sex in exchange “for a position with a special interest organization,” which the government admitted in a late-night filing Friday was based on a misreading of three-year-old text messages.

“It took me five minutes to review the evidence and tell they were joking. It was apparent on their face,” in the texts between Butina and another person, Chutkan said, saying she was “dismayed” that “someone at the U.S. attorney’s office or at the Department of Justice could look at those exchanges and conclude they were serious.”

While crediting the government with taking back the allegation, she warned assistant U.S. attorneys Erik M. Kenerson and Thomas N. Saunders, “It could make it difficult to have a fair trial when these mistakes are made.”

Chutkan then blasted Butina’s attorney for giving interviews opining on his client’s innocence and publicly characterizing evidence. The exchanges, the judge noted, violated court rules that bar attorneys from making public statements that could prejudice potential jurors.

“You’re going all over the networks giving explanations for the evidence in this case,” Chutkan said icily to Butina attorney Robert N. Driscoll. “I don’t think you’re going to be a witness in this case.”

The judge noted that Driscoll named a potential witness, discussed financial transactions between Butina and alleged associates, described government surveillance, falsely claimed that the government made a concession when it had not, and purported to speak for Butina in public, potentially biasing jurors without opportunity for cross-examination.

Chutkan went on to quote what she called “very inflammatory” language from defense filings that accused prosecutors of “desperation,” “cowardice” and “a craven willingness” to mislead that was “frankly shocking.”

“I’m not sure if the language is designed to affect my deliberation, but it is quite colorful,” the judge said.

After denying bail and imposing the gag order in a 45-minute hearing in which she spoke more than the attorneys, Chutkan set another hearing in the case for Nov. 13.

Butina had asked to be freed on bond because she has U.S. ties in her longtime relationship with Paul Erickson, a South Dakota-based Republican consultant she met in Moscow in 2013 and with whom she has been romantically linked.

Butina spent two years at American University in the global security program at the School of International Service and received a master’s degree in May.

Driscoll argued in a filing last month that the now-withdrawn allegation was a “sexist smear” that created the false impression Butina used sex as a spy tool. His filing said the allegation had been featured prominently in news coverage around the world, including on television in Siberia, where Butina’s parents live

Driscoll said the allegation was based on an erroneous interpretation of a playful text exchange between Butina and a married, longtime friend who does public relations work for a Russian gun rights group Butina founded.

Prosecutors had cited the messages in asking that she be held because, they argued, her romantic relationship with Erickson, 56, was “duplicitous.”

Prosecutors said their mistake should not undermine the gravity of the government’s overall case.

The case is not part of the special counsel’s investigation into Russian interference in the 2016 presidential election, but experts said it demonstrates the scale and scope of Russian efforts to influence U.S. politics.

Butina is accused of trying to cultivate “back-channel” relationships with the Republican Party’s leading presidential candidates and develop close ties to the NRA to provide Russian officials “with the best access to and influence over” the party.

Butina allegedly was assisted by Erickson, who helped introduce her to influential political figures and who sought to organize a meeting between then-candidate Donald Trump and Alexander Torshin, Butina’s colleague and a Russian central banker, at a May 2016 NRA convention.

In arguing on Friday that Butina should continue to be detained, prosecutors provided additional evidence that they said shows Torshin coordinated Butina’s activities, writing that at his direction, she drafted language to persuade the Russian foreign ministry to let him attend the NRA meeting as a “unique opportunity” to network with Trump and his entourage.

The campaign declined a request by Erickson to have Trump meet with Torshin as Russian President Vladi­mir Putin’s emissary, but Torshin and Butina briefly interacted with Donald Trump Jr. at a dinner.