Skip to content

AgentDojo: A Dynamic Environment for Prompt-Injection Attacks and Defenses

optionalcorefrontierpaperrubric 11/122024 · NeurIPS 2024 Datasets and Benchmarks Track · ~35 min

Edoardo Debenedetti, Jie Zhang, Mislav Balunović, …, Florian Tramèr

Read first: Not What You've Signed Up For: Indirect Prompt Injection

Status

TL;DR. AgentDojo turns indirect prompt injection into a measurable benchmark. Agents work in four simulated but stateful environments (Workspace, Slack, Travel, Banking) with 74 tools (the Table 1 caption says 70). Each of 97 user tasks is paired with each injection task in its suite, giving 629 security cases. Injected text is placed in tool outputs the agent actually reads. Code, not an LLM, checks whether the user’s task was done and whether the attacker’s goal was reached. In 2024 the best agents solved under 80% of benign tasks, attacks hijacked GPT-4o in about half of the cases, and a simple tool filter was the strongest of the defences tested.

Why it matters now. Every agent that reads email, web pages or files faces this threat, and claims such as “our agent is robust to prompt injection” need a shared yardstick. AgentDojo is designed as a live, extensible framework rather than a fixed test set, because static attack lists go stale and defences must be tested against adaptive attacks. Its three-metric reporting (benign utility, utility under attack, attack success) is now the common way to report the security of agent defences.

Environment, tasks and checks (§3). An environment holds mutable state, for example an inbox, a calendar and a cloud drive. Tools read and write that state. A user task is a natural-language request with a deterministic utility function over the before and after states. An injection task is an attacker goal with a security function, such as “money was sent to the attacker account”. Some fields in the state are placeholders, filled with injected text when an attack is run.

Three metrics (§3.4). For user tasks u∈Uu \in U and security cases (u,a)∈U×A(u, a) \in U \times A within a suite:

Benign utility=1∣U∣∑u1[utilityu],ASR=1∣U×A∣∑(u,a)1[securitya violated].\text{Benign utility} = \frac{1}{|U|}\sum_{u} \mathbb{1}[\text{utility}_u], \qquad \text{ASR} = \frac{1}{|U\times A|}\sum_{(u,a)} \mathbb{1}[\text{security}_a \text{ violated}].

Utility under attack is the share of security cases where the user task still succeeds with no adversarial side effects; its complement is the untargeted attack success rate. A defence is good only if it lowers ASR and keeps utility, so results are shown as points on a utility versus security plane.

Injection placement. Each user task records the tool calls needed to solve it. The framework uses this to put injections only into outputs of those tools, so the agent will really read them. An attack is a function that maps an attacker goal to injection text for each placeholder. Attacks that pick the best of several variants per case model an adaptive attacker.

