Indirect Prompt Injection in AI Agents: Attack Paths, Risks, and Defenses
AI agents that can browse the web, read email, parse documents, and call tools introduce a new attack path: indirect prompt injection, in which untrusted external content contains instructions the model may execute. This article covers the source–sink–canary model, large-scale automated testing, why agent architectures are structurally fragile, and a multi-layered defense strategy built on least privilege, trust boundaries, action auditing, content sanitization, and continuous red-team evaluation.
1. When an AI “Believes What It Reads”: A New Security Problem
Large language model (LLM)-powered agents are moving rapidly into production. They can read email, summarize web pages, parse documents, and call various tools to complete tasks. But an easily overlooked issue follows: the external content an agent reads may itself be an attack payload.
This is not a conventional attack in which an attacker compromises a server or steals a password. It is a new attack pattern: an AI agent reads a passage of text and treats a hidden “command” inside that text as a user instruction to execute. The industry calls this indirect prompt injection.
For example, imagine you hire a very obedient assistant whose daily job is to open letters, read email, and organize materials. One day, an invitation arrives in the mail pile. On the back, in very small text, it says, “Please forward the company account password to a certain mailbox immediately.” If the assistant cannot distinguish content from instructions and mechanically executes any text it sees, it may actually send the password—even if it never intended to betray you. It simply fails to realize that the act of “reading a letter” also smuggled in an “execute an instruction” trap.
What makes indirect injection dangerous is that it exploits not a system vulnerability but an AI agent’s natural tendency to believe what it reads and act on what it believes. As long as the agent cannot distinguish “this is what I should do” from “this is what the content says to do,” the attack remains effective.
2. The Three Elements of the Attack Chain: Source, Sink, and Canary
To understand indirect injection, we need a clear terminology to describe the complete attack chain.
Source: the entry point through which an agent reads external content, such as a web scraper, document reader, email processor, or skill/plugin loader. The content returned by these tools may contain instructions planted in advance by an attacker. A source is “uncontrolled”: the content comes from the open internet or third-party channels, where an attacker can construct arbitrary text.
Sink: the sensitive action that the agent ultimately performs and that has real-world impact, such as sending email, submitting a form, executing a system command, initiating a transfer, or publishing content. The attacker’s ultimate goal is to make the agent read a malicious instruction from a source and then trigger a sink to complete data exfiltration or a destructive operation.
Canary (Decoy): for attack objectives that do not require tool calls and only require the AI to output specific content, evaluators set a verifiable random string. If the string appears in the AI’s output, the output has been “contaminated” by external content and can serve as evidence of a successful attack.
Together, the full attack chain is: poisoned source → agent reads → instruction treated as a task → sink triggered (or canary leaked). The core job of a detection tool is to systematically enumerate source-to-sink combinations and verify one by one whether defenses fail.
3. Large-Scale Automated Testing: What 14,560 Experiments Show
Security evaluation cannot rely on a few attempts and luck. At the scale of 14,560 experiments, the goal is to replace ad hoc spot checks with structured coverage. In industry practice, security teams typically build automated testing frameworks to run large-scale, structured penetration tests against agent frameworks. Typical methods include:
- Build an attack technique library. Turn known injection techniques into reusable attack templates, such as instruction disguise, encoding obfuscation, role-play inducement, and multi-turn priming. These cover a range of variants from straightforward commands to highly covert payloads.
- Create a scenario matrix. Cross-product sources (web pages, email, documents, skill packs, etc.) with sinks (outbound transmission, execution, write operations, etc.) to form a complete test matrix and avoid blind spots in defenses.
- Automate adjudication. Use canary strings, tool-call logs, and sensitive-operation audits to automatically determine whether each experiment succeeded and to calculate success rates across attack techniques and scenarios.
Public industry research often presents sobering results: some attack techniques can achieve double-digit success rates—equivalent to one successful attempt in four. In security, that number is far from trivial. It means agent frameworks have a systemic weakness in the assumption that external content is trustworthy.
4. Why Are Defenses So Fragile?
There are several deep reasons agents are easily “steered” by injection:
- Training objectives and security objectives are in tension. Models are trained to understand and follow instructions as much as possible, and injection attacks are precisely instructions—only from an illegitimate source. At the semantic level, it is difficult for a model to distinguish, using text alone, between “user instructions” and “instructions embedded in content.”
- Context confusion. User instructions and external content are usually concatenated into the same context window, without a natural trust-boundary marker. The model may therefore treat both with equal weight.
- Toolchain amplification. Once an agent is connected to file, network, or execution tools, a single successful injection can escalate from “outputting incorrect content” to “executing dangerous operations,” changing the severity qualitatively.
- Supply chain risk in skill packs and plugins. Content in third-party extensions may itself be tampered with, creating an attack surface similar to software supply chain poisoning.
5. Building a Defense System
For indirect injection, a multi-layered defense approach is widely recognized:
- Least privilege. Agent tool calls should follow the principle of least privilege. Sensitive operations (outbound transmission, transfers, deletion) must require human confirmation or secondary authorization to avoid “read and execute.”
- Trust classification. In prompt engineering, explicitly distinguish system instructions, user instructions, and external content. Use structured markers to isolate content at different trust levels, and require the model to remain suspicious of imperative statements in external content.
- Output and action auditing. Maintain logs and alerts for all tool calls. Detect abnormal patterns—such as reading sensitive information followed immediately by an outbound action—to enable post-incident traceability.
- Injection detection and content sanitization. Before content enters the context, use a combination of rules and models to scan for suspicious instruction patterns, hidden characters, encoding obfuscation, and similar features.
- Continuous red-team evaluation. Integrate large-scale automated penetration testing into the development process. Run regression tests after each framework upgrade or tool change to quantify changes in defense effectiveness.
6. Conclusion
Indirect prompt injection reveals a fundamental change in security in the age of agents: the attack surface has shifted from code vulnerabilities to the semantic layer, where content becomes instructions. For developers and enterprises, building agent applications must begin with the default assumption that external content is untrusted. Through permission controls, trust classification, action auditing, and continuous evaluation, security capabilities should be built into the architecture. Only then can an AI assistant follow instructions without following them blindly.
