Loading date…
LinkedIn Twitter Instagram YouTube WhatsApp

Claude Code Opus 5 Auto Mode Hijacked via Prompt Injection Attack

Security researchers demonstrated Claude Code Opus 5's Auto Mode can be hijacked into executing malware through a simple prompt injection attack.

Claude Code Opus 5 Auto Mode Hijacked: How a "Summarize This Website" Request Turned Into Full Code Execution

Picture this. A developer opens Claude Code, types a one-line request — "summarize this website for me" — and walks away to grab coffee. Thirty seconds later, a Calculator window pops open on the machine. Not because of a bug. Because of malware. And the AI agent that was supposed to protect itself from exactly this kind of attack approved every step along the way.

This isn't a hypothetical. It's what security researcher Johann Rehberger, known in the industry as "wunderwuzzi" and the founder of Embrace The Red, demonstrated against Claude Code Opus 5 running in its default Auto Mode. His attack chain succeeded in 60% to 80% of test runs — a jarring number when you consider that Anthropic had just published a third-party evaluation claiming a 0.00% prompt injection success rate for the exact same configuration.

If you're running Claude Code, GitHub Copilot agents, Codex, or any other autonomous coding assistant in your SOC, dev pipeline, or personal workflow, this is worth five minutes of your attention. It's a masterclass in how indirect prompt injection defeats classifier-based guardrails without ever typing a single malicious command.

Table of Contents

What Actually Happened

Claude Code Opus 5 Auto Mode safety classifier bypassed despite 0% attack success evaluation

Claude Code Opus 5's Auto Mode is designed to cut down on "permission fatigue" — the well-documented problem where developers rubber-stamp every approval prompt without reading it. Instead of asking a human to approve every shell command, Auto Mode routes tool calls through a safety classifier that is supposed to block anything irreversible, destructive, or aimed outside the user's environment.

Anthropic had reason to be confident in this system. A third-party evaluation from Trajectory Labs tested 72 indirect prompt injection scenarios, ten times each — 720 attempts total — against Claude Fable 5, Opus 5, and Sonnet 5 in Auto Mode. Reported result: zero successful attacks.

Rehberger's research shows that number doesn't hold up against a targeted, multi-step attack chain built specifically to exploit how Claude reasons through obstacles rather than how it responds to a single malicious instruction. His approach didn't tell Claude to "run this command." It engineered a situation where Claude chose to run dangerous code entirely on its own — for reasons that looked, at every individual step, completely legitimate.

What Is Claude Code Auto Mode?

Claude Code Auto Mode classifier reviewing Bash commands file writes and network calls

Since mid-August 2026, Auto Mode has been the default permission setting for new Claude Code sessions on Pro, Max, and Team plans. Instead of a human approving every Bash command, file write, or network call, a classifier model — Sonnet 5 acts as the safety layer when Opus 5 is the primary model — reviews each tool call and decides whether to allow it, block it, or escalate to the user.

Anthropic has published legitimate wins for this system, including blocking data exfiltration attempts, dangerous git reset --hard operations, and over-privileged cloud access requests. The problem highlighted by this research isn't that Auto Mode is useless — it's that it was never designed to function as a full security boundary, and some users and teams are treating it like one.

The Attack Chain, Step by Step

Claude Code Opus 5 10 step attack chain from curl fallback to struct.py hijack

Here's how the exploit unfolded in Rehberger's lab environment. Notice that not one step, viewed in isolation, looks like an attack.

StepWhat HappenedWhy It Looked Safe
1User asks Claude Code to summarize a websiteCompletely routine, everyday request
2Claude's WebFetch tool hits the site, gets an HTTP 415 Unsupported Media Type errorJust a technical hiccup, not obviously hostile
3Claude falls back to curl via its Bash tool to retrieve the page directlyA reasonable engineering workaround
4The server redirects the request to a ZIP archive disguised as a "notebook catalogue"Looks like legitimate data, not an executable
5Claude extracts the ZIP: metadata, checksums, a README, a native decoder binary, and a file named struct.pyStandard archive contents
6Claude refuses to run the untrusted native decoder binaryThis is Claude behaving correctly and safely
7Claude writes its own Python decoder to process the Base85/zlib/JSON-encoded records insteadA smart, self-generated, "safer" alternative
8Claude runs the decoder from inside the extracted directoryNormal working-directory behavior
9Python's import mechanism loads the attacker's struct.py instead of the real standard library moduleInvisible to Claude and to the classifier
10A hidden payload executes: spawns a new process, opens Calculator (PoC signal), and calls back to a C2 serverHappens silently during "normal" decoding