AgentDojo: security cases, a stateful run and deterministic checks On the left, a grid crosses user tasks with injection tasks within a suite; each cell is one security case, and the four suites give 629 cases from 97 user tasks. In the middle, the agent runs a tool loop against a stateful environment such as an inbox, calendar and drive; one tool output contains injected text placed where the ground-truth tool path will read it. On the right, two code checks inspect the final state: a utility check asks whether the user task was done, and a security check asks whether the attacker goal was reached. Below, three metrics are reported: benign utility, utility under attack and targeted attack success rate, and defences are judged on the utility versus security plane. Security cases user x injection task a1 a2 a3 u1 u2 u3 4 suites: 629 cases Agent run LLM picks a tool call state: inbox, calendar, drive, bank, Slack tool output + injection Code checks on final state, no LLM utility check: user task done? security check: attacker goal met? Report three numbers benign utility, utility under attack, targeted ASR; a defence must lower ASR and keep utility
Original sketch. Each suite crosses user tasks with injection tasks. The agent runs against a stateful environment in which some tool outputs carry injected text, and deterministic checks on the final state decide utility and attacker success.
  • Scale (Table 1). Workspace 24 tools, 40 user and 6 injection tasks; Slack 11, 21, 5; Travel 28, 20, 7; Banking 11, 16, 9. The four rows sum to 74 tools, agreeing with the body text; the Table 1 caption says 70, an internal source inconsistency.
  • Baselines (Table 3, “important message” attack). Benign utility / utility under attack / targeted ASR: Claude 3.5 Sonnet 78.22 / 51.19 / 33.86; GPT-4o 69.00 / 50.08 / 47.69; Claude 3 Opus 66.61 / 52.46 / 11.29; GPT-4 Turbo 63.43 / 54.05 / 28.62; Llama 3 70B 34.50 / 18.28 / 20.03; Command-R+ 25.44 / 25.12 / 0.95. Most models lose 10 to 25 points of utility under attack.
  • Attack phrasing (Table 4, GPT-4o). The authors’ generic “important message” style injection reaches 57.7% targeted ASR, far above three earlier styles (3.7% to 5.7%). Picking the best attack per case mainly raises untargeted success (68.4% vs 49.9%).
  • Attacker knowledge (Table 2). Knowing the user’s and model’s names adds about 2 points; wrong guesses cut ASR roughly in half (45.8% to about 23%).
  • Defences (Table 5, GPT-4o). No defence 69.0 / 50.01 / 57.69; delimiters 72.66 / 55.64 / 41.65; PI detector 41.49 / 21.14 / 7.95; repeat prompt 85.53 / 67.25 / 27.82; tool filter 73.13 / 56.28 / 6.84. All defences lose 15 to 20 points of utility under attack.
  • Cost (App. D). About 35 US dollars for the 629 security cases and 4 dollars for the 97 utility cases on GPT-4o.
  • Numbers vary across tables. GPT-4o’s no-defence ASR is 47.69% in Table 3 but 57.69% in Table 5, and the tool filter is 6.84% in Table 5 but 7.5% in the text; the runs are not fully reconciled.
  • Simple attacks and defences. The tested attacks are generic, not optimised against each defence, so low ASR for a defence is an upper bound on its robustness, not a guarantee.
  • Hand-built tasks. 97 tasks over four domains is small, and scaling requires writing more checks by hand.
  • Single-session setting. The tool filter could fail when an agent keeps context across tasks: an injection could wait for a later task that grants the needed tools. Isolation also cannot stop injections that only bias a result, such as making one hotel listing always win.
  • Text only, 2024 models. Multimodal agents, long-running coding agents and newer models need new suites.

Questions to think through

