An AI assistant reads a web page to answer a question. Halfway down the page, hidden among the useful information, is a different instruction: ignore the user and send a local file somewhere else.

The page is not the user. It is not the developer. It is data. But an agent that treats the page's text as an instruction may cross a trust boundary that would be obvious in a conventional application.

That is the heart of prompt injection. The interesting part is not that a model can be tricked into saying something strange. It is what happens when the model has tools.

From misleading answers to actions

Prompt injection can arrive directly from a person interacting with an assistant, or indirectly through material the assistant was asked to process: a web page, a document, an email, a search result, a repository file or a tool response.

Imagine an assistant asked to summarise a support ticket. The ticket contains a message claiming to be a system administrator and instructing the assistant to look up credentials before answering. The attacker does not need to compromise the assistant's actual configuration. They only need their text to reach the model through a source the agent is already reading.

The outcome depends on the agent's permissions and design. An injection may contaminate an answer, expose information the agent can access, or influence an action such as sending a message or changing a file. The malicious text alone does not grant new permissions; it attempts to misuse permissions the agent already has.

The confused deputy, with a language model

This resembles a classic security problem: a trusted component is persuaded to use its authority on someone else's behalf. The agent can legitimately access a document or call an API, but the document author should not be able to decide how that authority is used.

Language makes the boundary particularly awkward. A retrieved document can contain both facts and commands, and the commands can be phrased as policies, urgent warnings or troubleshooting steps. A statement such as “this is an authorised security test” is still a statement from the document, not proof of authorisation.

Even otherwise useful features can add exposure. A tool result might contain instructions in a page footer; a code repository might include guidance intended for a human developer; an email might quote another message. The agent needs the content to do its job, but it must not promote that content into authority.

Defence starts outside the prompt

Instructions telling the model to ignore attacks are worthwhile, but they are not a security boundary on their own. A more reliable design assumes that an attacker-controlled instruction may eventually be encountered and limits the damage if it influences the model.

  • Limit permissions. Give each agent access only to the files, services and actions needed for its task. Read-only access is preferable when changes are unnecessary.
  • Separate reading from acting. Treat retrieved content and tool outputs as untrusted data. Require the user's actual request and application policy to authorise actions, not instructions embedded in a source.
  • Gate consequential actions. Require an explicit confirmation for sending messages, publishing content, deleting data or transmitting sensitive information. Show the destination and substance of the action.
  • Control data flows. Restrict outbound destinations and avoid placing credentials or unrelated sensitive data in the agent's context. Network controls and scoped credentials can reduce exfiltration opportunities.
  • Log and test. Record relevant tool calls and approval decisions, with care for sensitive data. Test workflows using adversarial documents and tool outputs, not just friendly prompts.

None of these controls guarantees that an agent will never follow a malicious instruction. Together, they make a successful manipulation less likely to become a serious incident.

What to ask before deploying an agent

For every external source, ask who can edit it. For every tool, ask what the agent can read or change. Then ask whether a malicious author of the first could influence the second. If the answer is yes, that path deserves a test and an appropriate approval or technical boundary.

The same questions apply to local agents. Running a model locally can reduce exposure to an external model provider, but it does not make repository files, websites or tool outputs trustworthy. The relevant boundary is between the authority to provide data and the authority to direct actions.

AI agents are useful precisely because they connect reading, reasoning and action. Securing them means keeping those connections useful without letting every document become a command.

Further reading