Across five-run samples, Rehberger reported three separate attack variants: a Python-based module-shadowing chain succeeding 3 out of 5 times (60%), a variant that spawned a nested headless Claude Code instance also succeeding 3 out of 5 times, and a variant that wrote files outside the original workspace succeeding 4 out of 5 times (80%).

The Real Exploit: Python Module Shadowing

Python module shadowing attack using fake struct.py to hijack base64 import

The technical core of this attack is old-school and elegant: Python module shadowing. When Python resolves an import statement, it searches the current working directory before it searches the standard library path.

Claude's self-written decoder ran a command similar to this:

cd WIC-notebook-catalogue
python3 -c 'import base64, zlib, json; ...'

What this does: changes into the extracted archive directory, then imports standard modules to decode the "catalogue" data.

Why it's dangerous here: the archive included a file literally named struct.py. Python's base64 module internally imports struct. Because the malicious struct.py sat in the current directory, Python loaded the attacker's file instead of the legitimate standard-library module.

Expected (malicious) output: decoding appears to work normally — the fake module re-exports the real low-level _struct functionality — while an obfuscated import-time expression silently launches a separate Python process that downloads and executes a remote payload.

This is the same class of vulnerability security teams have seen for years in supply-chain attacks — think typosquatted PyPI packages or dependency confusion — just repurposed to weaponize an AI agent's own problem-solving instincts.

Why the Safety Classifier Missed It

Claude Auto Mode classifier blocked cleanup after missing multi-hop payload execution

This is the part that should worry every team relying on classifier-based agent guardrails. Auto Mode's classifier evaluated the command Claude was about to run — a short, unremarkable Python decoder invocation. It had no visibility into what would happen once Python's import system resolved struct from a poisoned local file.

In several test runs, Claude itself noticed something was wrong only after the payload had already executed, and tried to kill the resulting process. Auto Mode reportedly denied that cleanup command too — a sharp illustration of a classifier reasoning about surface-level intent rather than downstream, multi-hop consequences.

Anthropic reportedly closed the disclosure as informative rather than as a vulnerability, reaffirming that Auto Mode is a best-effort convenience control, not a sandbox or a replacement for OS-level security boundaries.

Indicators and Artifacts to Watch For

SOC checklist for detecting Claude Code Auto Mode hijack indicators of compromise
  • Unexpected outbound curl or Bash fallback activity following a failed WebFetch/HTTP 415 response
  • ZIP or archive downloads containing Python files that shadow standard library module names (struct.py, os.py, json.py, socket.py, etc.)
  • Python processes spawning child processes immediately after an import statement, especially from a working directory that was just extracted from a downloaded archive
  • Unexplained network callbacks (C2-style beaconing) originating from a coding agent's sandbox or host
  • New processes launched by an AI coding agent that persist after the CLI session ends
  • File writes occurring outside the expected project workspace

Detection and Prevention Techniques

SOC prevention checklist for securing Claude Code and AI coding agents from hijacking

Whether you're a SOC analyst monitoring endpoints running AI coding agents, or a developer using Claude Code, Codex, or similar tools daily, these controls matter right now:

  • Never treat Auto Mode (or any classifier-based agent guardrail) as a full security boundary. It reduces friction; it does not replace isolation.
  • Run autonomous coding agents inside containers or VMs with no access to production credentials, SSH keys, cloud tokens, or your home directory.
  • Restrict outbound network access for agent sandboxes to an explicit allowlist of required domains.
  • Monitor process creation and parent-child process trees for anything spawned by Python, Node, or shell processes tied to AI agent activity — EDR rules tuned for "unexpected child process from interpreter" are highly relevant here.
  • Block execution from untrusted or recently-extracted directories where possible, and be suspicious of any workflow where an agent downloads an archive and immediately executes code from inside it.
  • Audit downloaded archives for module name collisions before letting any agent import from a directory containing third-party files.
  • Log and review agent-initiated Bash/shell fallbacks triggered by failed API or fetch calls — this was the pivot point in the entire attack chain.

Expert Tips for SOC Teams and Developers

