Prompt Injection Explained: How AI Agents Can Be Manipulated
What is prompt injection? Learn how malicious instructions in documents or websites can influence AI agents and what users can do to reduce risks.
What is prompt injection? It is an attempt to make an AI system follow instructions embedded in material that should be treated as data—such as a webpage, email, document or tool result. If an AI assistant is reading a page to answer your question, the page's author should not be able to take control of the assistant. Prompt injection tries to cross that boundary. The consequences range from an inaccurate answer to unauthorised use of connected tools.
How prompt injection works in everyday terms
Imagine asking an assistant to summarise a supplier's email. The email contains ordinary business information but also an instruction telling the assistant to ignore your request and forward confidential files elsewhere. That instruction comes from an untrusted source. The attack succeeds only if the system mistakes the email's contents for authority over its own behaviour and has tools or permissions capable of carrying out the request.
The crucial distinction is between the user's instruction and information the assistant is examining. A web article can quote commands, fictional conversations or malicious text without becoming an authorised operator of the reader's AI. A secure system must preserve that separation.
Direct and indirect prompt injection
A direct attempt is placed in the text a user deliberately sends to a model. An indirect attempt arrives through lower-trust material the model encounters while completing another task: a search result, repository file, support ticket, spreadsheet cell or external website. Indirect attacks are particularly important for AI agents that can browse, read messages and take actions.
Cybersecurity agencies have identified prompt injection and related input manipulation as AI-specific security concerns. The UK AI Cyber Security Code of Practice discusses indirect prompt injection alongside data poisoning and other risks. The NCSC secure-development guidance treats security as a requirement throughout an AI system's life cycle.
Four realistic situations where it matters
1. An assistant reading an external webpage
The user asks for a comparison of product specifications. A webpage includes text trying to redirect the assistant toward a different answer or website. A vulnerable assistant might repeat false claims or allow the page to change its task. A better design treats the webpage as evidence to evaluate, not as a source of instructions.
2. An AI assistant connected to email
The assistant reads a message containing an instruction to share information or change a calendar event. If it obeys that message without authorisation, the problem is more serious than a bad summary. The attacker may have influenced an action affecting real accounts. The remedy is not merely better wording in the user's prompt; permissions and action approvals must constrain the agent.
3. An AI coding agent reviewing a repository
Source code, comments and documentation can contain attacker-controlled text. An agent that treats repository content as orders could change files beyond the legitimate task. Restricting filesystem and network access, reviewing diffs and requiring approval for consequential operations can reduce damage.
4. An AI system processing retrieved documents
Search or retrieval systems often supply passages from many sources. If a malicious passage is allowed to override the user's request, the assistant can become a conduit for misinformation or data disclosure. The trust boundary applies regardless of whether the passage is in plain text, metadata or another supported input format.
Why “just tell the AI to ignore malicious instructions” is not enough
Clear instructions help establish intended behaviour, but they are not a substitute for technical access controls. A model can misclassify persuasive text or misunderstand which source is authoritative. The system also needs limits on the tools it can invoke, the files it can read and the actions it can complete without human approval.
Joint guidance on adopting agentic AI services highlights the risk of agents having excessive autonomy and permissions. The May 2026 joint guidance recommends layered defence, identity controls and ongoing monitoring. A sound design assumes some untrusted material will reach the model and limits what a mistake can cause.
What ordinary users can do
- Separate reading from acting. Let an assistant summarise or draft before allowing it to send messages, publish material or alter records.
- Use the least access required. A tool summarising one document does not need access to every cloud folder and payment account.
- Check action logs. If an agent can modify files or accounts, review what it changed, not just its final explanation.
- Confirm sensitive actions independently. New payees, password resets, external file shares and deletions should require deliberate authorisation.
- Keep backups and recovery routes. Versioned copies and revocable credentials reduce the consequences of accidental or malicious changes.
- Report suspicious instructions. If a webpage or document seems to be manipulating an assistant, preserve a safe description and inform the service provider or security team.
For organisations: a practical control checklist
| Control | Purpose | Question for testing |
|---|---|---|
| Data/instruction separation | Keep retrieved content from becoming system authority | Can a document override the user's request? |
| Least-privilege tools | Limit the actions available after model error | Can a summariser send email or delete files? |
| Human approval | Gate high-impact changes | Does payment or publication require confirmation? |
| Logging and monitoring | Detect unauthorised behaviour | Can investigators reconstruct tool calls? |
| Adversarial testing | Find weaknesses before deployment | Are external documents and tool outputs tested? |
| Incident response | Limit damage if a boundary fails | Can access be revoked quickly? |
These controls are a planning checklist, not a claim that any one implementation is immune. The NIST Generative AI Profile provides a broader framework for managing risks across an AI system's lifecycle.
What prompt injection does not prove
A prompt-injection failure shows a weakness in how a particular system handles untrusted content. It does not, by itself, show that the model has independent ambitions or can sustain control over infrastructure. Equally, it would be a mistake to dismiss the issue because an individual attack looks like ordinary text. Connected agents can turn an instruction-handling error into a consequential action.
For documented cases where agents crossed real boundaries, see our separate rogue AI incidents article. For personal account controls, read how to reduce AI access to your information. These pages answer different questions and should not be merged into a single unfocused guide.
Frequently asked questions
Can a webpage hack an AI assistant just by containing text?
Not every assistant is vulnerable and not every injected instruction succeeds. The risk arises when a system treats lower-trust content as authoritative and has access to tools or information that make the resulting behaviour consequential.
Is prompt injection the same as hacking a website?
No. It targets the AI system's handling of instructions and untrusted inputs. It may be part of a broader attack, but does not necessarily involve compromising the website or operating system.
Can a user-written prompt prevent all injection attacks?
No. User instructions can help, but security depends on application architecture, permission limits, monitoring, testing and approval controls.
Does prompt injection mean an AI takeover is happening?
It is a concrete security risk, not evidence by itself of a global takeover. Broader loss-of-control scenarios involve additional capabilities and uncertainties.
Primary sources
- UK NCSC: Guidelines for Secure AI System Development.
- UK Government: Code of Practice for the Cyber Security of AI.
- Joint agencies: Careful Adoption of Agentic AI Services, May 2026.
- NIST: Generative AI Risk Management Profile.
Research note dated 7 November 2026. Examples are illustrative and defensive, not instructions for attacking real systems. Verify implementation details and current guidance before publication.