KIEV, Ukraine – On a morning earlier this year, Ukraine’s top intelligence officials woke up to discover that the country's spy agency had been ransacked and torched by intruders who seemed to know what they were looking for.

The previous night, it turned out, the country’s pro-Russian president, Viktor Yanukovych, had ordered his operatives to steal a trove of state secrets from Ukraine's Security Service, known as the SBU, before fleeing to Moscow on Feb. 22.

During their raid on the spy agency, the thieves also stole data on more than 22,000 officers and informants as well as anything documenting decades of cooperation between the SBU and its Russian counterpart, the Federal Security Service, or FSB.

What the burglars weren't able to carry, they burned or destroyed. In the ruins of the offices, scorched files and empty folders lay strewn on the floors.

“Every hard drive and flash drive was destroyed — smashed with hammers,” said one current Ukrainian intelligence official recently. By the time he and his colleagues got there, "it was all ash and dust."

For a country in the shadow of Russia and embarking on an uncertain path toward democracy, the break-in was devastating.

As the current SBU director Valentyn Nalyvaichenko put it, the thieves took “everything that forms a basis for a professional intelligence service."

Head of the Security Service of Ukraine Valentyn Nalyvaichenko gives a press conference in Kiev on March 11, 2014. Image: SERGEI SUPINSKY/AFP/Getty Images

Just days after the break-in, the director of the intelligence service, Oleksandr Yakymenko, surfaced in Russia, having defected with four other top spies and a dozen or so subordinates loyal to Moscow.

In the following weeks and months, the security service was thrown into turmoil as the agents' new allegiances played out. After the Russian invasion of Crimea, thousands of Ukrainian spies switched sides and began reporting to Moscow. Similarly, as the Kremlin-backed insurgency took off in eastern Ukraine, dozens of Ukrainian agents there became agents of the Kremlin.

“We have no idea who we can trust right now,” said a top SBU spy, still loyal to the government in Kiev. "Everybody is suspicious of everybody."

When Nalyvaichenko became the SBU’s new chief on Feb. 24, he inherited a spy agency already riddled with spies. According to him, as many as one in five SBU agents had either worked for the Soviet KGB or studied at its training academy.

Even as Ukraine was in the midst of pro-democracy protests, a team of 30 Russian agents from the FSB came to Ukraine to meet with Yakymenko, allegedly to discuss assisting his officers in quashing the civil uprising.

Since then, the SBU has sought to root out pro-Russian spooks among its ranks.

Documents accompanying an illicit shipment of weapons suggest they came from Russian-occupied Crimea at the behest of Ukraine's ex-spy chief Oleksandr Yakymenko.

So far, 235 agents, including the former counterintelligence chief and his cousin, and hundreds of other operatives believed to be working for Moscow, have been arrested and 25 high treason probes against Yanukovych-era SBU officials have been launched. All regional directors for the agency have changed, as well as half of their deputies.

After the arrests, Nalyvaichenko boldly stated that “all traitors” have been purged from the SBU — a declaration that even the agency's own officials say they find hard to believe.

Indeed, three senior sources from within Ukraine’s security services, who agreed to be interviewed on condition of anonymity, said the thefts and mass defections had compromised SBU more severely than previously acknowledged.

Ukrainian soldiers get new tanks and other military vehicles on Dec. 6, 2014.

Many agents with ties to the Russians are “still in the business,” as one of the SBU officials said. He added, however, that these mostly dormant agents are "closely watched" by Ukraine's own security services.

Olexiy Melnyk, co-director for Foreign Relations and International Security Programs at the Kiev-based Razumkov Center, said that Nalyvaichenko's assessment is "too optimistic."

"It’s very unlikely that they got rid of all collaborators and spies," he said.

In April, as fighting raged between government forces and Kremlin-backed separatists in eastern Ukraine, the SBU started planning a secret operation for its elite tactical unit, called Alpha. An enigmatic Russian known as Igor "Strelkov" Girkin, himself a confessed former FSB agent, was commanding rebel fighters on the front lines and the Ukrainians were keen to get him.

Igor Strelkov, the top military commander of the self-proclaimed 'Donetsk People's Republic', delivers a press conference on July 28, 2014 in Donetsk, eastern Ukraine Image: BULENT KILIC/AFP/Getty Images

According to two senior Ukrainian security officials, agents had figured out that Girkin was spending time at a checkpoint on the edge of Sloviansk with several of his fighters. But no sooner had the operation gotten underway before Girkin was tipped off by a mole inside the Ukrainian security service and he slipped away.

He has since surfaced in Russia, where he has become quite the star after boasting that he "was the one who pulled the trigger of war" in Ukraine.

But sabotage and defectors are not the only challenges — the country’s security service is also hobbled by inexperience and a lack of funds, officials said.

In this photo provided by the Russian Defense Ministry, Russian Defense Minister Sergei Shoigu, left, awards a former Ukrainian special forces "Berkut" officer, back to camera, at a military base in Sevastopol, Crimea, Monday, March 24, 2014.

To overhaul the agency, the SBU has brought in scores of fresh recruits. But while the young agents come from more Kiev-friendly western regions of Ukraine, many of the recruits — who are mostly in their early twenties — have little experience. Still, the intelligence service has little choice.

“What is better, to have professional former KGB guys who probably still have more friends in [Russia] or have loyal young guys who can learn and who we can be confident he will not leak secrets to Russia?” said Melnyk.

And it may not be very hard to turn the new recruits as pay is meager — about $200 per month — and moonlighting as a Russian informant may pay "three, maybe four times more," according to one SBU officer.

To test their loyalty, new and old agents are subjected to recurrent interrogations and lie detector tests. But, as one security officer put it: “the rifle is the best lie detector.”