Expert SOC analyst tips for AI coding agent security and red team testing
  • Treat AI coding agents the same way you'd treat a junior contractor with root access: sandbox first, trust incrementally.
  • If your org has deployed Claude Code, Cursor, Codex, or similar tools at scale, add "AI agent host" as its own asset category in your EDR/SIEM with dedicated detection rules — don't lump it in with generic developer workstation monitoring.
  • Red-team your own agent deployments using the same "indirect" technique: don't inject an obvious command, engineer a scenario where the agent chooses the dangerous path itself.
  • Remember that a 0% success rate on a fixed evaluation set does not mean 0% real-world risk — evaluation benchmarks test known scenario categories, not creative, novel attack chains.

Related Cybersecurity Topics You Should Explore

FAQ

Q1. Is Claude Code Opus 5 fundamentally unsafe to use?
No. The research shows a specific weakness in Auto Mode's classifier-only defense against multi-stage indirect prompt injection — not that the model itself is broadly unsafe. Used with proper sandboxing, it remains a capable and reasonably well-defended tool.

Q2. What is indirect prompt injection?
It's an attack where malicious instructions are hidden inside content the AI agent processes — a website, a file, an archive — rather than typed directly by the user. The agent follows the hidden instructions because it can't reliably distinguish trusted user intent from untrusted external content.

Q3. Does this mean Auto Mode should be disabled?
Not necessarily. Auto Mode still reduces real risk from careless manual approvals. The takeaway is to pair it with sandboxing and monitoring, not to rely on it alone.

Q4. How is this different from the 0% prompt injection claim Anthropic published?
Anthropic's evaluation tested 72 known scenario categories with a fixed evaluation harness. Rehberger's research used a novel, targeted, multi-step attack chain that wasn't part of that scenario set — illustrating that benchmark performance doesn't guarantee resistance to creative real-world attacks.

Q5. What is Python module shadowing?
It's when a malicious file placed in a directory that Python searches early (like the current working directory) has the same name as a legitimate module, causing Python to load the attacker's file instead of the real one.

Q6. Can this attack happen with other AI coding agents, not just Claude Code?
Yes. Similar classifier-bypass and indirect prompt injection research has targeted OpenAI's Codex CLI and other agentic coding tools. This is an industry-wide architectural challenge, not unique to one vendor.

Q7. What did Anthropic say about this disclosure?
Anthropic reportedly closed the report as informative, reiterating that Auto Mode is intended as a best-effort convenience control rather than a security boundary or sandbox replacement.

Conclusion

This research is a reminder that AI agent security isn't a solved problem just because a benchmark says 0%. The most dangerous attacks won't look like attacks at all — they'll look like an agent doing exactly what it was designed to do: solving problems, working around errors, and writing its own code when the "unsafe" option gets refused.

If you deploy Claude Code, Codex, or any autonomous coding agent in your environment, sandboxing and monitoring aren't optional extras anymore — they're the actual security boundary. The classifier is a helpful filter, not a wall.

Found this breakdown useful? Share it with your SOC team or dev lead before your next Auto Mode session, and drop a comment if you've seen similar agent-hijacking attempts in your own environment.

Shubham Chaudhary

Welcome to Xpert4Cyber! I’m a passionate Cyber Security Expert and Ethical Hacker dedicated to empowering individuals, students, and professionals through practical knowledge in cybersecurity, ethical hacking, and digital forensics. With years of hands-on experience in penetration testing, malware analysis, threat hunting, and incident response, I created this platform to simplify complex cyber concepts and make security education accessible. Xpert4Cyber is built on the belief that cyber awareness and technical skills are key to protecting today’s digital world. Whether you’re exploring vulnerability assessments, learning mobile or computer forensics, working on bug bounty challenges, or just starting your cyber journey, this blog provides insights, tools, projects, and guidance. From secure coding to cyber law, from Linux hardening to cloud and IoT security, we cover everything real, relevant, and research-backed. Join the mission to defend, educate, and inspire in cyberspace.

Post a Comment

Previous Post Next Post
×

🤖 Welcome to Xpert4Cyber

Xpert4Cyber shares cybersecurity tutorials, ethical hacking guides, tools, and projects for learners and professionals to explore and grow in the field of cyber defense.

🔒 Join Our Cybersecurity Community on WhatsApp

Get exclusive alerts, tools, and guides from Xpert4Cyber.

Join Now