AI Security
Researchers Expose Cache-Based Backdoor Attack on AI Agent Security Tools
A new vulnerability allows malicious Python packages to bypass security scanners by hiding dangerous code in compiled bytecode caches while keeping source code clean.
Security researchers have uncovered a critical gap in how tools scan AI agent skills—third-party packages that give systems access to sensitive runtime capabilities. The attack, dubbed PyCache Trap, exploits the difference between what security scanners inspect and what Python actually executes.
The Vulnerability#
Agent skills bundle instructions with executable resources, allowing external packages to interact with an AI system's runtime environment. Current security tools examine documentation and visible source code to determine whether a skill is trustworthy. However, Python can execute a compiled bytecode cache (.pyc files) that may contain entirely different behavior than the source code—and most scanners never check these cached versions.
The researchers demonstrated that an attacker can pair benign, clean source code with a malicious substituted cache file that a Python loader will accept and run. When security scanners inspect the visible source, they see nothing suspicious and approve the package. But when the code runs, the hidden bytecode executes the attacker's instructions instead.
Attack Success and Impact#
Testing across 100 agent skills and seven different security scanners, PyCache Trap achieved 94–100% success rates at evading detection. The scanners showed no semantic recognition of the dangerous behavior embedded in the cache files. Additionally, scanner-guided rewriting—changing how an invocation is worded while keeping the cache payload intact—further separated package admission from recognition of concealed activity.
A Proposed Solution#
To address this gap, the researchers propose Execution-Aware Validation (EAV), which connects inspected instructions, scripts, imports, and runtime artifacts into a typed execution graph. EAV combines behavioral analysis grounded in actual code behavior with trusted reproduction of compiled artifacts.
When tested against their attack families, EAV detected all 100 source-present cache substitutions. Across a broader evaluation of five attack families and 200 benign skills, the approach achieved 92.8% recall at a 10% false-positive rate—a significant improvement over existing tools.
