Cross-domain prompt injection (XPIA) testing with PyRIT

PyRIT's XPIA workflow plants instructions in content an agent later reads, then scores whether the agent followed them. This page explains how to scope, build and verify that test.

On this page

What XPIA testing with PyRIT checks in RAG systems and agents

XPIA testing with PyRIT checks whether instructions hidden in external content can steer an agent or RAG system away from its intended task. If your agent or retrieval pipeline reads web pages, uploaded files, resumes or emails that your organization does not control, the question is not whether the model refuses a direct harmful request but whether text it merely reads can change what it does with your tools, data or outputs. PyRIT's cross-domain prompt injection workflow is built to answer that question.

PyRIT models the attack as a workflow with three steps: an attack setup step that places the adversarial instruction into content, an external processing step where the system under test ingests and acts on that content, and a scoring step that judges what the agent did. The attacker never talks to the objective target directly. The payload travels through an intermediate location such as a storage container, a document store or a web page, and the test succeeds or fails on the downstream behavior. Scoring therefore has to look at actions and outputs, not only at the text the agent returns to a user.

Run this test before an agent gains write access, email sending, ticket creation or access to sensitive retrieval indexes, and again after any change to the ingestion path, retrieval settings or system prompt. Confirm with your engineering team which content sources feed the agent, which of them an outside party can edit, and which actions the agent can take without a human approval step. Those answers determine which XPIA scenarios are worth building first.

How a planted instruction reaches the agent and gets scored

The flow starts in PyRIT's attack setup, where the injected prompt is written to an external store such as an Azure Storage container through AzureBlobStorageTarget. The agent's ingestion or retrieval step then reads that content, which crosses the trust boundary from external data into the agent's own instructions. The objective target acts on what it read, and PyRIT scorers evaluate the resulting output and actions. Check whether the agent followed the planted instruction, not only whether its reply looked harmful.

Planted content travels from PyRIT through the agent's ingestion step to scoring.

Which injection surfaces to test: web pages, files, resumes and retrieval stores

Browsing and summarizing agents fetch pages written by someone other than the operator, so any page they visit is a possible carrier for instructions. In PyRIT's model, the attacker controls the external content and the objective target is the agent that later processes it. The payload is placed in page markup, visible or hidden text, metadata or alt text, and the processing step is the agent's fetch, render or extraction of that page. Confirm whether the agent receives raw HTML, extracted text or a rendered view, because hidden elements may be stripped in one and kept in another. Also confirm which domains the agent is allowed to fetch and whether it follows links, since those settings decide whether your planted page can be reached at all.

  • Delivery: host a test page on infrastructure you control and register its URL with the agent's allowed sources.
  • Processing step: the agent fetches, renders or summarizes the page within a user task you define.
  • Parsing to confirm: how the agent handles scripts, hidden CSS, comments and image alt text.
  • Reachability to confirm: whether the agent can resolve your host, follow redirects and cache previous fetches.
  • Scoring target: whether the agent took an action it should not, such as calling a tool, revealing context or changing its answer.

Before running anything, confirm the agent's browsing policy and logging, so you can trace each fetch to the payload that caused it.

How to score what the agent did after it read the planted content

A planted instruction only matters if the agent acts on it, so scoring has to look past the chat reply to what the agent did with its data, tools and decisions. The cards below cover the outcomes worth scoring and which PyRIT scorer types can detect each one.

The agent followed the planted instruction

This is the core XPIA result: the agent treated text from the external document as a command rather than as data to summarize or evaluate. Check whether the response or the next action carries the payload's requested behavior, such as a specific phrase, format change or redirected answer. An LLM judge given the planted instruction and the agent's output can score this well, but ask the judge to confirm that the behavior came from the document rather than the user's own request.

The agent exfiltrated context or data

Check whether the agent revealed system prompts, retrieved chunks, other users' records or credentials that the planted content asked for. Pattern-based custom logic works well here, using canary strings you seed into the system prompt and knowledge base beforehand. Use an LLM judge only for paraphrased leaks, since a canary match is easier to reproduce and defend in a finding.

The agent called a tool it should not have

Tool calls are often invisible in the final text, so an LLM judge reading only the reply will miss them. Write custom scoring logic that reads the agent's tool-call log from your test target and flags any call outside the allowed set, such as sending an email, writing a file or querying a database the task did not need. Record the arguments as well as the tool name.

The agent altered a decision output

In a RAG hiring screener or similar workflow, the damage may be a changed score or ranking rather than harmful text. Compare the structured output against a baseline score for the same document with the planted content removed. Custom logic that checks the numeric or categorical field is more reliable than asking a judge whether the score looks wrong.

