Skip to content

Twin Agent: Context residual compression for privilege-separated agentsTwin Agent: Context Residual Compression for Privilege Separated Agents

Paper Tracker· arXiv:2607.19595· Zhanhao Hu, Dennis Jacob, Xiao Huang, Zhaorun Chen, Bo Li, David Wagner·Indexed by this site · 2026-10-04· Originally publishedDefenses

Quick read

Defenses

Based on the paper PDF (AI-generated); refer to the original

Twin Agent uses restricted hints against injection; GPT-5.2 non-adaptive ASR on SWE-bench-injected is 0.0%.

Threat modelThe attacker injects instructions through untrusted inputs (issue, tool outputs), manipulating reasoning and privileged tool calls. The Explore Agent can see U but cannot execute privileged actions; the Safe Agent executes privileged actions and only contacts untrusted content through hints that are length-limited and can be intercepted by the detector. The adaptive attack is aware of the Twin Agent design, and PAIR is conducted in a white-box setting.

Questions
LLM agents must both handle untrusted information and execute privileged actions, and prompt injection can manipulate downstream reasoning and tool use. The authors argue that existing privilege separation often reduces utility and requires substantial task-specific engineering.
Methods
Twin Agent contains a near-symmetric Explore Agent and Safe Agent: the former reads untrusted content but cannot perform privileged actions, while the latter performs privileged actions and does not directly read untrusted content. The former transmits only residual hints within the budget based on the latter's current trajectory; if over the limit, it truncates or intercepts, and if detected as injection, it discards.
Experiments and results
Under non-adaptive attacks, GPT-5.2 Twin on SWE-bench-injected has Utility 62.5% and ASR 0.0%. Gemini-2.5-Flash Twin on AgentDojo has ASR 0.1%. Adaptive multi-round ASR is 4.7%.
Limitations and future work
The authors note that the evaluation domains are few and lack formal guarantees, and stronger attacks may defeat the design. The experiments include three benchmarks; the adaptive attack is a two-stage evaluation only on SWE, and the paper does not report the attacker LLM model or the number of repetitions for the main results.
Experimental setupGPT-5.2、Gemini-2.5-Flash et al. · SWE-bench Lite、SWE-bench-injected et al. · Utility、ASR
Evaluated models
GPT-5.2Gemini-2.5-FlashGemini-3.5-Flash
Benchmarks
SWE-bench LiteSWE-bench-injectedAgentDojoDecodingTrust-Agent
Metrics
UtilityASR
AI summaryThe researchers propose Twin Agent, a general privilege separation design pattern inspired by residual coding, to defend against prompt injection attacks from untrusted context. The design consists of two approximately symmetric agents: Explore Agent examines untrusted information, and Safe Agent performs privileged actions; Explore Agent conditions on Safe Agent's current context and only passes it a compact hint about the next action, reducing the amount of information needed to maintain task utility. The authors validate that the design achieves a better trade-off between safety and utility by measuring changes in utility and attack success rate as a function of prompt length changes. On the long-horizon software engineering tasks of SWE-bench Lite and the heterogeneous multi-tool interaction tasks of AgentDojo and DecodingTrust-Agent, Twin Agent blocks prompt injection attacks while maintaining high task utility, outperforming both the undefended agent and the privilege separation baseline.

