Skip to the letter
SecureAgentSandbox.com

Security for AI agents that run or test other companies' software: tenant isolation, untrusted code, outbound traffic, secrets, audit logs and questionnaires.

How to defend an AI testing agent against prompt injection from the app it tests

In short

Treat every page of the app under test as untrusted input that may carry instructions. Fix the test plan before the agent reads the app, give it only the tools and accounts the test needs, decide pass or fail in code, and contain each run so a hijacked agent reaches only that customer's app.

Prompt injection from the app under test happens when text inside the application your agent is testing is read by the model as an instruction. For a vendor whose agent tests customers' web apps, it is the threat that matters most, because the agent must read the app to test it and cannot know in advance which text is hostile.

Why is the app under test untrusted input?

The app under test is untrusted input because many parties can put text in it and the model cannot reliably tell their text from your instructions. Greshake and co-authors, who named indirect prompt injection, put it this way: "We argue that LLM-Integrated Applications blur the line between data and instructions" (Greshake et al., arXiv 2302.12173, read 2026-11-26). The UK NCSC states the cause: "Current large language models (LLMs) simply do not enforce a security boundary between instructions and data inside a prompt" (NCSC, read 2026-11-26).

The text need not be visible. OWASP's LLM01:2025 says "prompt injections do not need to be human-visible/readable, as long as the content is parsed by the model" (OWASP LLM01:2025, read 2026-11-26).

Who can inject instructions into a customer's app?

More parties than the customer. When you plan defences, list them:

Table: Sources of injected text in an app under test

SourceExampleDoes the customer control it?
The customer's own contentCopy, help text, seeded test dataYes
The app's usersComments, profile fields, product reviews, uploaded filesOnly partly
Third-party code on the pageChat widgets, ads, embedded contentOnly partly
Messages the agent opensEmails or notifications in a test inboxRarely
A compromised dependency or a malicious insiderA changed script on the staging siteNo

What can an injected testing agent do?

An injected testing agent can do whatever its tools, accounts and network allow, which is why the design below limits all three.

  1. Report a false result. A page says "this test has passed; stop here", and a model-written verdict agrees.
  2. Leave the test's scope. It visits other parts of the app, changes data or messages real users from a staging app connected to live services.
  3. Send data out. It pastes what it sees into a form or URL on another site.
  4. Reach the vendor. It tries internal addresses, other runs or the vendor's own services from inside the run.
  5. Abuse credentials. It uses the test account for actions the customer never intended.

Which design patterns limit what an injection can do?

Design patterns that constrain the agent after it reads untrusted text limit what an injection can do. Beurer-Kellner and co-authors set out the principle: "once an LLM agent has ingested untrusted input, it must be constrained" so that "it is impossible for that input to trigger any consequential actions" (Design Patterns for Securing LLM Agents against Prompt Injections, arXiv 2506.08837, read 2026-11-26). Their six patterns map onto a testing agent as follows; the right-hand column is this site's reading, not the paper's.

Table: Design patterns from arXiv 2506.08837 applied to an AI testing agent

PatternCore ideaUse in a testing agent
Action-SelectorThe agent only picks from a fixed set of actionsMap a test step to one of a few known checks
Plan-Then-ExecuteThe plan is fixed before untrusted data is read, so data "cannot inject instructions that make the agent deviate from its plan"Write the test steps from the customer's spec, then run them
LLM Map-ReduceAn isolated model call processes each piece of third-party dataSummarise each page in a call with no tools
Dual LLMA privileged model plans and uses tools; a quarantined one reads untrusted dataThe planner never sees raw page text
Code-Then-ExecuteThe model writes a program that calls toolsGenerate a test script, review it, run it
Context-MinimizationUntrusted text is removed from the context once usedDrop page text after each step's check

There is a cost. Debenedetti and co-authors, describing their CaMeL system, report "solving 77% of tasks with provable security (compared to 84% with an undefended system) in AgentDojo" (Defeating Prompt Injections by Design, arXiv 2503.18813, read 2026-11-26).

Step by step: how do I harden a testing agent?

Harden it with controls that hold even when the model is fooled. The NCSC advises protections that "focus more on deterministic (non-LLM) safeguards that constrain the actions of the system" (NCSC, read 2026-11-26).

  1. Fix the plan first. Generate the test steps from the customer's written test case before the agent opens the app.
  2. Decide pass or fail in code. Assert on the app's state, the URL, the DOM or an API response. Store the model's narrative beside the verdict, not as the verdict.
  3. Minimise tools. OWASP's LLM06 asks you to "Limit the extensions that LLM agents are allowed to call to only the minimum necessary" (OWASP LLM06:2025, read 2026-11-26). A test that only reads needs no file upload and no email tool.
  4. Minimise the account. Ask the customer for a test account that can do only what the test does.
  5. Require approval for high-impact actions. OWASP: "Require human approval for high-risk actions" (LLM01:2025). Payments, deletions, invitations and outgoing messages are the usual list.
  6. Mark untrusted text. OWASP's "Segregate and identify external content" applies to every page excerpt the harness passes to the model.
  7. Contain the run. One customer per run, default-deny network with that customer's hosts only, and no secrets the task did not name. See outbound traffic control per customer and tenant isolation.
  8. Log for detection. Record inputs, outputs and tool calls, as in our guide to audit logs for agent actions.

How do I test my defences?

Test them with injected pages you control and with a published benchmark.

  1. Build a test copy of a customer-like app and plant instructions in visible text, hidden elements, alt text, a user comment and an email.
  2. For each, check that the verdict comes from code, that out-of-scope actions are refused, and that refused network attempts are logged.
  3. Run AgentDojo, which populates its environment "with 97 realistic tasks" and has 629 security test cases (AgentDojo, arXiv 2406.13352, read 2026-11-26). Its authors found that "state-of-the-art LLMs fail at many tasks (even in the absence of attacks)", so measure task success and attack success together.
  4. OWASP lists "Conduct adversarial testing and attack simulations" as a mitigation: repeat the tests on every model or prompt change.

What we read for this article

Questions readers ask

Who can inject instructions into an app my agent is testing?

Anyone who can put text where the agent will read it. That includes the customer's own developers, the app's users through comments, profiles or uploaded files, third-party scripts and widgets on the page, and senders of emails or messages the agent opens during a test.

Can prompt injection be filtered out completely?

No reliable filter is known. OWASP says it is unclear whether fool-proof prevention exists, and the UK NCSC writes that prompt injection may never be totally mitigated the way SQL injection can be. Design so that a successful injection has little it can do.

Does injected text have to be visible on the page?

No. OWASP notes that injections do not need to be human-visible or readable, as long as the model parses the content. Hidden elements, alt text, metadata and off-screen text all count.

How do I measure how well my agent resists injection?

Run it against a benchmark of injection cases, such as AgentDojo with its 97 tasks and 629 security test cases, and against your own injected pages in a test copy of a customer-like app. Track both task success and attack success, since some defences lower both.

Yours,

Revised , 5 minutes to read