All articles
November 21, 2026

Prompt injection in AI agents and how to contain it, 2026

Prompt injection is untrusted text that tries to override an agent's instructions. You cannot fully prevent it, so you limit what a hijacked agent can reach and do.

Person typing on a laptop with code on screen, a dark scene that evokes securing AI agents from hijacking

Prompt injection is when untrusted text, hidden inside content an AI agent reads, tries to override the agent's instructions. You cannot fully prevent it today, so the working strategy is to limit what a hijacked agent can see, reach and do. This article explains how the attack works and which controls shrink the damage.

What prompt injection is and why agents raise the stakes

Prompt injection happens "when untrusted text or data enters an AI system," and its contents then try to override the system's instructions, according to OpenAI's guide to safety in building agents. The goals it lists are exfiltrating private data through downstream tool calls, taking misaligned actions, and otherwise changing model behavior in unintended ways.

Checklist diagram with three items: Data leaves, Actions happen and Behavior drifts
Checklist: What prompt injection is and why agents raise the stakes.

A chatbot that only produces text can embarrass you. An agent that holds credentials and calls tools can act. That gap is the whole risk. OpenAI notes that the danger is highest when agents process arbitrary text that influences tool calls.

The attack path is content the agent reads

The attacker doesn't need access to your prompt. They only need to put text where your agent will read it. Anthropic describes prompt injections as "adversarial instructions hidden within content that AI models process." Its example is an email with hidden white text that tells the agent to forward confidential emails to an external address. The same trick works in a web page, a shared document, a support ticket, a calendar invite or a tool description.

That's why it's often called indirect prompt injection: the instruction arrives through data, not through the person using the agent. To the model, both are just text in its context window. It has no built-in way to tell which text carries authority.

What can go wrong

Three outcomes matter in practice:

  • Data leaves. The agent is steered into sending records, files or secrets to an outside address through a tool call.
  • Actions happen. The agent deletes data, sends a message or approves something nobody asked for.
  • Behavior drifts. The agent quietly follows the attacker's goals for the rest of the session.

Contain the damage first: least privilege

Assume some injection will eventually land. Then the question is how much a compromised agent can do, and least privilege answers it. This is the same question behind choosing between autonomous and assisted AI: the more an agent can do without a person, the more an injection is worth to an attacker.

Scope the credentials narrowly

The Model Context Protocol's security best practices describe scope minimization as a progressive model. Start with a minimal scope set, raise it through targeted challenges only when a task needs more, and log every elevation. The page warns against wildcard scopes such as * or all, because a leaked token with broad scopes widens the blast radius. It also says servers "MUST NOT accept any tokens that were not explicitly issued for the MCP server," which keeps one stolen token from working across systems.

For a typical agent this means one credential per job, read-only where reading is enough, and no shared admin key.

Approve and sandbox local tooling

The same MCP page says clients that offer one-click server setup must get consent before running commands. The client should show the exact command without truncation and require explicit approval, and servers should run in a sandbox. If you let an agent install or start tools, treat that as code execution, because it is.

Network reach matters too. The page lists server-side request forgery as a risk when a malicious server supplies internal URLs. Its mitigations include blocking private, loopback and link-local address ranges, validating every redirect hop and routing outbound requests through an egress proxy. For any agent that fetches URLs, an allowlist of destinations is the simplest version of the same idea.

Constrain data flow and keep people on risky steps

Least privilege limits the reach. These controls limit what untrusted text can influence in the first place.

Node map diagram with four parts: payments, deletions, outbound messages and permission changes
Node map: Constrain data flow and keep people on risky steps.

Pass structured data between steps

OpenAI advises designing workflows so "untrusted data never directly drives agent behavior." In practice, extract only specific fields, such as an enum or a validated JSON object with fixed field names, instead of passing free text from one step to the next. A free-text channel is exactly where an attacker smuggles instructions. A fixed schema leaves them nowhere to hide.

Related guidance from the same page: never place untrusted variables in developer-level messages, because those take precedence over user messages and give an attacker the most control. Pass untrusted input as user content instead.

Keep approvals on tool calls

For tools that read or change real data, keep a human confirmation step. OpenAI recommends enabling approvals for MCP tools so people can review and confirm every operation, including reads and writes. Approvals cost seconds. They're also the one control that doesn't depend on the model noticing the attack. Put them on anything irreversible: payments, deletions, outbound messages and permission changes.

Limit what the agent can see and send

An agent cannot leak what is not in its context. Keep secrets, customer records and unrelated files out of the context window unless the task needs them. OpenAI also points out that you do not have full control over what a model shares with connected servers, so choosing what to connect is part of the design. If the agent calls a model vendor's API, review what data you send to a model vendor and what the vendor retains.

What layered defenses do and do not achieve

Model makers are working on this, and the numbers are improving. In Anthropic's internal evaluation of browser use, published November 24, 2025, an adaptive attacker with 100 attempts per environment succeeded against Claude Opus 4.5 at a rate of 1.4% with the improved safeguards, against 8.0% for the model alone. Anthropic's defenses combine reinforcement learning, classifiers that scan untrusted content entering the context window, and expert human red teaming.

Read those figures with care. The test used one automated attacker type and was run by the vendor, and Anthropic itself writes that "a 1% attack success rate, while a significant improvement, still represents meaningful risk." It adds that "no browser agent is immune to prompt injection." OpenAI's guide is similarly direct: guardrails are "not foolproof," and structured outputs and isolation "greatly reduce, but don't fully remove" the risk.

So plan for failure. Run evals against your own workflows, grade traces to see where the agent was steered, and re-test when you change tools or models.

Conclusion

Prompt injection comes from how language models read text. It isn't a bug you patch once. Treat every document, page and message your agent reads as untrusted, give the agent the smallest credentials that do the job, force structured data between steps, and keep a person on anything you could not undo. If you are designing an agent workflow and want a second pair of eyes on its permissions, our AI automation work starts with exactly that map, and you can reach us through /contact.

Frequently asked questions

What is prompt injection in an AI agent?

Prompt injection is untrusted text or data that enters an agent's context and tries to override its instructions. The goal is usually to send private data out through a tool call or to trigger an action nobody asked for.

Can a system prompt stop prompt injection?

No. Clear instructions and examples help, but OpenAI describes guardrails as not foolproof, and says structured outputs and isolation reduce the risk without removing it. Rely on permissions, approvals and limited data access for the cases a prompt misses.

Which single control matters most?

Least privilege. If the agent cannot reach sensitive data or irreversible actions, a successful injection has little to steal and little to do. Add human approval on any step you could not undo.