Weeks before he was charged with espionage, former CIA officer Kevin Mallory voluntarily went to his old co-workers and told them he had been in touch with Chinese intelligence.

On that point, both sides in the Alexandria federal court case agree. But while Mallory’s defense attorneys argue their client was trying to be helpful, prosecutors say he was trying to cover his tracks.

Mallory, 60, was arrested last week and accused of selling top secret and other classified documents to Chinese intelligence officials.

“We are here because Mr. Mallory repeatedly sought out government agents to provide information,” public defender Geremy Kamens said in a hearing Thursday. “It makes no sense, if Mr. Mallory sought to secretly betray his government. . . . These are not the actions of someone who is trying to hide. ”

Prosecutors countered that Mallory had been expecting to meet CIA officers, not FBI agents, when he sat down to a meeting in Washington in May. When he let the agents search a device given to him by Chinese operatives, they say he was surprised that the classified documents and conversations about them had not been erased.

“He tried to claim he was being cooperative, he was reaching out to people,” Assistant U.S. Attorney John Gibbs said in court. But “he lied repeatedly to the FBI.”

Left unexplained by Gibbs was Mallory’s motivation for going to the CIA. But Customs agents conducting what court documents say was a routine search upon Mallory’s return from Shanghai in April found $16,500 in his bags. Mallory had claimed not to be carrying more than $10,000. That interaction may have spooked Mallory.

Gibbs did suggest that debt led Mallory to allegedly sell secrets. He said the $25,000 paid to Mallory by the Chinese agents was his only income this year.

The Leesburg resident was let out on a $10,000 bond after the hearing, over the government’s objections. He will be monitored by GPS, is restricted in his use of the Internet and cannot leave the area without permission.

Gibbs suggested the Chinese government could help Mallory sneak out of the country.

“He understands how to . . . change identities, to leave places quickly and covertly,” Gibbs said.

A search of Mallory’s home found wigs and fake mustaches, Gibbs said, but he was cut off by Judge Ivan Davis from further discussing the search.

Members of Mallory’s church, a Chinese-speaking Mormon congregation, vouched for him in letters and came to court in support.

“Mr. Mallory is the straightest of straight arrows,” Kamens argued.