Prompt Injection Guide

Learn prompt injection: attacks, defenses and hands-on practice

Prompt injection is an attack in which text that reaches a large language model is followed as an instruction, so the model acts for the attacker instead of the application that deployed it. Pwned Labs teaches direct and indirect prompt injection hands-on against live LLM-backed and agentic applications, in its Academy labs and in the AI Systems Attack and Defense bootcamp that leads to the AISRTP certification.

The attack is possible because a model reads its system prompt, the user's message, retrieved documents and tool results as one stream of text, with no enforced separation between instructions and data. This guide explains direct and indirect injection, how the attack plays out in chat applications, RAG pipelines and agents, how to detect and limit it, and where to practice it legally.

Chat interface of an AI assistant of the kind targeted by prompt injection
The Basics

What is prompt injection?

Prompt injection is input that changes the behavior of a large language model in ways the application's developer did not intend. The OWASP GenAI Security Project ranks it first, as LLM01, in both the 2025 and 2026 editions of its Top 10 for LLM Applications, and MITRE ATLAS tracks it as technique AML.T0051, LLM Prompt Injection.

The cause is a design property of current models. A system prompt, a user message, a retrieved passage and a tool result all arrive as tokens in one context window, and the role labels that separate them are tokens as well. Models are trained to give some of those sources more priority than others, but that ordering is learned behavior and nothing in the model enforces it.

The UK National Cyber Security Centre contrasts prompt injection with SQL injection for this reason: SQL injection can be closed with parameterized queries, while there is a good chance that prompt injection will not be mitigated in the same way, so the practical goal is to reduce its likelihood and its impact. Pwned Labs places prompt injection in the Instruction and Context families of its seven-family AI Attack Taxonomy.

An AI application surrounded by the cloud services, models and tools it connects to
Direct vs Indirect

What is the difference between direct and indirect prompt injection?

In direct prompt injection the attacker is the user. The instruction is typed into the chat window or sent in an API request, and the attacker sees the model's reply immediately. Claimed authority, role-play framing, encoded text and requests built up over several turns are examples of direct techniques. MITRE ATLAS records direct injection as AML.T0051.000.

In indirect prompt injection the attacker does not interact with the model. The instruction is planted in content the application will read later, such as a web page, an email, a support ticket, a shared document or a knowledge base record. A legitimate user then asks an ordinary question, the application retrieves the planted content, and the model follows it inside that user's session. MITRE ATLAS records this form as AML.T0051.001.

Two disclosed cases show the indirect pattern. EchoLeak (CVE-2025-32711) was a zero-click prompt injection issue in Microsoft 365 Copilot that a single crafted email could trigger, and ForcedLeak, reported by Noma Labs, reached Salesforce Agentforce through text submitted in a Web-to-Lead form. The Pwned Labs explainer on indirect prompt injection covers this form in more depth.

Diagram of an AI agent and the tools, data and channels inside its blast radius
LLM Apps, RAG & Agents

How does prompt injection work in LLM apps, RAG and agents?

What an injection can reach depends on how the application around the model is built. In a chat application with no tools, the model can only give away what is in its own context. A successful injection can extract the system prompt, along with any credentials, internal addresses or business rules that were written into it.

In a retrieval-augmented generation (RAG) pipeline, text is fetched from a knowledge base at query time and pasted into the prompt. Anyone who can write to a source that the pipeline indexes can put instructions in front of the model, and a single poisoned document can affect each later user whose question retrieves it.

In an agent, the model's output drives tool calls such as reading files, querying APIs, sending messages or running code. An injected instruction then becomes an action taken with the agent's identity and permissions, and tool results return to the context, where they can carry further instructions. Simon Willison's lethal trifecta names the combination that makes data theft possible: access to private data, exposure to untrusted content and the ability to communicate externally. Pwned Labs covers RAG and agentic systems in the AISRTP bootcamp across AWS Bedrock, Azure AI Foundry, Google Vertex AI and self-hosted stacks.

PromptStorm cyber range logo
Detection & Defense

How do you detect and defend against prompt injection?

The OWASP entry for 2026 states that no reliable prevention mechanism exists today, so defense assumes that an injection will sometimes succeed and limits what can follow from it. In practice this means keeping secrets out of the system prompt, giving the model the narrowest set of tools and data the task needs, checking authorization in server-side code on each tool call, treating model output as untrusted input wherever it is rendered or executed, restricting where tools can send data, and requiring human approval for high-impact actions.

