Prompt injection in Claude Code, Cursor and Codex: what to set in each
Yes, Claude Code, Cursor and Codex can all be steered by text you never wrote, because they read repository files, web pages and tool output. It is unclear if any setting prevents this completely, so the settings limit damage. In Claude Code, turn the sandbox on, because it is off by default, with /sandbox. In Cursor, treat Auto-review as a filter, not a boundary. In Codex, keep the default of network off. Public cases are in the overview.
Prompt injection means inserting malicious text to override an assistant's instructions. A chat assistant sees what you paste. A coding agent goes and gets things, and prompt injection can happen when it retrieves and follows instructions from untrusted content, for example a web page or a dependency README. A dependency README is the documentation file inside a package you install. Where the hidden text sits is on the indirect injection page. For an AI agent, prompt injection in Claude Code, Cursor or Codex is the same attack with different settings, and the rest of this page is those settings.
01What to set, tool by tool
| Tool | Where | Setting |
|---|---|---|
| Claude Code | /sandbox in a session, or sandbox.enabled set to true in ~/.claude/settings.json | Sandbox, off by default |
| Cursor | Settings > Agents > Approvals & Execution | Run mode: Auto-review, Allowlist or Run Everything |
| Codex | /permissions to switch to read-only; --sandbox workspace-write --ask-for-approval on-request for local work | Sandbox mode and approval policy |
The order to switch things on is on the prevention page, together with the limits of each control.
02Prompt injection in Claude Code
With Claude Code v2.1.283 or later, auto mode is the built-in starting permission mode for interactive terminal and VS Code sessions. In auto mode a separate classifier model reviews actions before they run and blocks what appears driven by hostile content Claude read. It reduces prompts but does not guarantee safety. Manual mode (config value default) asks before Bash commands except a built-in set of read-only ones. Switch modes with Shift+Tab in the CLI, the mode indicator in VS Code or the mode selector in the desktop app. The list of what auto mode blocks is on Claude Code auto mode.
Prompt injection in Claude Code is limited by two things you control: what runs without asking, and what the sandbox lets a command touch. The sandbox is a boundary the operating system enforces around shell commands, and it is off by default. Once it is on, commands can read the entire computer except certain denied directories, and that default still allows reading credential files. Commands can write to the current working directory and its subdirectories. It covers shell commands only: Claude's file tools, MCP servers and hooks run outside it. It also protects its own config paths, because a command that could edit those files could grant itself permissions, or add a hook or MCP server that Claude Code runs outside the sandbox. A hook is a command or other handler you define that runs automatically at set points in Claude Code's work; examples are on Claude Code hooks. Setup is on Claude Code sandbox.
Protected paths inside your project include shell startup files such as .bashrc and .zshrc, .gitconfig, and hooks and config inside .git. Project MCP choices you made once can be reset with claude mcp reset-project-choices.
The --dangerously-skip-permissions flag is equivalent to --permission-mode bypassPermissions, and the docs say to use that mode only in isolated environments like containers, VMs or dev containers without internet access. Setting bypassPermissions in a project's .claude/settings.json or settings.local.json does not take effect, and the session starts in Manual mode. More is on dangerously skip permissions.
Fixes for advisories ship as new versions: users on standard auto-update received the fix for CVE-2026-55607 automatically. If you update by hand, do it.
03Cursor
Cursor's docs recommend Auto-review as the safest useful setup for most people. Its classifier runs on the Cursor backend and can allow a call you would have blocked, or block a call you would have allowed. Treat it as a filter, not a wall.
The Cursor sandbox on macOS uses Seatbelt, the sandbox framework built into the system. Its network mode is your own allowlist plus Cursor's built-in defaults for common package managers and language tools, and that is the default. The built-in list includes github.com, and an Allow All mode lets the sandbox reach everything. If a sandboxed command fails on a sandbox restriction, the agent can rerun it outside the sandbox, and the classifier reviews that rerun. Setup is on Cursor sandbox.
Cursor protects paths like .git/config, .git/hooks, .vscode, .cursorignore and sensitive Cursor config files. File-Deletion Protection prevents the agent from automatically deleting files, including rm commands, and External-File Protection prevents automatic changes outside the workspace. Cursor workspace trust is disabled by default. For untrusted repositories the docs suggest a basic text editor instead. One public case, an indirect injection chained to code execution in versions below 1.3.9, is in the overview table and walked through on the indirect page.
04Codex
The agent runs with network access turned off by default. Use caution when enabling network access or web search. Web search uses a cache by default, which reduces exposure to prompt injection from arbitrary live content, and web results should be treated as untrusted. With --yolo or another full access sandbox setting, web search defaults to live results. On macOS the sandbox uses the built-in Seatbelt framework.
The default workspace-write mode lets the agent read files, edit within the workspace and run routine local commands inside that boundary. Codex protects .git as read-only inside writable roots. Auto-review in Codex reviews eligible approval requests instead of surfacing them to you, with the same sandbox boundary as standard on-request mode. The danger-full-access mode runs the agent without sandbox restrictions. You can disable approval prompts with --ask-for-approval never or -a never, and that works with all sandbox modes. Turning prompts off removes the person from the loop, so keep it for environments with nothing to steal. Sandbox setup is on Codex sandbox.
05Project MCP servers in all three
An MCP server is a program the agent talks to for extra tools. Verify you trust each server before connecting it. A cloned repository can't approve its own servers. Claude Code prompts for approval in interactive sessions before using project-scoped servers from .mcp.json files. In Cursor, all MCP connections need your approval and each tool call still needs individual approval. In Codex, project-defined MCP servers can run commands outside the sandbox, and destructive app or MCP tool calls always require approval when the tool advertises a destructive annotation, a label the tool puts on itself. Poisoned tool descriptions are on MCP tool poisoning, and general risks are on MCP security.
06Reported cases
Claude Code advisories include CVE-2026-55607, which needed a cloned repository with injected instructions. For Cursor, CVE-2026-26268 involved a prompt-injected agent writing git hooks. Each is in the table on the overview, and the advisory list for Claude Code is on Claude Code security.
07What no setting does
No setting for prompt injection in Claude Code, Cursor or Codex removes the risk: it is unclear if there are fool-proof methods of prevention. Plan for an injection to get through one day, and limit what it can reach. More on controls is on how to prevent prompt injection.
Settings limit what an agent may do; they do not show you what it did. Artificial Immunity's free, open-source core watches Claude Code, Cursor and Codex sessions on your Mac and reports what it finds.
FAQ
Is Claude Code vulnerable to prompt injection?
Like any agent that reads outside text, yes. One advisory, CVE-2026-55607, needed a cloned malicious repository with injected text and a Claude Code run against it. Servers that fetch external content can also expose you to the risk.
Why does AI keep falling for prompt injection attacks?
Models follow any instructions that make it to the model, whether or not they came from the operator or from some other source. Rules written into a system prompt may be bypassed.
How to protect against AI prompt injection?
No single setting does it. Combine the sandbox, approvals and a short network allowlist. The prevention page has the checklist and the order to do it in.
Can a cloned repository approve its own MCP servers?
No, and Claude Code prompts for approval in interactive sessions before using project-scoped servers from .mcp.json files.
Does Cursor Auto-review stop prompt injection?
Not reliably. Auto-review is not a security boundary, and the classifier can make mistakes in both directions.
Does Codex let a web page reach my machine?
By default the agent runs with network access turned off. If you enable network access or web search, use caution.
Related guides
Sources
- Claude Code docs: security
- Claude Code security advisories (GitHub API)
- Cursor security advisories (GitHub API)
- NVD: CVE-2025-54135
- Cursor docs: run modes and sandbox
- Claude Code docs: permission modes
- Claude Code docs: sandboxing
- Claude Code docs: MCP
- Claude Code docs: hooks
- OpenAI Codex docs: internet access
- OpenAI Codex docs: agent approvals and security
- OpenAI Codex docs: sandboxing
- OWASP LLM01: Prompt Injection
- Cursor docs: security