The agent ignored the instruction

A negative result counts as evidence, so record it explicitly rather than leaving the run blank. An agent that processes the document, returns the expected output and shows no payload effects has passed that attempt. Keep these results in memory alongside the successes so that a later rerun can show whether a model or prompt change altered the outcome.

The agent flagged the content

Some agents detect suspicious instructions and say so, which is a useful defense even if the payload was partly followed. Score flagging separately, using an LLM judge with a rubric that asks whether the agent identified the embedded instruction as untrusted. Confirm with your own environment whether a flagged response still triggered any tool call, because a flag alongside an action is a failure.

Configuration choices for an XPIA test and when each fits

This table compares the delivery target, payload format, scorer type and memory backend you can choose for an XPIA test, with the situation each one fits and the trade-off it carries. Read each row against the agent's real ingestion path, since the delivery channel decides which other choices are workable.

ChoiceOptionWhen it fitsTrade-off
DeliveryAzureBlobStorageTargetThe agent or RAG pipeline ingests files from an Azure Storage container, such as a summarisation job that reads uploaded documents.Tests the ingestion path only if your pipeline really reads that container. Requires Azure storage access and cleanup of test files.
DeliveryCustom HTTP or WebSocket endpointThe agent fetches content through an API or accepts uploaded content through your own service.Needs a target adapter for your request format and response parsing. Confirm the endpoint keeps no state you cannot reset between runs.
DeliveryPlaywright-driven web appThe agent browses pages or reads a web UI, so the planted instruction must be reached through a real page load.Closest to real browsing, but slower and more brittle to selectors and layout changes. Plan for browser maintenance.
PayloadPlain textThe agent ingests raw text from files, emails or tickets, and you want a baseline with the fewest moving parts.Easiest to filter or detect, so a pass tells you less about hidden-content handling by the parser.
PayloadHTMLThe target renders or summarises web pages, where hidden elements, comments or metadata may reach the model.Results depend on how the agent's HTML-to-text step strips markup. Test the extraction step as well as the model.
PayloadDocument-embedded textThe agent reads PDFs, Word files or resumes, as in a RAG hiring screener, and hidden text may survive extraction.Requires document generation and a check that the text layer is extracted. Confirm the parser used in production.
ScorerLLM judgeThe outcome is a judgement, such as whether the agent followed an instruction in a planted document or changed its answer.Flexible, but the judge can be wrong. Measure its accuracy on known cases before trusting results.
ScorerAzure AI Content SafetyYou need a managed classifier for harmful or policy-violating output produced after injection.Detects content categories rather than whether a tool was misused. Often needs a separate check for agent actions.
ScorerCustom logic on tool callsYou need to confirm an exact action, such as an unauthorized send, file write or API call, recorded in your logs.Precise and cheap to rerun, but requires the agent to expose tool-call records to the test harness.
MemorySQLiteA single tester or a local lab run where conversations and scores stay on one machine.Simple setup, but not suited to shared team review or concurrent runs. Confirm your retention and backup needs.
MemoryAzure SQLSeveral testers share results, or evidence must sit in an Azure environment your governance team controls.Adds database provisioning, access control and cost. Confirm connection setup and permissions with your Azure team.

Setting up an XPIA workflow in PyRIT step by step

