Indirect prompt injection: when the attack hides in what the agent reads
Indirect prompt injection is when the malicious instructions sit in something the model reads, not in what you type. It happens when an LLM, the AI model behind the agent, accepts input from external sources, such as websites or files. The attacker does not need access to your chat: this kind of attack can be carried out remotely, without a direct interface. The main risk is that an agent with private data, untrusted content and a way to send data out can be tricked into stealing that data.
If you only know the basic idea, start with the prompt injection overview. This page is about the case that matters most for coding agents: the text comes from content, not from you.
01What makes an attack indirect
An agent does more than answer your message. It opens files, fetches web pages, reads package documentation and calls tools. Every one of those is a way for outside text to reach the model. The model follows any instructions that make it to the model, whether or not they came from its operator.
So the attacker does not need your chat. They need to put text where your agent will read it: a file in a repository, a web page, package documentation, the description of a tool. That is the whole trick behind indirect prompt injection.
02Direct vs indirect prompt injection
A direct attack comes through the prompt input itself. An indirect attack reaches the model through content it was asked to read. Both try to override or manipulate the assistant's instructions by inserting malicious text.
| Direct | Indirect | |
|---|---|---|
| Where the text sits | In the input someone types | In an external source such as a website or a file |
| How the attacker reaches the model | Through the input | Remotely, without a direct interface |
| Who sees it | Whoever reads the chat | Often nobody: it need not be human-visible or readable |
For an agent that works on its own, the indirect column is the one to worry about, because nobody is watching the pages it reads.
03Where the hidden text can sit
Prompt injection can happen when the agent retrieves and follows instructions from untrusted content, for example a web page or a dependency README. A dependency README is the documentation file that ships inside a package you install.
Other places follow from the same idea:
- A repository you cloned. One Claude Code advisory, CVE-2026-55607, needed the user to clone a malicious repository containing injected instructions and run Claude Code against it. A CVE is a public number assigned to a security hole.
- An MCP server that fetches outside content. An MCP server is a program that gives the agent extra tools. Servers that fetch external content can expose you to prompt injection risk. General risks are on MCP security.
- A tool description. Instructions can be embedded in a tool's description, invisible to the user but visible to the model. That is covered on MCP tool poisoning.
- Text a person cannot see. Injected text can affect the model even when it is imperceptible to humans.
04How a hidden instruction travels: a Cursor chain
CVE-2025-54135 shows how an indirect prompt injection gets from planted text to running code. Today Cursor agents can modify workspace files without approval, except for configuration files. Before version 1.3.9 that gap was wider: an agent could create a new dotfile, a file whose name starts with a dot, without approval.
An attacker could chain an indirect injection to write to the settings file and trigger remote code execution, which means running the attacker's commands on the victim's machine, without the victim's approval. It was fixed in version 1.3.9. If you use Cursor, check that you run 1.3.9 or later; the settings that limit this kind of chain in each tool are on prompt injection in coding agents.
Read as a chain: the agent reads planted text, the text asks for a file write, creating a new file needed no approval, and the file the agent wrote ran code. This case is also in the table of real cases on the overview.
05How the data gets out
Reading your files is half of the attack. The other half is sending them somewhere, and two cases show how.
- In Claude Code, using WebFetch alone doesn't prevent network access. WebFetch is the tool that downloads a web page. If Bash is allowed, Claude can still use curl, wget, or other tools to reach any URL.
- One advisory, CVE-2026-54316, was about a pre-approved huggingface.co host in WebFetch. A pre-approved host is a site the agent may contact without asking you. That host created a covert out-of-band channel for encoding and exfiltrating data Claude can access. Exfiltrating means sending data out.
An agent with private data, untrusted content and a way to communicate externally can be tricked into accessing the private data and sending it to the attacker.
06Where to go from here
In Claude Code, an MCP server that fetches outside content is one of the doors, and a cloned repository cannot approve its own servers. Reviewing .mcp.json does not show every server a session can load. Claude Code prompts for approval in interactive sessions before using project-scoped servers from .mcp.json files.
It is unclear if there are fool-proof methods of prevention, so the useful question about indirect prompt injection is what a successful one could reach: your private data, and a way to send it out. The wider picture is in AI agent security. The prevention checklist lists the measures and where each one falls short. Settings for Claude Code, Cursor and Codex are on the coding agents page.
Hidden instructions show up only in what the agent does next, so it helps to see what ran: Artificial Immunity's free, open-source core watches agent sessions and program starts on your Mac and reports what it finds.
FAQ
What is the main risk of an indirect prompt injection attack?
The agent can be tricked into reading your private data and sending it to the attacker, when it combines private data, untrusted content and a way to communicate externally.
What are the key differences between direct and indirect attacks?
A direct attack comes through the user's prompt input and alters the model's behavior. An indirect one arrives through external sources such as websites or files that the model accepts as input. The attacker can reach the model remotely, without a direct interface.
Can a web page really give orders to my agent?
It can try. Prompt injection can happen when the agent retrieves and follows instructions from untrusted content, such as a web page or a dependency README.
Can I spot the hidden text by reading the page?
Not reliably. Injections do not need to be human-visible or readable, as long as the model parses the content.
Is a tool description a form of indirect injection?
Invariant Labs calls tool poisoning a specialized form of indirect prompt injection. It has its own page on this site.