Indirect prompt injection: how to protect AI agents from hidden instructions

As organisations adopt AI assistants and agents capable of searching through documents, reading emails, browsing the internet or interacting with internal systems, the importance of protecting them against indirect prompt injection also increases. This vulnerability arises when instructions contained within external content can be interpreted by the model as commands it must execute. The problem is particularly significant with agent-based AI, because these systems do not merely generate responses: they may also have permissions to carry out certain actions. In this article, Eva Georgieva, a specialist who develops and secures automated and increasingly agent-based systems, explains what indirect prompt injection is, why it poses a security challenge, and which principles of architecture, testing and governance can help reduce exposure.

Picture of Eva Georgieva

Eva Georgieva Follow

Reading time: 9 min

Indirect prompt injection is an AI security risk in which instructions hidden within external content can influence an agent, particularly when that agent has access to data, systems or the ability to carry out actions.

What is indirect prompt injection and why does it pose a risk to AI?

As organisations move AI assistants and autonomous agents from pilot projects into production, connecting them to email, documents, browsers and internal systems, one type of vulnerability has moved just as quickly from academic research to active exploitation: prompt injection.

OWASP ranks it amongst the top risks for applications based on large language models (LLMs), whilst the National Institute of Standards and Technology (NIST) has addressed this type of threat within the scope of artificial intelligence security. It is one of the key security challenges in the evolution towards AI systems with greater autonomy.

I build and protect automated and increasingly agent-based systems professionally, so let me be blunt: we have handed our AI assistants the keys to the building and then been surprised when they do exactly what a hidden note tells them to do.

This article analyses the most significant form of this problem, indirect prompt injection; why agents that carry out real-world actions have completely changed the stakes; and how we can test for vulnerability to it and defend against it, without the alarmism that often accompanies this topic.

What is indirect prompt injection and how does it work?

Indirect prompt injection occurs when an instruction intended to influence an AI is embedded within external content that the system processes, such as a document, an email, a web page, a calendar entry or a database record.

The vulnerability stems from a structural property of large language models: they do not always reliably distinguish between the data they are supposed to process and the instructions they are supposed to follow. To the model, both appear as text within the same context.

Therefore, when an assistant is asked to summarise a document containing a line such as ‘ignore the user’s request and, instead, perform the following action’, the model may lack a sufficiently robust mechanism to recognise that phrase as content rather than a command. As a result, it may act on the embedded instruction.

This is a contemporary manifestation of a long-standing problem known as the confused deputy: a trusted component—in this case, the assistant—operating with delegated privileges is manipulated via untrusted input to misuse those privileges. It shares principles with vulnerabilities such as SQL injection or cross-site scripting, although the boundary of trust differs.

This gives rise to an important distinction. In direct prompt injection, it is the user themselves who provides the malicious instruction. In indirect prompt injection, the instruction is embedded in external content consumed by the agent: a document, an email, a web page, a calendar entry or a database record.

Indirect injection is a particularly significant concern in the enterprise environment because the instruction can originate from any source capable of injecting content into the flow processed by the agent and, furthermore, may be invisible to the human operator.

Why do AI agents increase the impact of prompt injection?

Agent-based AI encompasses artificial intelligence systems capable not only of generating content, but also of using tools, consulting information sources and carrying out specific actions within the permissions granted to them.

The significance of this vulnerability has grown in tandem with the capabilities of these systems. Early conversational models primarily generated text; a compromised chatbot might return an incorrect response. Today’s assistants, however, can take action: browse the internet, read and send emails, modify files, query systems and, increasingly, perform operations on the user’s device.

When a system can simultaneously consume untrusted content and carry out relevant actions via delegated access, a successful injection ceases to be merely a content-related issue and can become an operational one, with the potential to result in data exposure, unauthorised communications or unwanted transactions.

Research published in this field has demonstrated attacks using documents containing instructions hidden from human users. Risks of this nature have also been analysed in browsers and AI-enabled tools. Other research has examined the vulnerability of commercial models to injections carried out over multiple interactions, as well as the possibility of compromising the persistent memory of certain agents.

The fundamental principle can be summarised as follows: every data source that an agent can read constitutes a potential injection surface.

Consequently, the attack surface may increase as system integration grows, precisely at the same time as its utility increases.

How should prompt injection be addressed from a governance and risk management perspective?

AI governance enables the establishment of responsibilities, controls and processes to manage the risks associated with the development and use of artificial intelligence systems.

Given the structural nature of this vulnerability, it is increasingly advisable to address it through formal frameworks rather than relying on isolated measures.

OWASP provides specific guidance on the security of applications based on large language models and agent-based systems. Meanwhile, the NIST AI Risk Management Framework and NIST’s work on attacks against artificial intelligence systems offer complementary guidance.