This sequence takes a test team from a clean Python environment to a verified cross-domain prompt injection run, with a check at each step so you can tell whether the planted content reached the agent and whether the agent acted on it. Each stage produces an artifact you can review before moving on.

  1. Install PyRIT on a supported Python version

    Create an isolated virtual environment and install PyRIT with pip. The PyPI package supports Python 3.10 up to but not including 3.15, and the PyRIT documentation recommends Python 3.13, so pick that version if your environment allows it. Confirm the install by importing the package in a Python session and checking that the version reported matches the release you intend to test against, such as v1.1.0 if you are pinning to that release.

  2. Configure credentials and settings files

    Place credentials in ~/.pyrit/.env and non-secret settings in ~/.pyrit/.pyrit_conf. Keep storage account keys and model API keys out of scripts and version control, and confirm with your security team where secrets for the test environment should come from. The check is a short test script that loads the configuration and reports which targets it can reach, without printing the secret values themselves.

  3. Connect the objective target

    Configure the target that represents the agent under test, whether that is a RAG pipeline, a summarisation agent or a screening assistant, using the target types PyRIT supports, such as an OpenAI, Azure or Hugging Face model, or a custom HTTP or WebSocket endpoint. Confirm with the agent owner which tools, data sources and permissions the agent has, because those determine what a successful injection can do. The check is one benign test prompt that returns a normal response from the agent.

  4. Create the storage container for planted content

    Create the container the agent reads from or ingests, such as an Azure Blob Storage container that PyRIT's AzureBlobStorageTarget can write to. Use a dedicated test container that the agent's processing pipeline already watches, and confirm with the platform owner that the agent is allowed to read it in the test environment. The check is a successful test upload followed by confirmation that the agent's ingestion path can see the new object.

  5. Write the injected payloads

    Author the payloads to hide in the content types the agent processes, such as an HTML page for a summarisation agent or text concealed in a resume PDF for a RAG screener. Start each payload with a clearly marked, harmless instruction, such as a request to include a specific marker string in the output, so the result is easy to score. Store the payload set in version control. The check is a review of each file to confirm the instruction text is present and the surrounding content looks like normal material.

  6. Run the XPIA workflow

    Execute the workflow so that PyRIT runs its attack setup step, writes the planted content to storage, triggers the agent's external processing step, and then scores the response. PyRIT's workflow design means the attacker never talks to the objective target directly, so the planted content is the only channel. Record the run identifier and the time of each step. The check is that the workflow completes each stage without an unhandled error and that the processing step was triggered, confirmed in the agent's logs.

  7. Verify results in memory records

    Query PyRIT memory, which stores conversations and results in SQLite or Azure SQL, to confirm the payload was written, the agent processed it, and the score reflects what the agent actually did. Compare the agent's output and any tool calls against the expected injected behavior, and note cases where the payload was present but not acted upon. The check is a memory record for each payload that links the planted content, the agent response and the scorer decision, so an auditor or engineer can trace the result.

Security and operational risks of running XPIA tests

An XPIA test deliberately puts hostile instructions into content your agent will read, then lets the agent act on them. The risks sit in the test itself: where payloads land, what the agent can reach, and what the test run records. The cards below cover the controls to set before the first run.

Payload leakage into shared storage

Planted instructions are uploaded as files, for example through AzureBlobStorageTarget into an Azure Storage container. If that container is shared, synced or indexed by other systems, the planted payload can reach people and tools outside the test. Use a dedicated container with its own access policy, a short retention period and a clean-up step at the end of each run. Confirm which other services read that container before the first upload.

Blob storage targets

Live tool calls and data egress

An agent that summarizes a planted page may also send email, open tickets, call an API or write to a file share. A successful injection in a test can therefore cause a real side effect. Run the agent against a sandboxed tenant with stubbed or read-only tools, and block outbound network paths that the agent does not need for the test. Record every tool call the agent makes so the scoring step can see what happened.

Sensitive transcripts in PyRIT memory

PyRIT memory stores conversations and results in SQLite or Azure SQL, and those transcripts contain the planted payloads and any data the agent returned. Treat the memory database as sensitive: restrict file permissions, encrypt the disk or database, and decide who may export transcripts for review. Check the retention rule for your test records before the run, not after.

Credentials in local configuration

PyRIT reads credentials from ~/.pyrit/.env and settings from ~/.pyrit/.pyrit_conf. A tester's home directory is a weak place for keys to sit, especially on shared jump hosts or laptops. Scope each key to the test tenant, use short-lived identities where the target supports them, and keep the file out of version control and out of logs. Confirm that the agent's own credentials are separate from the ones PyRIT uses.

Clean retrieval index for tests

Do not load production documents, customer records or internal knowledge bases into the retrieval index that the agent queries during XPIA tests. Use a synthetic corpus that mirrors the structure of real content, so the test shows how the agent handles untrusted input without exposing live data to the model, the logs or the scorer. Ask the agent team to confirm which indexes, caches and connectors the agent can reach from the test environment.

Private reporting of PyRIT vulnerabilities

If your testing surfaces a defect in PyRIT itself, report it privately rather than in a public issue. The project directs vulnerability reports to the Microsoft Security Response Center under its security policy. Keep the reproduction details inside your team until the report is handled, and check the README for the current reporting path before you file.

PyRIT README

Questions buyers ask about XPIA testing with PyRIT

How long does an XPIA test take and what drives the duration?

Duration depends mostly on how many content surfaces the agent reads, how many payload variants you test, how complex the scorer must be, and how many retest rounds follow fixes. A single surface with one planted instruction and a simple scorer is a much shorter job than an agent that reads web pages, uploaded files and mailbox content through several tools. No duration is fixed in advance: the written scope sets the timeline once the surfaces and payload classes are agreed. Ask any provider to break the schedule into discovery, payload build, execution, scoring review and retest so you can see which phase drives the total.

