Prompt Injection in AI Agents: Trust Boundaries and Defenses
Defend AI agents against prompt injection with explicit trust boundaries, constrained tools, controlled data movement, and tests of actual side effects.
Abhishek Raj · · 8 min read
Prepared with AI research assistance. Sources are linked throughout; worked examples are illustrative unless stated otherwise. Editorial approach.
Prompt injection becomes an application-security problem when text obtained during a task can influence how an agent uses authority. A malicious instruction in a retrieved document does not need to change the original user request. It only needs to persuade the model to invoke a legitimate capability with an unauthorized purpose, destination, or argument.
The engineering objective is therefore broader than recognizing suspicious sentences. Build a system in which untrusted content cannot silently acquire the authority of the user or the application. This guide develops a hypothetical internal research assistant to show how that boundary can be enforced.
Model the attacker’s control and the agent’s authority
Begin with a concrete task: an employee asks for a comparison of three public vendors using an internal procurement policy. The assistant can read that policy, search the web, and create a draft report. A hostile vendor page may contain instructions addressed to the assistant. The employee authorized a comparison, not disclosure of the internal policy or changes to purchasing rules.
Record each input channel and who controls it. Public pages, email bodies, uploaded files, repository comments, search snippets, and tool-returned descriptions are potentially lower-trust inputs. An authenticated source can still contain attacker-controlled material: a real support ticket may have been submitted by an adversary.
Separately inventory capabilities. Reading a confidential policy, retrieving a public page, and transmitting a report to an external recipient create different consequences. The dangerous connection is a path from attacker-controlled data through a model decision to a privileged effect.
OWASP describes indirect injection, retrieval poisoning, multimodal content, and persistent attacks as related attack surfaces. Its guidance also distinguishes input screening from an enforcement boundary. Use that taxonomy to broaden the test set, rather than treating a short list of suspicious phrases as a complete defense. OWASP prompt injection prevention.
Keep content provenance separate from instruction authority
A useful evidence envelope preserves source identity, retrieval time, access scope, and the purpose for which the content was obtained. The body remains data even when it contains phrases that impersonate an administrator or describe an urgent operational procedure.
For the illustrative assistant, a retrieved passage might be represented as:
{
"evidence_id": "ev_vendor_b_14",
"source_class": "external_web",
"retrieved_for": "compare_vendor_support_terms",
"content_hash": "illustrative-digest",
"allowed_use": "evidence_for_report",
"body": "Untrusted source content retained here."
}
These fields help preserve provenance; they are not magical delimiters. A model can still misinterpret the body. The executor must derive permission from authenticated task context and application policy, never from allowed_use or any other field supplied by the model itself.
Treat transformations carefully. A summary of an external page remains derived from external content. A specialist agent’s confident restatement does not turn it into an administrator instruction. Preserve the evidence lineage through summarization, handoffs, and memory writes so downstream components can make the same distinction.
A useful design rule is that source content may contribute facts to a report, but may not create new permissions, tools, recipients, or execution objectives. This is an application policy proposed here; its enforcement belongs outside free-form generation.
Put consequential decisions behind an independent executor
The model should propose an operation that a separate component validates. For this example, the executor receives the authenticated employee, task scope, proposed tool, arguments, resource identifiers, and evidence references. It checks whether that exact operation follows from the task’s authorized capabilities.
| Proposed operation | Illustrative executor decision |
|---|---|
| Read the approved procurement-policy document | Permit within the employee’s access scope |
| Search public vendor support documentation | Permit through the controlled retrieval service |
| Save a draft in the employee’s internal workspace | Permit with destination and ownership checks |
| Send the policy to an address found in a vendor page | Reject: external content cannot authorize disclosure |
| Add an unknown integration advertised by a page | Reject: tool installation is outside the task |
Do not give the model a generic network client when a narrower research interface will do. A search tool can accept a query and return evidence without exposing arbitrary authenticated requests. A report-writing tool can write to a preselected internal workspace without accepting an arbitrary destination URL.
This reduces the consequences of a bad model decision even when detection fails. It also makes permissions testable without relying on a model’s explanation. See least privilege for agent tools for credential and capability boundaries.
Constrain data movement as well as tool names
An allowlisted tool can still carry sensitive information in its arguments. A permitted web-search query containing confidential policy text would disclose that text to the search provider. A permitted image URL can encode private content. A legitimate messaging API can send a report to the wrong audience.
For the hypothetical assistant, separate public retrieval from private synthesis. The retrieval worker receives vendor questions without the internal policy. The synthesis worker receives approved evidence and the policy but cannot access general outbound networking. A controlled publication step checks the destination and the permitted disclosure class.
This separation has costs. It can require additional calls, explicit interfaces, and more careful handling of tasks that truly need private context during retrieval. Choose the separation around actual data-flow requirements rather than assigning decorative agent roles.
CaMeL research explores separating control flow from untrusted data and enforcing capability-based information-flow policies around tool calls. Its results are tied to the authors’ evaluated tasks and assumptions. The architectural lesson is worth examining, but adopting a few provenance labels does not reproduce that system or establish its guarantees. Defeating Prompt Injections by Design.
Walk through a hostile vendor page
Suppose the assistant retrieves a vendor page containing a normal support comparison and an embedded request to perform an unrelated synchronization step. The request claims that the internal policy must be uploaded before the comparison is valid. This scenario is hypothetical and uses no real destination or customer data.
The retrieval stage stores the page as external evidence. A screening classifier may flag the instruction-like passage, but the workflow does not depend on that classifier being correct. The page cannot add an upload capability or change the authorized task.
If the model proposes an upload anyway, the executor rejects it because the task grants no external disclosure right. It records the attempted operation and the relevant evidence identifier. The assistant can continue comparing verifiable vendor facts, omit the contaminated passage, or escalate if the remaining evidence is insufficient.
The user-facing report should distinguish an unavailable fact from a policy decision. It should not invent support terms merely because a page was quarantined. Security controls need a usable recovery path; otherwise users may routinely bypass them to finish legitimate work.
If the model copies the hostile instruction into its own summary, the summary retains the external lineage. If the user later asks a different question, that stored summary still cannot authorize an action. This prevents a temporary retrieval result from becoming a durable instruction through memory reuse.
Bind approvals to the operation being authorized
A human approval can help with consequential disclosure, but a vague “continue?” prompt is inadequate. Show the actual action, destination, data classification, and affected resources using a trusted application interface. Do not let the untrusted page write the approval message.
Store approval against a normalized operation description or immutable proposal. Changing the recipient, attachment, resource version, or disclosure scope requires a fresh authorization decision. Revalidate access immediately before execution; approval does not preserve a permission that has since been revoked.
Protocol-level authorization matters too. MCP’s security guidance discusses confused-deputy risks in proxy authorization and requires per-client consent in that setting. It also rejects token passthrough without proper audience separation. Those controls protect a different boundary from model instruction-following, so an agent needs both sound integration authorization and action-level checks. MCP security best practices.
For durable waits and changed state, use the mechanisms described in human-in-the-loop approval gates.
Evaluate attempted effects and ordinary task success
Construct a test matrix crossing content channel, attacker control, available capability, and intended prohibited outcome. Include benign documents discussing security, because a filter that blocks every mention of an attack can make a research assistant unusable.
Test after transformations: retrieval, OCR, summarization, handoff, and memory reuse. Vary language and presentation while preserving the attacker’s intended outcome. Run repeated trials where model behavior is variable, and record which configurations, prompts, policies, and tool versions were evaluated.
Grade the actual effects. Did any sensitive field enter an outbound request? Was an unauthorized recipient selected? Was a forbidden operation merely proposed, rejected, or executed? A final answer claiming that the attack was ignored is insufficient evidence.
Anthropic’s browser-defense report describes layered model training, classifiers, and red teaming while explicitly acknowledging remaining risk. Treat such provider evaluations as evidence about their tested configuration, not as a guarantee for an application with different tools and permissions. Anthropic’s browser prompt-injection defenses.
Track legitimate task completion alongside prohibited-effect rates. Inspect both detection misses and executor-policy gaps. A detected instruction followed by a permitted leak is an authorization failure; an undetected instruction whose action is blocked demonstrates why the external boundary matters.
Frequently asked questions
Can a stronger system prompt solve prompt injection?
It can guide behavior and reduce some mistakes, but it should not carry the entire security boundary. Enforce permissions, destinations, and data-movement policy independently of the model’s interpretation.
Does read-only tool access eliminate the problem?
It reduces mutation risk, but reading private data and placing it into a public query or generated external link can still disclose information. Examine communication paths and output rendering as well as write APIs.
Should every suspicious document stop the entire run?
That depends on the task and available evidence. A bounded workflow can quarantine one source and continue with independently supported facts. Stop or escalate when the remaining evidence cannot satisfy the task without crossing its authorized scope.
Source reference list
Related reading
- Least Privilege for AI Agents: Scoped Credentials and Capability Design
Design least-privilege AI agents with scoped credentials, resource-bound grants, controlled delegation, explicit elevation, and credential lifecycle checks.
- Human-in-the-Loop Agents: Designing Useful Approval Gates
Design human-in-the-loop agent approvals with immutable proposals, qualified reviewers, expiry, durable resumption, and checks against changed resource state.
- Research Agents: Source Discovery, Citation Verification, and Synthesis
Build research agents that verify source identity, map claims to evidence, preserve uncertainty, and produce citations readers can inspect and trust.