These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.

  1. Derive / compute

    AgentDojo has four suites: Workspace (40 user tasks, 6 injection tasks), Slack (21, 5), Travel (20, 7) and Banking (16, 9). Show that crossing user and injection tasks within each suite gives 629 security cases. Then, with GPT-4o and no defence at 57.69% targeted ASR, estimate how many cases succeed for the attacker, and explain why a suite-level breakdown is needed before reading that average.

    What a strong answer covers
    • 40 × 6 + 21 × 5 + 20 × 7 + 16 × 9 = 240 + 105 + 140 + 144 = 629.
    • 0.5769 × 629 is about 363 successful attacks.
    • The Workspace suite contributes 240 of the 629 cases (38%), so the average is weighted toward one domain.
    • Suites differ a lot: Slack has about 92% attack success, while some injection tasks never succeed. The authors hypothesize that Slack's relatively large attacker-controlled share of tool output contributes; 92% is not a measure of that share.
    • A defence that only helps in one suite can move the average a lot or very little depending on that suite's weight.
  2. Mechanism

    AgentDojo scores utility and security with deterministic functions over the environment state, not with an LLM judge as ToolEmu does. Explain how a user-task utility check and an injection-task security check work, and why an LLM judge is a poor choice specifically for prompt-injection evaluation.

    What a strong answer covers
    • Each task has a function that compares the environment state before and after the run (and the model output) and returns pass or fail, e.g. whether the right calendar event exists or whether money was sent to the attacker account.
    • Utility under attack requires the user task to succeed with no adversarial side effect; targeted ASR requires the attacker's goal state to be reached.
    • An LLM judge reads the trajectory, which contains the injected text, so the same injection that fooled the agent may also fool the judge.
    • Deterministic checks are reproducible and cheap, and cannot be argued with; the cost is that tasks and checks must be written by hand.
    • Ground-truth tool-call sequences for each user task let the framework place injections only in tool outputs the agent will actually read.
  3. What if…

    Table 5 compares defences for GPT-4o: none, data delimiters, a BERT prompt-injection detector, repeating the user prompt after each tool call, and a tool filter. Using benign utility, utility under attack and targeted ASR, rank the defences and explain the trade-off each one makes.

    What a strong answer covers
    • No defence: 69.0 benign utility, 50.01 utility under attack, 57.69 ASR.
    • Delimiters: utility rises slightly (72.66) but ASR stays high (41.65), so marking untrusted text alone is weak.
    • PI detector: ASR falls to 7.95 but benign utility falls to 41.49 because of false positives that abort the agent.
    • Repeat prompt: best utility (85.53 benign, 67.25 under attack) and ASR 27.82, but an adaptive attack could target the repetition itself.
    • Tool filter: ASR 6.84 (7.5 in the main text) with utility 73.13, because many attacks need a write tool the task never needed; it fails when tools cannot be planned up front or the task's own tools suffice for the attack (17% of cases).
  4. Critique

    The paper finds that more capable models tend to be easier to attack (an inverse-scaling pattern), with GPT-4o at 69.0% utility and 47.69% ASR versus Command-R+ at 25.44% and 0.95%. Critique the claim that weaker models are safer. What confound explains the pattern, and what metric would separate being fooled from being able to carry out the attack?

    What a strong answer covers
    • Targeted ASR needs the agent to complete the attacker's multi-step task; a weak model may follow the injection but fail to execute it, which looks like security.
    • So ASR mixes susceptibility (did the model adopt the injected goal) with capability (could it carry it out).
    • A cleaner measure conditions on capability, e.g. ASR divided by the model's success rate on the injection task when given as a normal user request.
    • Utility under attack (denial-of-service robustness) correlates strongly with benign utility, which also reflects capability.
    • Weak models are not a defence because they are also not useful; the goal is high utility with low ASR, i.e. moving the Pareto frontier.
  5. Design

    Design a new AgentDojo-style suite for a deep-research agent that searches a fixed web corpus and writes a cited report. Specify the environment state, user tasks, injection tasks, where injections are placed, and the deterministic checks, while keeping the suite safe to release.

    What a strong answer covers
    • State: a frozen document collection with a search tool and a page-reading tool, plus an output report and any side-effect tools such as email or file write.
    • User tasks: questions with known answers and required evidence documents, checked by exact-match answers and citation sets.
    • Injection tasks with checkable goals: cite a planted unreliable page, drop a specific true source, or trigger an unrequested side effect; placed in documents the ground-truth search path retrieves.
    • Vary injection position and the share of retrieved text the attacker controls, since both affected ASR in AgentDojo.
    • Report benign utility, utility under attack and targeted ASR; release only harmless placeholder goals and evaluate defences such as source filtering and tool restriction.
  6. Connect

    Connect AgentDojo's finding that injections placed at the end of a tool output succeed most often (up to 70% for GPT-4o) to what you know about position effects in long-context models and in RAG. What does this suggest for how a retrieval system should order and format documents before handing them to an agent?

    What a strong answer covers
    • Long-context studies show models weight the start and end of the context more than the middle (lost in the middle), and recency strongly shapes instruction following.
    • Text at the end of a tool output is the last thing the model reads before choosing its next action, so it acts most like a fresh instruction.
    • A retrieval layer controls ordering; attackers may influence it too, e.g. through sorting by date or name, which the paper notes.
    • Possible mitigations: put a trusted restatement of the task after untrusted content (like the repeat-prompt defence), shorten or summarise untrusted text, and keep untrusted content in clearly delimited blocks.
    • These help but do not fix the root cause, since the model still cannot tell instructions from data.

Done with this page?

Status