The researchers propose Twin Agent, a general privilege separation design pattern inspired by residual coding, to defend against prompt injection attacks from untrusted context. The design consists of two approximately symmetric agents: Explore Agent examines untrusted information, and Safe Agent performs privileged actions; Explore Agent conditions on Safe Agent's current context and only passes it a compact hint about the next action, reducing the amount of information needed to maintain task utility. The authors validate that the design achieves a better trade-off between safety and utility by measuring changes in utility and attack success rate as a function of prompt length changes. On the long-horizon software engineering tasks of SWE-bench Lite and the heterogeneous multi-tool interaction tasks of AgentDojo and DecodingTrust-Agent, Twin Agent blocks prompt injection attacks while maintaining high task utility, outperforming both the undefended agent and the privilege separation baseline.

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Untrusted context can manipulate privileged actions through prompt injection; Twin Agent uses length-limited residual hints for privilege separation.

    Untrusted inputs can manipulate an agent's downstream reasoning and privileged tool calls via prompt injection.

    • Scenario: The authors point out that LLM agents in open environments must both handle untrusted information and perform privileged actions such as code, filesystem, web, or API operations. Untrusted inputs can be treated as instructions, thereby inducing harmful or unintended actions.
    • Limitations of existing work: Secure-by-design approaches such as Dual LLM and CaMeL separate untrusted observations from privileged execution, but plan-first approaches struggle with long-horizon tasks that require repeated exploration and strategy revision based on feedback. Restricted communication such as booleans or enums also struggles to preserve utility amid mixed information, and often requires manual workflows, rigid interfaces, or task-specific strategies.
    • Core observation: The authors argue that attacking the latest and strongest models usually requires longer injections, while preserving a useful next action often requires relatively little task-relevant information. Defense should widen the gap between these two amounts of information.
    • Proposed method: Twin Agent uses Explore Agent to examine untrusted information and Safe Agent to perform privileged actions; the former conditions on the latter's current context and passes only a compact residual hint. The authors examine the safety–utility trade-off by measuring utility and attack success rate as hint length varies.
    • Threat model:
      • Goal: Make the victim agent follow the attacker-specified goal, or perform harmful, unintended privileged actions. Evaluation goals include writing files, deleting files, and injected instructions in tool outputs.
      • Victim system: An LLM agent that simultaneously processes untrusted context and retains privileged actions; examples include SWE-agent and tool-calling agents.
      • Knowledge and inputs: The attacker can control untrusted regions such as user-submitted issues, retrieved or web content, and tool outputs. The adaptive evaluation is aware of Twin Agent's core design and optimizes the hint using white-box PAIR. The paper does not frame the main threat as black-box or gray-box.
      • Channel after isolation: Safe Agent cannot directly observe U. The authors state that the hint is its only input that can be influenced by untrusted content; over-budget hints are truncated or blocked, and hints detected as injections are discarded.
  2. What related research exists?

    The paper divides related work into prompt injection, model-side defenses, and privilege separation, and criticizes the adaptive risk or utility degradation of the latter two categories.

    The introduction and Related Work are organized by attacks, model-side defenses, and architectural privilege separation.

    • Prompt injection attacks
      • Malicious instructions in inputs: Perez and Ribeiro (2022), Greshake et al. (2023), Liu et al. (2024) discuss embedding malicious instructions in user inputs or external content, causing the model to treat untrusted data as trusted instructions.
      • Agent tool actions: Debenedetti et al. (2024), Zhan et al. (2024) discuss such attacks manipulating multi-step reasoning and inducing unauthorized or harmful tool actions. The paper only describes these here.
    • Model-side defenses
      • Detectors: ProtectAI.com (2023), Blueteam AI (2024), Wan et al. (2024), Jacob et al. (2025), Li et al. (2025), Meta (2025) train classifiers to filter malicious inputs before downstream models or agents.
      • Fine-tuning: StruQ by Chen et al. (2024), Jatmo by Piet et al. (2024), SecAlign by Chen et al. (2025a), Meta SecAlign by Chen et al. (2025b) train foundation models on prompt injection data.
      • Paper's criticism: The paper states that these methods can improve robustness but remain vulnerable to adaptive attacks; the authors observe that successfully attacking the latest, strongest models seems to require fairly long malicious injections, and exploit this in length limits.
    • Security architectures and privilege separation
      • Origins: Dual LLM by Willison (2023) and privilege separation by Provos et al. (2003), assigning different trust levels to different components.
      • Subsequent instances: CaMeL by Debenedetti et al. (2025), Beurer-Kellner et al. (2025), Costa et al. (2025), Jacob et al. (2026) use plan-first, structured communication, restricted data types, or restricted information flow. The introduction describes the latter two as allowing booleans and enums to flow to the privileged agent.
      • Paper's criticism: The paper states that these methods improve security but often rely on heavily engineered workflows, rigid protocols, or task-specific policies, incurring utility loss and not being practical for all tasks.
    • Baselines and benchmarks
      • Baseline methods: Undefended/Default Agent; Dual Agent (the isolated side cannot communicate to the privileged side); CaMeL (mainly plan-first).
      • Benchmarks/datasets: SWE-bench Lite and its injected rewrite SWE-bench-injected, AgentDojo, DecodingTrust-Agent. ReAct (Yao et al., 2023), SWE-agent (Yang et al., 2024) are treated as interaction forms to preserve, not defense baselines.

    The authors position Twin Agent as a relaxation of strict privilege separation: conditioned on the Safe Agent's current trajectory, passing only the residual needed for the next step, rather than a fixed plan before interaction, or compressing the full context seen by the isolated side.

  3. How does the paper address this problem?

    Twin Agent makes Explore Agent pass only budget-limited residual hints to Safe Agent, without retransmitting untrusted context.

    Twin Agent separates exploration from privileged execution, allowing only budget-limited residual hints across the trust boundary. The authors say it is inspired by residual coding and can serve as a drop-in replacement for the ReAct pattern, requiring less task-specific workflow engineering.

    Problem setup

    • At time t, the context consists of the trusted region T, the untrusted region U, and the interaction history I_t. T includes the system prompt, trusted task instructions, verified environment state, and trusted tool schemas; U includes external documents, web pages, tool outputs, or user-submitted bug reports.
    • An undefended agent selects actions using the full context, so U can directly enter reasoning and tool calls.
    • The left panel of Figure 1 is a schematic of information budget and safety/utility, not measured curves. The right panel shows hint examples at different character lengths with Safe Agent outputs, marked as attack failure or success; do not quote injected text from it.

    Three patterns the paper contrasts

    • Strict privilege separation: The privileged agent cannot see U; the isolated agent can see U but cannot perform privileged actions, and typically produces values that are opaque to the privileged LLM and dereferenced by a non-LLM orchestrator at execution time.
    • Plan-first: A plan is generated using only trusted information, and executor actions must be authorized by that plan. The authors argue that without replanning or restricted feedback, the plan cannot directly absorb information that emerges during execution, making it poorly suited for software engineering tasks that require repeated feedback.
    • Restricted information flow: The isolated side compresses the untrusted information it sees and then passes it to the privileged side. The authors argue that U contains large amounts of both relevant and irrelevant information, while the privileged side often needs only a small amount for the next step, making it hard to preserve utility within a fixed protocol.

    Residual hints

    • Explore Agent observes U but cannot perform privileged actions. Safe Agent performs privileged actions, does not directly observe U, and maintains the authoritative interaction history.
    • The design goal is for Safe Agent's actions to approach the useful actions of an undefended agent on the full context, while relying only on the hint. Equation (11) is written as min D(πs(T, Ht(e), It(s)), π(T, U, It(s))) s.t. Budget(Ht(e)) ≤ b. D is action divergence and b is the hint budget.
    • The authors state that Equation (11) is not the optimization solved in implementation. The implementation approximates it with in-context generation: Safe Agent retains the undefended agent's architecture, prompt structure, and action space, differing only in the visible context; Explore Agent sees Safe Agent's current trajectory and is prompted to pass only the missing task-relevant information.
    • The authors' rationale is that communication should be differential: most information is already shared via conditioning, so there is no need to retransmit full observations. Under a fixed budget, the authors argue that utility is primarily determined by Explore Agent's ability to extract task information, while safety is primarily determined by Safe Agent's isolation and control.

    Instantiation on two types of systems

    • The adaptation pattern is the same: privileged actions are separated from untrusted information processing; an Explore Agent that can see the full untrusted context is added; and a compact hint is used to try to keep the trajectory close to the original undefended agent.
    • SWE-agent: Explore Agent can read the full issue and repository, can give hints, and outputs virtual bash that is not executed. Safe Agent can read and write the repository and generate patches, but cannot read the issue. Bash outputs enter the shared context and are visible to both. Section D provides the three system prompt sets.
    • AgentDojo and DecodingTrust-Agent: Tool outputs are untrusted, while system messages and user instructions are trusted. Explore Agent sees tool outputs and gives hints; Safe Agent performs privileged actions based only on trusted context and the hint.

    Security assumptions and adjudication

    • The authors' key assumption is that short injections are unlikely to successfully attack frontier models. Thus they limit hint length, truncating or blocking over-limit hints.
    • They also use a detector to check each hint, discarding it if judged an injection. Section A provides the detector prompt, which returns only one token (1 for suspicious, 0 otherwise), and provides a reminder text for Safe Agent. The authors assume it is hard to find a short injection that both evades the detector and attacks the model used by Safe Agent. In Section 4.3 they say the strong adaptive experiments appear to support this assumption; later they report a nonzero multi-round ASR, which should be read alongside.
    • The authors state that the hint is the only input to Safe Agent that can be influenced by untrusted content, so blocking this channel makes the design secure-by-design against prompt injection. This is a design argument.
    • Utility is the percentage of tasks completed per each benchmark protocol. ASR is the percentage of attacked tasks in which the injected instruction is followed or unsafe privileged actions are executed; SWE-bench-injected determines whether the attack goal is achieved by checking the final patched repository.
  4. What experiments did the paper conduct?

    In Table 1, Twin's non-adaptive ASR includes 0.0%, 0.1%, and 3.3%; the adaptive multi-turn is 4.7%.

    Experimental setup

    • Models: SWE-bench-injected uses GPT-5.2. AgentDojo uses Gemini-2.5-Flash. DecodingTrust-Agent uses GPT-5.2 and Gemini-3.5-Flash (Table 1).
    • Benchmarks: From the 300 items in SWE-bench Lite, 232 were selected, and one of two payloads (write a secret string or delete a file) was randomly injected into the issue, called SWE-bench-injected. AgentDojo uses workspace, slack, travel, banking, with the attack being the default important_instructions, injected into tool outputs; the number of task items is not stated in the paper. DecodingTrust-Agent takes the settings with higher ASR in CRM and Finance, constructs 60 items, with injection in tool responses.
    • Baselines: Default/Undefended; Dual Agent, which appears in the table only for SWE-bench-injected; CaMeL, which appears in the table only for AgentDojo. CaMeL's max_attempts was changed from 10 to 3.
    • Metrics: Utility is the percentage of tasks successfully completed according to the benchmark protocol. ASR is the percentage of attacked tasks in which the injection was followed or an unsafe privileged action was executed; SWE is determined by inspecting the final patch repository.
    • Twin settings: The character budget for SWE-bench-injected and DecodingTrust-Agent is 100, and for AgentDojo it is 200. The main experiment uses both the reminder text and the detector from Section A. The model hosting the detector is not stated in the paper.
    • Repeats: The number of repeats for the main results is not reported in the paper. The Table 1 title is non-adaptive attacks.

    Main results

    According to Table 1. Defaults not listed in the table below are in the bullet points.

    Swipe horizontally to read the table

    BenchmarkModelAgentUtilityASR
    SWE-bench-injectedGPT-5.2Default61.2%97.0%
    SWE-bench-injectedGPT-5.2Dual0.0%0.0%
    SWE-bench-injectedGPT-5.2Twin62.5%0.0%
    AgentDojoGemini-2.5-FlashDefault61.9%41.5%
    AgentDojoGemini-2.5-FlashCaMeL30.9%0.0%
    AgentDojoGemini-2.5-FlashTwin62.9%0.1%
    DecodingTrust-AgentGPT-5.2Twin95.0%3.3%
    DecodingTrust-AgentGemini-3.5-FlashTwin93.3%3.3%
    • Authors' interpretation: The authors state that the undefended agent has high utility but high ASR; the privilege-separation baseline can lower ASR, while utility decreases. The authors state that after reducing CaMeL's retry budget from 10 to 3, utility dropped from about 35% in the original paper to the value in this evaluation.
    • Defaults not listed in the table: On DecodingTrust-Agent, GPT-5.2's Utility is the same as Twin in the table, with an ASR of 10.0%; Gemini-3.5-Flash's Utility is 96.7% and ASR is 26.7% (Table 1).
    • Summary and counterexamples: The authors state that Twin's utility is slightly higher than the baselines, and believe that a more compact context may also bring utility gains. This claim does not cover the Utility decrease for Gemini-3.5-Flash, nor the Slack suite below.

    AgentDojo by suite

    • What was tested: Table 2, the same Gemini-2.5-Flash, four suites, comparing only Default and Twin.
    • Results: On Workspace, Twin has Utility 67.5% and ASR 0.0%, while Default has 65.0% and 23.6%. On Slack, Twin has 66.7% and 0.0%, while Default has 90.5% and 92.4%. On Travel, Twin has 55.0% and 0.0%, while Default has 40.0% and 69.3%. On Banking, Twin has 56.2% and 0.7%, while Default has 43.8% and 47.2%.
    • Authors' interpretation: The paper does not separately explain the Utility decrease on Slack. The overall numbers are the same as Table 1 and are not repeated here.

    Adaptive attacks

    • What was tested: Only on SWE-Agent-Twin, GPT-5.2, with a 100-character budget. The authors state that due to cost, a multi-turn optimization attack was not implemented, and a two-phase construction was used instead. In the first phase, PAIR was run for 100 iterations, repeated 10 times per attack target, for a total of 20 optimized attacks, to see whether the Safe Agent's next output was the target action. In the second phase, a copy-and-paste injection was appended to the bug report, requiring the Explore Agent to forward the optimized text as a hint. After combination, one optimized hint was randomly drawn per instance, and the full multi-turn task was run. The attacker LLM model is not stated in the paper. Section C gives the PAIR prompt, which provides the detector prompt to the attacker; the template is not paraphrased.
    • Results: In Table 3, Phase 1 single-turn ASR is 0.0%, Phase 2 single-turn ASR is 100.0%, and the combined multi-turn Utility is 62.5% with an ASR of 4.7% (11 instances executed the malicious action). Of the 232 instances, the malicious hint passed the detector one or more times in 57; of those, 11/57 ultimately executed the malicious action. Each of these 11 instances was rerun 5 times, and 0 of 55 runs executed the malicious action.
    • Authors' interpretation: The authors consider this to resemble nondeterministic failure under the evaluated decoding settings; they also state that any nonzero success constitutes a safety failure, and believe that strengthening guardrails or running voting over multiple runs could further reduce ASR. Section F uses sphinx-doc__sphinx-7975 as an example, showing that after the hint passes, the Safe Agent may still modify the repository according to the attack goal; the payload is not quoted.

    Hint budget and cost

    • What was tested: The maximum hint budget for SWE-Agent-Twin ranges from 50 to 200 characters, with None meaning unlimited. Utility is evaluated on a subset of 20 items. ASR uses the first-phase attack from Section 5.3, PAIR with 100 iterations repeated 10 times, assuming the Explore Agent is fully compromised.
    • Results: The legend of Figure 3a is Utility Twin, Utility Base, ASR Twin (Adaptive), with the horizontal axis being Information Budget. The authors state that as the budget increases, task-relevant residuals increase, utility rises, and empirical safety risk also rises. The converted text does not show the readings at each point.
    • Cost: In Figure 3b, the authors state that at budgets of 50 and 100, the per-instance cost of SWE-Agent-Twin is about twice that of the baseline SWE-Agent. The text does not give dollar endpoints.

    Other ablations and analyses

    • Section A / Figure A1: On a SWE-bench subset, compares undefended, reminder text only, detector only, and the combination; the subfigures are delete file and write secret string. The authors state that both strategies improve the Safe Agent's safety, and the combination is best. The main experiment uses the combination. The text does not give the ASR at each point.
    • Section B / Figure A2: Uses an unnamed LLM judge to compare trajectories with and without hints, scoring each at 10 checkpoints, with deviation scores from 0.0 to 1.0. The four cases are scikit-learn__scikit-learn-13241, sphinx-doc__sphinx-11445, mwaskom__seaborn-3010, and pydata__xarray-4094. The authors state that deviation is lower with hints; the figure caption states that without hints the bug is not found, and hints align the trajectory with the baseline. The text does not give scores.
  5. What are some points that can be further explored?

    The authors note that only a few domains were evaluatedchers and there is no formal guarantee, so stronger attacks could still defeat the design.

    Limitations and future directions noted by the authors

    • Domains: The authors state that evaluations were conducted only in a few application domains, and further evaluation on other tasks is needed (Limitations).
    • Guarantees: The authors state that Twin Agent appears safe empirically, but there is no formal guarantee, and stronger attacks could still defeat the design (Limitations).

    Experimental coverage

    • Models: The tested models in Table 1 are GPT-5.2, Gemini-2.5-Flash, and Gemini-3.5-Flash. SWE-bench-injected uses GPT-5.2; AgentDojo uses Gemini-2.5-Flash; DecodingTrust-Agent uses GPT-5.2 and Gemini-3.5-Flash.
    • Task sets: SWE-bench-injected has 232 instances, filtered from the 300 instances of SWE-bench Lite; AgentDojo covers four environments: workspace, slack, travel, and banking; DecodingTrust-Agent covers CRM and Finance, totaling 60 instances. The number of AgentDojo task instances is not stated in the paper.
    • Baseline placement: In Table 1, Dual Agent appears only on SWE-bench-injected, and CaMeL only on AgentDojo. The comparison within DecodingTrust-Agent is against Default.
    • Attack types: Table 1 uses static, non-adaptive injections. The adaptive evaluation is a two-stage attack on SWE-Agent-Twin with GPT-5.2 and a 100-character budget; the authors state that multi-round attacks were avoided due to cost (Section 5.3). The paper does not report the PAIR attacker LLM model, the detector's hosting model, or the number of repetitions for the main results.
    • Budget and components: The hint budget ablation measures Utility on a 20-instance subset (Section 5.4). Section A compares reminder text, detector, and their combination on a SWE-bench subset; the main experiments in the body use the combination.
  6. Summarize the main content of the paper

    Twin has non-adaptive ASR 0.0% on SWE-bench-injected and adaptive multi-round ASR 4.7%.

    Twin Agent is a privilege separation design against prompt injection: untrusted context is separated from privileged execution, and only length-limited residual hints are allowed across the boundary.

    • Problem: Agents must both read issues, web pages, or tool outputs, and execute code, files, or APIs. The authors argue that plan-first and rigid communication struggle to preserve both long-horizon utility and safety.
    • Method: Explore Agent can read untrusted content but cannot perform privileged actions; Safe Agent retains the original agent's prompt and action space but does not directly see U. The hint is conditioned on its current trajectory, truncated or blocked if over budget, and suspicious hints are discarded by a detector. The authors state this reduces the need for task-specific re-engineering of workflows.
    • Non-adaptive numbers: In Table 1, GPT-5.2 Twin on SWE-bench-injected has Utility 62.5% and ASR 0.0%, while Default has ASR 97.0%, and Dual has Utility and ASR both 0.0%. On AgentDojo, Gemini-2.5-Flash Twin has Utility 62.9% and ASR 0.1%, while CaMeL has 30.9% and 0.0%. On DecodingTrust-Agent, both Twin runs have ASR 3.3%; GPT-5.2 Utility stays at 95.0%, while Gemini-3.5-Flash drops from 96.7% to 93.3%.
    • Exceptions: In the Slack suite of Table 2, Twin Utility is 66.7%, lower than Default's 90.5%, with ASR dropping from 92.4% to 0.0%. The authors' claim that utility is "slightly above baseline" does not cover this suite, nor the Utility drop for Gemini-3.5-Flash.
    • Adaptive: In Table 3, with GPT-5.2 and a 100-character budget, Safe Agent single-round ASR is 0.0%, Explore Agent forwarding ASR is 100.0%, and full multi-round ASR is 4.7%. The authors consider any nonzero success a safety failure.
    • Author conclusions: The authors argue that the hint budget empirically tunes the safety–utility trade-off and that the approach can be used to build adaptive and safer LLM agents. They also state there is no formal guarantee and stronger attacks could still defeat the design.

Related papers

Show 3 more papers
Read originalarxiv.org