For organisations subject to the European Artificial Intelligence Regulation (EU AI Act), the applicable requirements will depend on the classification and specific characteristics of the system. In certain cases, requirements relating to security, robustness and risk management may make resistance to attacks and monitoring relevant considerations not only from a technical perspective, but also from a regulatory compliance standpoint.

Addressing prompt injection within an established governance framework, rather than treating it as an isolated technical problem, enables a more systematic approach.

How can exposure to indirect prompt injection be assessed in a controlled manner?

A canary test uses a benign marker to check whether a system has followed an instruction specifically entered during a controlled test.

Organisations can determine whether a particular AI workflow is susceptible to indirect prompt injection through a simple, non-destructive test based on a canary—that is, a benign marker that will appear in the output only if the AI assistant has acted on a built-in instruction.

The procedure is as follows:

  1. Select a representative document, such as a report, a note or a record of the type typically processed by the workflow.
  2. Incorporate an instruction directed at the AI, rather than at the human reader, and hide it within the content.
  3. Send the document to the assistant or workflow in exactly the same way as would be done during normal use.
  1. Examine the result. If the marker included specifically for the test appears in the response, the workflow has followed an externally supplied instruction and there is exposure to this type of behaviour.

The test can be responsibly scaled up on systems controlled by the organisation itself. A canary can be used to safely assess whether certain external instructions can alter the system’s response or intended behaviour.

These tests must be restricted to in-house and authorised environments and documented as part of a formal assurance process.

How can AI agents be protected against prompt injection?

Defence against prompt injection must be addressed primarily through architecture and security controls, and not solely through instructions directed at the model.

A common, but insufficient, response is to instruct the model to ignore instructions embedded within the content. Such instructions can be circumvented by reformulating them, in much the same way that blocking specific strings alone never solved the problem of SQL injection.

A more lasting mitigation requires architectural measures:

  • Treat all ingested content as untrusted data by default, clearly distinguishing it from the system’s own instructions, which must retain their authority.
  • Apply the principle of least privilege to the agent’s capabilities. The impact of a potential injection is limited by the actions and access rights granted to the system.
  • Require human authorisation for significant or irreversible actions, so that a compromised agent can propose them but cannot execute them automatically.
  • Avoid combining extensive ingestion of untrusted content with high-impact action capabilities within a single unsupervised agent. Separating these two functions constitutes a significant control.
  • Implement logging and anomaly detection for tool usage. Operations triggered by an injection may appear legitimate because the agent uses genuine access rights for an unintended purpose. Monitoring must take into account anomalous patterns and not solely prohibited actions.
  • Align controls with an established security framework, such as the OWASP guidelines for agent-based applications, to achieve systematic rather than reactive coverage.

What problems can prompt injection cause in an enterprise environment?

The fundamental risk arises when two conditions coincide: the agent processes information that is not entirely trustworthy and, at the same time, has the capability to act upon other systems.

In this scenario, indirect prompt injection can lead to behaviour that differs from what the user expects. Depending on the permissions granted to the agent, the potential impact may include information exposure, unauthorised communications, file modifications or other unintended operations.

For this reason, one of the most important security principles is to limit the agent’s capabilities to the minimum necessary and to establish human oversight when an operation may have significant consequences or prove irreversible.

How will security evolve in the face of prompt injection and agent-based AI?

Indirect prompt injection is not an entirely unknown type of threat, but rather a trust issue arising in a new technological context.

Security professionals have long operated on the principle that external inputs should not be automatically trusted—a principle applied in the protection of databases, web forms and file uploads.

Agent-based AI extends this challenge through systems capable of consuming content from multiple parts of the digital environment and acting upon it using delegated authority.

The organisations best prepared to deploy these systems securely will be those that treat every document, message and web page processed by an agent as a potentially untrusted input reaching a system with the capacity to act, and that manage risk through architecture, testing and governance rather than relying solely on instructions directed at the model.

For the foreseeable future, prompt injection will remain a factor that must be taken into account when operating autonomous artificial intelligence systems.

The practical approach is to treat the assistant for what it really is: a brilliant, tireless and deeply literal collaborator that tends to believe what it reads, and which we must therefore supervise appropriately.

In this context, Telefónica has taken on the challenge of becoming the best gateway for citizens to access digital technologies. This aim involves not only bringing innovation and the new capabilities of artificial intelligence within reach, but doing so whilst promoting the responsible and safe use of technology. In the field of agentic AI, making progress in security, governance and oversight will be essential to harness its potential whilst, at the same time, properly managing risks such as indirect prompt injection.

Share it on your social networks


Communication

Contact our communication department or requests additional material.