A US Secret Service agent inserted a USB drive infected with "malicious malware" into his laptop after the hardware was confiscated from a Chinese woman who was arrested late last month at Trump's Mar-a-Lago resort.

The agent testified in court on Monday that the thumb drive began installing files in a "very out-of-the-ordinary" way, and he quickly stopped his analysis of it.

Prosecutors say that the woman, Yujing Zhang, was carrying a USB drive with "malicious malware" on it, four mobile phones, a laptop, and a hard drive when she was arrested while attempting to gain entry to Trump's Palm Beach resort on March 30.

Cybersecurity experts criticized the agent's move on Monday, suggesting the USB drive could have transferred a dangerous virus onto a government device.

Visit BusinessInsider.com for more stories.

A US Secret Service agent inserted a USB drive infected with "malicious malware" into his laptop after the hardware was confiscated from a Chinese woman who was arrested late last month after attempting to gain entry to President Donald Trump's Mar-a-Lago resort.

Agent Samuel Ivanovich testified in court on Monday that he put the thumb drive into his own computer, and it began installing files in a "very out-of-the-ordinary" way. He quickly stopped his analysis of the drive, the Miami Herald reported.

The woman, Yujing Zhang, was found carrying a USB drive with "malicious malware" on it, four mobile phones, a laptop, and a hard drive when she was arrested at Trump's Palm Beach resort, law-enforcement officers said. It's still unclear what kind of malware Zhang had on the USB drive.

Read more: The Chinese woman who was arrested after gaining access to Trump's Mar-A-Lago allegedly had a hidden camera detector in her hotel room

In a search of Zhang's hotel room, law-enforcement officers also said they found a signal detector used to discover hidden cameras, $8,000 in cash, nine USB drives, and five SIM cards.

Secretary of State Mike Pompeo suggested on Friday that Zhang may be a Chinese spy.

Cybersecurity experts were critical of Ivanovich's move, suggesting that the USB drive could have transferred a dangerous virus onto a government device.

"As a taxpayer, I'm very concerned about where Agent Ivanovich's laptop is and where it's been since he plugged a malicious USB into it. If this was the Secret Service quick reaction playbook, perhaps Zhang planned to get caught all along (not joking)," tweeted Jake Williams, a cybersecurity expert and former National Security Agency hacker.

Eric Geller, a cybersecurity reporter at Politico, tweeted, "Very disturbing that Secret Service agents aren't better trained than this."

On Tuesday, business reporter Kai Ryssdal tweeted a statement from a Secret Service agent who told Ryssdal that Ivanovich's laptop was "off-network" and that he needed to test the USB drive in order to testify in court that the hardware was infected with malware.

"This was an off-network computer, dedicated for analysis, and they were expecting the drive to act maliciously," the agent reportedly wrote. "But you cannot authoritatively say it did so for court purposes until you actually do it."