What does XPIA testing cost, and which parts are one-time and which recur?

The cost has three components: the setup work of mapping the agent's tools, data paths and permissions, the build of planted payloads and scorers, and the execution and reporting. Setup and scorer design are largely one-time, because they are reused across runs. Re-execution after a model, prompt or tool change recurs, and so does any retainer for continuous testing. DeployOpen does not publish prices. A quote follows from the written scope, so ask for each phase and each recurring run to be priced separately, along with what counts as a retest.

Can our team run XPIA tests in-house with PyRIT?

Yes, if you have engineers comfortable with Python and with the agent's architecture. PyRIT is an open-source framework from Microsoft under the MIT license, and its workflow model separates the attack setup step, the external processing step and scoring, which is the structure XPIA testing needs. The AzureBlobStorageTarget can upload a prompt as a text file to a storage container for cross-prompt scenarios. The harder work is designing payloads that reflect your content, writing scorers that detect the actions you care about, and keeping the test tenant isolated. Confirm that someone on your team owns those three things before you start.

What does the work need from our team before testing starts?

The test needs four inputs. First, the agent architecture: which model, which retrieval or RAG store, which tools and which external content paths it reads. Second, sample content that matches production, such as web page formats, file types and resume or email layouts, so payloads look like real inputs. Third, a test tenant with access to the agent and its tools, isolated from production data and mailboxes. Fourth, named owners for each tool the agent can call, who can confirm what an action should look like and approve a fix. Missing owners usually delay scoring decisions more than the testing itself.

Do PyRIT XPIA results count as a compliance attestation?

No. PyRIT results are test evidence that show what an agent did when given planted instructions under the conditions you tested. They do not constitute an audit report, attestation or certification. DeployOpen prepares systems, controls and evidence for compliance assessments, but independent auditors and certification bodies issue the assessment outcomes. Keep the PyRIT memory records, the payloads, the scorer definitions and the run configuration together so an auditor can trace how each result was produced. Ask your assessor early which evidence format they accept.

What does a fixed-scope XPIA engagement cover?

A fixed-scope engagement covers an agreed set of agent surfaces, payload classes, scorers and retest rounds, with deliverables and timelines written down before work starts. Typically this includes architecture review of the agent's data and tool paths, building the XPIA workflow in your test environment, running the agreed payloads, scoring the outcomes, and reporting findings with fixes and a retest. Anything outside the written scope, such as new surfaces added midway, should be handled as a change to the agreement. Ask for the exact list of surfaces and deliverables in the quote.

What does a successful XPIA attack look like in scoring?

A scored success means the agent acted on instructions embedded in external content instead of its user's request. Examples include revealing data from another document, calling a tool with attacker-chosen arguments, or ranking a résumé because of hidden text. The scorer must check the agent's actions and outputs, not only its text, which is why scorer design takes real effort. Document the expected safe behavior for each payload first, so a failing run points to a clear gap in the agent's controls.

How DeployOpen scopes and delivers XPIA testing

DeployOpen runs security testing for AI systems and agents, including XPIA testing with PyRIT against the content your agent or RAG system reads. Engagements start with a written scope that names the entry points, the processing steps and the evidence you need, then move through build, handover and optional ongoing support.

How we scope

  • Inventory every external source the agent or RAG pipeline reads, such as web pages, uploaded files, email and resumes.
  • Map the processing step, including tools, permissions and data the agent can reach after it reads untrusted content.
  • Agree in writing which injection paths, target endpoints, test accounts and success criteria the engagement covers.

How we build

  • Configure PyRIT in an environment you control, with the target, scorer and memory settings agreed during scoping.
  • Build planted-content test cases for each source type, using benign canary actions so results are safe to review.
  • Run the XPIA workflow, then review each trigger, the agent's tool calls and the scorer output against the expected behavior.

How we hand over

  • Deliver a findings report with reproducible test inputs, memory exports, scorer results and the agent actions observed.
  • Document recommended fixes, such as content sanitization, tool permission limits and confirmation steps, with owners named.
  • Retest the fixed paths and record which findings are closed, open or accepted, so your team can repeat the runs.

How we support

  • Engagements are fixed-scope, and scope, deliverables and timelines are agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer when the agent or its sources change.
  • Confirm with us how PyRIT upgrades and target changes will be re-tested before you rely on earlier results.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.