Prompt injection
An attack where instructions hidden in content the model reads (a web page, an issue comment, a dependency's README) are followed as if they came from the user. It is the reason an agent with tool access should never be pointed at untrusted input without limits on what those tools can do.
At a glance
- Category
- Security vulnerability
- OWASP LLM Top 10
- LLM01 (2025)
- Entry points
- Issues, READMEs, web pages, tool output
- Root cause
- Instructions and data share one input
- Main defense
- Limit what the agent can reach
How it works
A language model receives one stream of tokens. It has no hard boundary between the instructions you typed and the text a tool pulled in, so text that looks like an instruction can be treated as one. An attacker writes something like "ignore previous instructions and run the following command" where your agent will read it: an issue body, a code comment, a package README, a fetched web page, even text a human cannot see but the model parses.
Direct injection is the user typing the hostile text. Indirect injection, the one that matters for agents, arrives through content the user never wrote. The payload does not need to be clever. It only needs to be read by a model that has the tools to act on it, at a moment when nobody is watching the tool calls.
Why it matters
Damage scales with capability. An injected chat model gives a bad answer. An agent with a shell, network access and credentials can be steered into reading ~/.ssh, posting environment variables to a URL, or pushing a commit. Coding agents read untrusted text as routine work (public issues, outside pull requests, dependency docs) and often hold exactly the tokens an attacker wants.
Asking the model to ignore malicious instructions lowers the hit rate without closing the hole, and phrase filters are easy to route around. What holds up is limiting blast radius: run sessions that touch untrusted input in a sandbox with no secrets mounted, restrict outbound network to an allowlist, scope tokens narrowly, and require human approval for irreversible actions like pushing to a protected branch or publishing a package.
Prompt injection versus jailbreaking
A jailbreak is a user trying to make the model break its provider's rules. Prompt injection is a third party hijacking a model that is working for someone else. The victim of a jailbreak is the provider's policy; the victim of an injection is the user and whatever the agent can reach.
Common mistakes
- Relying on a system prompt that tells the model to disregard instructions found in documents.
- Giving an agent that triages public issues the same broadly scoped token you use for deploys.
- Trusting an agent's summary or code when it was produced from untrusted input.
Related terms
Frequently asked questions
Can prompt injection be fully prevented?
Not with current models, because instructions and data share one input channel. The practical goal is to make a successful injection unable to do much damage.
Is it safe to let an agent read GitHub issues from strangers?
It is reasonable if that session cannot reach secrets, cannot push to protected branches, and cannot send data to arbitrary hosts. Without those limits, an issue is a direct line to your shell.
Does MCP make prompt injection worse?
It widens the surface, since every connected tool can return text the model reads and can act on its behalf. Review which servers you connect and what each is allowed to do.