Claude Code Opus 5 Auto Mode Bypassed via Python Module Shadowing Exploit

Security researcher Johann Rehberger has published technical details on a multi-stage exploit chain that achieves arbitrary code execution against Claude Code Opus 5 running in Auto Mode. The attack demonstrates how adversarial files can bypass Anthropic's safety classifiers and prompt injection defenses by exploiting standard runtime behavior in Python. Anthropic rolled out Auto Mode as the default starting mode for Claude Code in mid-August 2026. Auto Mode replaces explicit human permission p

3 min
Claude Code Opus 5 Auto Mode Bypassed via Python Module Shadowing Exploit

Security researcher Johann Rehberger has published technical details on a multi-stage exploit chain that achieves arbitrary code execution against Claude Code Opus 5 running in Auto Mode. The attack demonstrates how adversarial files can bypass Anthropic's safety classifiers and prompt injection defenses by exploiting standard runtime behavior in Python.

Anthropic rolled out Auto Mode as the default starting mode for Claude Code in mid-August 2026. Auto Mode replaces explicit human permission prompts with automated safety classifiers and layered input filters. A third-party evaluation by Trajectory Labs cited by Anthropic reported a 0.00% indirect prompt injection attack success rate across 72 test scenarios. However, Rehberger demonstrated an attack success rate between 60% and 80% using a targeted adversarial workflow.

The Attack Chain: From Web Retrieval to Python Module Shadowing

The exploit begins when Claude Code is tasked with summarizing an external web domain. When the agent attempts to fetch the target URL using its internal WebFetch tool, the attacker's web server responds with an HTTP 415 Unsupported Media Type status. This forces the model to fall back to using command-line tools such as curl via Bash.

Claude Code Security Architecture

The server then issues an HTTP 303 redirect pointing to a ZIP archive containing encoded files, catalogue metadata, a compiled macOS binary labeled as a decoder, and a Python script named struct.py.

Claude Code's internal safety checks correctly identify the supplied compiled binary as untrusted and refuse to execute it. Instead, the agent writes and executes its own Python script to decode the records directly using standard library modules such as base64 and zlib.

This safety decision triggers the actual vulnerability. Because Claude executes Python within the extracted directory, Python places that directory at the beginning of its module search path. When the standard base64 module imports the built-in struct module, Python imports the attacker-supplied struct.py instead of the system library.

Process Detachment and Classifier Inversion

During module initialization, the malicious struct.py launches a background process using python3 -I to avoid recursive shadowing loops. The detached process fetches a second-stage payload from an external server, writes it to disk, and executes a command-and-control agent.

In several test runs, Rehberger observed that after the initial execution, Claude Code inspected the workspace files, detected the malicious nature of struct.py, and attempted to terminate the running payload. However, Auto Mode's safety classifier intervened and blocked Claude's own process-termination command, preventing the agent from killing the rogue background process.

In an alternative variation of the attack, the poisoned script invoked headless Claude Code CLI sessions (claude -p), creating child agents with their own context and tool permissions to perform local reconnaissance.

Implications for Coding Agent Sandboxes

The findings highlight a fundamental architectural limitation of relying on semantic model classifiers as security perimeters. While model classifiers and input filters can intercept direct prompt injections, they do not enforce operating system-level boundaries.

Security researchers emphasize that autonomous coding agents operating on untrusted data require strict isolation mechanisms:

  • Running agent runtimes inside ephemeral virtual machines or hardened containers.
  • Restricting outbound network access to allowlisted package repositories and APIs.
  • Enforcing strict path permissions to prevent access to user home directories, SSH keys, and cloud credentials.
  • Utilizing explicit process execution controls rather than relying solely on automated intent classifiers.

Sources

Written by

More to read

  • Declarative Prompt Optimization and LLM Compilers in Production: Comparing DSPy, TextGrad, SAMMO, and AdalFlow

    Production AI applications are rapidly moving away from hardcoded prompt strings and manual trial-and-error tweaking. As language model systems expand into multi-stage pipelines, retrieval-augmented generation (RAG) graphs, and multi-agent loops, manual prompt adjustments fail to scale. Changing a system prompt or upstream retrieval format frequently degrades downstream extraction, reasoning, or tool-calling performance. To resolve this fragility, the industry is adopting declarative prompt opt

    1 min
  • Cognition Reaches 00M Annualized Revenue on Enterprise Devin Adoption

    Cognition AI, the startup behind autonomous software engineering agent Devin, has reached approximately $900 million in annualized revenue, according to financial data reported by The Information. The figure represents a more than threefold increase since the start of 2026, driven by accelerating enterprise adoption of autonomous developer workflows. Internal executive projections cited in the report indicate the company expects to finish 2026 with more than $1.5 billion in annualized run-rate

    1 min
  • Reference-Free Preference Optimization: Mathematical Foundations of SimPO and ORPO, Length-Normalized Implicit Rewards, Target Margins, and Monolithic Alignment

    Reference-Free Preference Optimization: Mathematical Foundations of SimPO and ORPO, Length-Normalized Implicit Rewards, Target Margins, and Monolithic Alignment Post-training alignment has shifted from complex multi-stage reinforcement learning pipelines toward direct preference optimization paradigms. While Proximal Policy Optimization (PPO) requires maintaining four concurrent models in memory (policy, value, reference, and reward networks), Direct Preference Optimization (DPO) reduced this f

    1 min