Guardrails such as Amazon Bedrock Guardrails prompt attack filters, Azure AI Content Safety Prompt Shields and Google Cloud Model Armor are detection filters that analyze the text sent to a model, and in some products the responses that come back. Guardrails are mitigations. They lower the success rate of known attack patterns, and they do not form a security boundary, because rephrased or encoded input can still pass as benign.

Detection depends on logging the assembled prompt, the retrieved content and each tool call with its arguments, then alerting on behavior outside the normal pattern, such as an agent contacting a destination it does not usually reach. The Pwned Labs guide to prompt injection prevention maps each control to the attacks it limits, and PromptStorm, a SkyFall cyber range for business teams, tests incident response against attack chains that target AI and LLM workloads.

Example AISRTP certificate
Hands-On Practice

How can you practice prompt injection hands-on at Pwned Labs?

Prompt injection should only be tested against systems that you own or are explicitly authorized to assess, which is why purpose-built practice environments are useful. Pwned Labs provisions a live environment for each lab, so the attacks run against real LLM-backed applications and the cloud resources behind them, with nothing to install.

The Academy has a free tier, the full premium lab library costs $20 a month, and $200 a year adds cyber ranges. The AI Systems Attack and Defense bootcamp is on demand and costs $399 with lifetime access and two exam attempts. It covers direct and indirect prompt injection, RAG and agentic systems, and detection and defense, and it leads to the AISRTP (AI Systems Red Team Professional) certification, which is assessed with a 24-hour practical exam.

For teams, PromptStorm is the SkyFall range that targets AI and LLM workloads. The wider curriculum is described on the AI security training page.

Prompt Injection Reference

Direct vs indirect prompt injection compared

The two forms differ in who delivers the instruction and who is present when it runs. The identifiers in the table come from MITRE ATLAS.

Direct prompt injection Indirect prompt injection
Who delivers the instruction The attacker, acting as a user of the application A legitimate user or an automated job that causes the application to read content the attacker planted
Where the text enters The chat input or the API request Retrieved content such as web pages, emails, tickets, documents, knowledge base records and tool results
What the attacker needs Access to the application's input The ability to write to a source the application reads. Direct access to the application is not required
Who sees the instruction The attacker Not necessarily anyone. The text can be hidden from the person using the application
MITRE ATLAS technique AML.T0051.000 AML.T0051.001
Example The OWASP example scenario of a customer support chatbot that is told to ignore its guidelines, query private data stores and send emails EchoLeak in Microsoft 365 Copilot, ForcedLeak in Salesforce Agentforce, and the Slack AI case that MITRE ATLAS records as AML.CS0035

Indirect injection is harder to spot in a design review, because the person who triggers it is a legitimate user and nothing unusual appears in what they typed.

What prompt injection can reach in each type of application

The same weakness has a different reach in each type of application. The table shows how injected text arrives, what it can reach and which control limits the damage.

Application type How injected text arrives What a successful injection can reach Control that limits the damage
Chat application with no tools The user's own message The system prompt and anything stored in it, and output that breaks the application's policy Keep secrets and access decisions out of the prompt
RAG pipeline A document, page or record that the retriever returns The answers given to later users whose questions retrieve the content, and the data the pipeline can read Control who can write to indexed sources, and treat retrieved text as data
Agent with tools A user message, retrieved content or a tool result The actions the agent's tools and identity allow, such as reading files, calling APIs or sending data out Least-privilege tools, server-side authorization on each call and human approval for high-impact actions
Agent with third-party tool servers Tool descriptions and tool output from a server the agent connects to, for example over the Model Context Protocol The same actions as any agent, across each server it is connected to Pin and verify tool servers, and treat tool output as untrusted input

Pwned Labs describes how these stages chain together in its guides to AI red teaming and MCP and AI agent security.

Which defenses limit prompt injection, and where do they stop?

The controls below are drawn from the mitigation list in the OWASP LLM01:2026 entry, which states that no single control is sufficient. The right-hand column gives the limit that OWASP notes for each one.

Control What it does Where it stops
Role and limits in the system prompt Tells the model what it may and may not do A partial control. An attacker who infers the prompt can work around it
Input and output guardrails Filter prompts, documents and responses for known attack patterns Semantic filters can be evaded by rephrasing or encoding
Separating and labeling external content Passes retrieved text through a marked channel so the model can tell data from instructions An attacker who knows the marking scheme can imitate it
Output validation in application code Checks each response against a strict schema before another system acts on it Catches format violations. A response in the right format can still carry a harmful request
Least privilege for tools and credentials Keeps credentials in application code and scopes each operation to what the task needs Broad permissions granted for convenience bring the risk back
Human approval for high-impact actions Puts a person in front of privileged, irreversible or externally visible actions Approval fatigue lowers reviewer judgment at volume
Adversarial testing Runs attack simulations against the deployed defenses Results from static test sets can overstate protection, so OWASP recommends testers who know the defense

