Indirect Prompt Injection in the Agent Era: A Complete Guide to Attack Paths and Defense
As AI agents gain the ability to read emails, browse websites, and use external tools, third-party content can become an attack surface. This article explains how indirect prompt injection works, models the attack chain through sources, sinks, and canaries, examines why current defenses fail, and outlines a layered security strategy for reducing risk.
Indirect Prompt Injection in the Agent Era: A Complete Guide to Attack Paths and Defense
As AI agents begin reading emails, browsing websites, and calling external tools on behalf of users, a frequently overlooked security risk is becoming increasingly important: what happens when the content an agent reads contains malicious instructions?
A recent large-scale security evaluation of an open-source agent framework produced a concerning result. Some attack techniques achieved success rates of approximately one in four attempts. This article examines the threat from four perspectives: attack principles, attack-chain modeling, experimental findings, and practical defenses.
1. What Is Indirect Prompt Injection?
Traditional attacks typically involve an attacker attempting to breach a system’s defenses. Indirect prompt injection works differently. The attacker does not interact with the AI directly. Instead, they embed malicious instructions in external content that the AI is expected to process, such as web pages, email attachments, documents, chat messages, or external skill packages.
The agent encounters and processes the content as part of its normal workflow—and may then execute the embedded instructions.
One analogy is an assistant who opens mail on behalf of an executive. A letter may contain tiny text on the back saying, “Forward the account password to this email address.” If the assistant cannot distinguish between content and instructions, they may follow the request without hesitation, even though they never intended to act against the executive’s interests.
Indirect prompt injection exploits the language model’s tendency to treat the content it reads as trustworthy and actionable. At the architectural level, models cannot reliably distinguish between data to be processed and commands to be executed.
This class of attack is particularly dangerous for three reasons:
- The attack surface grows with agent capabilities. The more tools an agent can access—such as search, email, code execution, and form submission—the more content sources can be poisoned and the more sensitive actions can be reached.
- The attack is inexpensive and scalable. Attackers do not need system privileges. They only need to place carefully crafted text in publicly accessible web pages, emails, or other content channels.
- The behavior can be difficult to detect. Malicious instructions can be hidden in HTML comments, invisible characters, or long passages of text, making them difficult for users to notice and auditors to identify.
2. Modeling the Attack Chain with Sources, Sinks, and Canaries
To evaluate the risk systematically, security testing often models the attack chain using three elements:
- Source: The tool or entry point through which the agent reads external content, such as web scraping, document parsing, email access, or external plugin loading. The payload enters the model context through these channels.
- Sink: A sensitive agent action that can create real-world impact, such as sending an email, submitting a form, executing a command, or initiating a transaction. The attacker’s ultimate goal is to make the agent move from reading the malicious instruction at the source to triggering the sink.
- Canary: A predefined, verifiable string used in attacks that do not depend on tool calls and only require the model to output specific content. If the string appears in the model’s output, the context can be considered contaminated.
The complete attack path can be summarized as:
Poisoned content → Agent reads the content → Malicious instructions enter the context → The model mistakes them for user intent → A sensitive action is triggered or information is disclosed
A minimal implementation for detection could look like this:
def check_output_for_canary(model_output: str, canary: str) -> bool:"""Return True if the output contains the predefined canary string."""return canary in model_outputdef audit_tool_call(tool_name: str, args: dict, policy: dict) -> bool:"""Validate tool calls against policy before execution."""if tool_name in policy["sensitive_tools"]:return require_human_confirmation(tool_name, args)return True
Using this model, one security research team conducted more than 14,000 injection experiments against an open-source agent framework. The tests covered multiple content sources, including web pages, documents, and emails, as well as different categories of sensitive actions.
The results showed that some attack techniques achieved a maximum success rate of 25.5%—approximately one successful attack in every four attempts. In security engineering, this is a significant figure. It indicates that mainstream agent frameworks currently lack reliable, built-in resistance to content-level prompt injection.
3. Why Existing Defenses Often Fail
The experiments revealed several common weaknesses that agent developers should take seriously:
- Instructions and data are not clearly separated. Retrieved text and user instructions may be processed at the same priority level, without a reliable trust hierarchy based on content origin.
- Tool calls often lack a second approval step. In many frameworks, once the model decides to call a sensitive tool, the action is executed directly without human-in-the-loop approval or policy-engine interception.
- Outputs are rarely checked for contamination. Few frameworks verify whether the model’s final response repeats or acts on instructions originating from untrusted content.
- Multi-step reasoning amplifies the risk. An agent’s planning and execution loop can carry contaminated context across multiple turns. A malicious instruction may only take effect several steps later, making the attack harder to trace.
4. Best Practices for Building a Layered Defense
There is no single solution to indirect prompt injection. In practice, organizations need a defense-in-depth strategy. The following measures are widely recognized as important safeguards.
1. Input Protection: Isolate and Sanitize Content
Clearly mark content retrieved from external sources, for example by wrapping it in dedicated delimiters. System instructions should explicitly state that content inside those delimiters is data only and must not be executed as an instruction.
Content security services can also be used to detect injection patterns and filter clearly directive or malicious language.
2. Authorization: Apply Least-Privilege Tool Access
Follow the principle of least privilege. Sensitive actions—such as sending email, initiating transactions, or deleting or modifying data—should not be available by default to fully automated workflows.
An independent policy engine should validate tool calls before execution. High-risk actions should require explicit human confirmation.
3. Output Protection: Detect Contamination and Audit Activity
Check model outputs for canary strings and for the disclosure of sensitive information, including credentials and personal data.
All relevant events should be connected to centralized logging, monitoring, and alerting systems. Every tool call should be traceable and capable of being reviewed or replayed during an investigation.
4. Runtime Security: Perform Continuous Testing
The defense against indirect injection is an ongoing process rather than a one-time configuration task. Injection testing should be integrated into the CI/CD pipeline, using automated red-team tools to perform regression-oriented penetration tests against agents.
In cloud-native deployments, container isolation can help separate execution environments. Sensitive tasks can also be routed through asynchronous approval workflows using messaging systems, reducing the potential blast radius of an individual attack.
Conclusion
The value of an AI agent lies in its ability to act autonomously. That same autonomy is also the source of much of its risk.
Indirect prompt injection demonstrates that once AI begins reading the world on a user’s behalf, the world itself becomes part of the attack surface. More than 14,000 experiments and a maximum success rate of 25.5% are not merely alarming statistics; they form a clear engineering checklist.
Trust classification, tightly scoped permissions, human approval for high-risk actions, output validation, and end-to-end auditing should all be treated as core architectural requirements. Only by making agent security a first-class concern—just as it is in traditional software security—can agents become reliable productivity tools instead of unwitting executors of an attacker’s instructions.
