The AI Agents Meant to Protect Us Can Be Turned Against Us
Ask an AI coding agent to scan open-source code for security holes, and it might run the attacker’s code on your own machine instead. That’s the unsettling finding from a new proof-of-concept published Wednesday by the AI Now Institute. The attack, dubbed “Friendly Fire,” targets Anthropic‘s Claude Code and OpenAI‘s Codex — two of the most widely used AI coding agents — when either is running in an autonomous mode that approves its own actions.
The core issue isn’t that these tools are poorly built. It’s that they’re too trusting — of the code they analyze and of themselves. When a developer asks an AI coding agent to review a third-party library or a pull request for vulnerabilities, the agent might execute commands embedded in the very code it’s supposed to inspect. Attackers can craft malicious snippets that look like harmless code but contain hidden instructions for the AI to run.
How the Friendly Fire Attack Works
The attack exploits a fundamental design flaw in autonomous coding agents. These agents operate by reading code, analyzing it for security issues, and then — crucially — executing actions based on that analysis. In autonomous mode, they don’t stop to ask a human for permission before running a command. So if the code under review contains a carefully disguised instruction like a shell command or a hidden API call, the agent runs it without a second thought.
The AI Now Institute demonstrated this with Claude Code and Codex. In their tests, they embedded malicious payloads inside seemingly benign open-source packages. When the agents scanned these packages for vulnerabilities, they triggered the payloads — effectively compromising their own host environment. The attack doesn’t require sophisticated social engineering. It’s a simple bait-and-switch: hide a dangerous command inside code that looks safe to review.
“The agent doesn’t distinguish between code it should analyze and code it should execute,” the researchers noted in their paper. “It treats all code as equally trustworthy.”
Why Autonomous Mode Is the Problem
Autonomous mode is a feature, not a bug — at least from the developer’s perspective. It lets Claude Code and Codex work through long tasks without constant hand-holding. You ask it to audit a codebase, and it plows through hundreds of files, flagging issues and even suggesting fixes. That speed is what makes these tools valuable.
But speed comes at a cost. In autonomous mode, the agent approves its own actions. It doesn’t ask, “Hey, should I run this command?” It just runs it. That’s fine when the code is clean. But when the code is malicious, the agent becomes an unwitting accomplice. The attacker doesn’t need to break into your system; they just need to trick the tool you trust into doing it for them.
The researchers point out that this isn’t a theoretical risk. Open-source code is the backbone of modern software development, and developers regularly use AI coding agents to scan it for flaws. If an attacker can poison a popular package — or even a single pull request — with a payload that targets these agents, they can compromise every machine that scans it.
Both Anthropic and OpenAI Have Been Notified
The AI Now Institute says it responsibly disclosed the vulnerability to both Anthropic and OpenAI before publishing the proof-of-concept. As of now, neither company has released a patch or a public statement addressing the specific attack. The researchers note that the issue isn’t limited to these two tools — any AI coding agent running in an autonomous mode that executes code from the input could be vulnerable.
Claude Code and Codex are the most prominent examples, but the attack pattern likely applies to other agents that follow similar design principles. The researchers recommend that developers avoid using autonomous mode when scanning untrusted code. If you must use it, they suggest running the agent in a sandboxed environment with no network access and limited file system permissions.
“The safest approach is to never let an AI agent execute code it’s analyzing,” the paper states. “Treat all external code as hostile until proven otherwise.”
What Developers Can Do Right Now
Until the companies roll out fixes, developers have a few options to protect themselves:
- Disable autonomous mode when scanning code from unknown sources. Require explicit human approval for every action.
- Run AI coding agents in isolated environments — containers, virtual machines, or sandboxes with restricted permissions.
- Audit the agent’s actions manually before approving them. Don’t trust the agent’s judgment blindly.
- Use static analysis tools that don’t execute code as part of their workflow. Traditional linters and vulnerability scanners don’t have this problem.
None of these are perfect solutions. Disabling autonomous mode defeats the purpose of using AI agents for speed. Running them in sandboxes adds overhead. But for now, it’s the best defense available. The Friendly Fire attack is a reminder that AI security flaws aren’t just about models hallucinating or leaking data — they can also turn your tools into weapons.
The broader lesson is that AI coding agents need a fundamental redesign. They should treat code as data, not as commands. They should never execute code they’re analyzing unless explicitly instructed to — and even then, only with human oversight. Until that happens, every developer using Claude Code or Codex in autonomous mode is one malicious pull request away from a compromised machine.
“We built these tools to help us write safer code,” the researchers conclude. “But we forgot to make them safe themselves.”