For each control mapped to the attacks it limits, see the Pwned Labs guide to prompt injection prevention and its walkthrough of the OWASP LLM Top 10.

Practice this at Pwned Labs

Pwned Labs runs these prompt injection labs against live systems, and all three are Premium Academy labs:

  • Breach the Perimeter via Prompt Injection (Premium, Beginner): use direct prompt injection to make an exposed AI assistant reveal secrets, then use a leaked SAS token and multi-tenant service principal credentials to move across Entra tenants.
  • Exploit Indirect Prompt Injection for Azure Access (Premium, Beginner): profile an AI assistant, plant instructions in content it later retrieves, then follow what it exposes to Azure storage and on to deployment credentials.
  • Emulate Storm-0501 Tactics for Cloud Compromise (Premium, Intermediate): emulate Storm-0501 tradecraft that combines command injection and indirect prompt injection with managed identity abuse and Microsoft 365 data exfiltration.

A fourth lab, Pivot into EKS from Prompt Injection (Intermediate), starts from a prompt injection flaw in an AI shopping assistant and continues into an Amazon EKS cluster and the AWS account behind it.

Frequently asked questions

What is prompt injection in simple terms?

Prompt injection is when text that reaches a large language model is treated as an instruction, so the model follows the attacker instead of the application's rules. It works because the model reads instructions and data as one stream of text and has no enforced way to tell them apart.

What is the difference between direct and indirect prompt injection?

In direct prompt injection the attacker types the instruction into the application. In indirect prompt injection the instruction is planted in content the application reads later, such as a web page, an email, a ticket or a document, so it runs during a legitimate user's request and the attacker needs no direct access to the application.

Is prompt injection the same as jailbreaking?

Jailbreaking is one form of prompt injection. OWASP describes jailbreaking as the subset in which the attacker's goal is to make the model violate its safety protocols. Prompt injection is the wider category and covers any input that alters the model's behavior in ways the developer did not intend, including instructions hidden in retrieved content.

Can prompt injection be fully prevented?

With current models there is no reliable way to prevent it. OWASP states that no reliable prevention mechanism exists today, and the UK National Cyber Security Centre says there is a good chance it will not be mitigated in the way SQL injection can be. Defense therefore focuses on limiting what the model can access and do, so that a successful injection has a small effect.

Do guardrails stop prompt injection?

Guardrails reduce the risk and do not remove it. Products such as Amazon Bedrock Guardrails, Azure AI Content Safety Prompt Shields and Google Cloud Model Armor detect known attack patterns, and OWASP notes that filters of this kind can be evaded by rephrasing or encoding. They are mitigations to use alongside least-privilege tools, server-side authorization and careful output handling, and they are not a security boundary.

Where does prompt injection rank in the OWASP Top 10 for LLM Applications?

Prompt injection is ranked first, as LLM01, in both the 2025 and 2026 editions of the OWASP Top 10 for LLM Applications. MITRE ATLAS tracks it as technique AML.T0051, with AML.T0051.000 for direct injection and AML.T0051.001 for indirect injection.

How do I learn prompt injection hands-on?

Learn it by attacking applications you are authorized to test, starting with direct injection and moving on to indirect injection, RAG and agents. Pwned Labs teaches this in the AI Systems Attack and Defense bootcamp, which is on demand, costs $399 with lifetime access and two exam attempts, and leads to the AISRTP certification through a 24-hour practical exam.

Where can I practice prompt injection legally?

Practice only on systems you own or are explicitly authorized to assess. Pwned Labs provides prompt injection labs in live environments that it provisions for you, including Breach the Perimeter via Prompt Injection and Exploit Indirect Prompt Injection for Azure Access, which are in the premium lab library at $20 a month.

About Pwned Labs

Pwned Labs is a hands-on cloud and AI offensive security training platform. It runs real-world attack labs and bootcamps for AWS, Azure, GCP, Kubernetes and AI systems, including the ACRTP, MCRTP, GCRTP, KRTP and AISRTP certifications. Free labs are at pwnedlabs.io/explore.