Skip to content

Learning to Inject: Automated Prompt Injection via Reinforcement LearningLearning to Inject: Automated Prompt Injection via Reinforcement Learning

arXiv· arXiv:2602.05746· NeurIPS 2026· Xin Chen, Jie Zhang, Florian Tramèr·Indexed by this site · 2026-10-12· Originally publishedSelected AttacksSelectedAttention41

Quick read

Attacks

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

AutoInject learns injection suffixes on AgentDojo with black-box RL, with Gemini-2.5-flash ASR 58.00%.

Threat modelBlack-box: only query access to the victim agent pipeline. The goal is to execute tool calls with correct parameters from the injection target. r_sec indicates whether the injection action was executed; r_util is optional, indicating whether the original user task was completed. Transfer deployment does not require online utility. The suffix is embedded in external content. Token probabilities are not required, nor is full victim text output observed.

Questions
When LLM agents process external content such as email and web pages, adversarial instructions embedded in it can hijack tool behavior. The authors state that manual red teaming and jailbreak optimizers both struggle to reliably produce tool calls with correct parameters.
Methods
AutoInject treats suffix generation as token-level decisions, uses a feedback model to compare candidates against the current best suffix, converting sparse success/failure into continuous rewards, and then updates a 1.5B policy with GRPO; it can query online or be trained offline and transferred.
Experiments and results
On AgentDojo, AutoInject's ASR is higher than templates and several optimization baselines; Gemini-2.5-flash full set is 58.00%, Meta-SecAlign-70B hardest task is 21.88%. Offline suffixes transfer, but utility drops across tasks.
Limitations and future work
The authors note the attack assumes the model executes tool calls immediately; clarification requests and planning-execution separation bypass this setting. Evaluation is on AgentDojo and the listed models, and the paper does not report attack numbers for CaMeL and IPI-Guard.
Experimental setupGemini-2.5-flash、GPT-4.1-nano et al. · AgentDojo · ASR、utility under attack et al.
Evaluated models
Gemini-2.5-flashGPT-4.1-nanoGPT-5-nanoClaude-Sonnet-3.5Qwen3-4BGemma3-4BMeta-SecAlign-70BGPT-4o-miniGemini-2.0-flash
Benchmarks
AgentDojo
Metrics
ASRutility under attackbenign utility
AI summaryand selection rationaleResearchers from ETH Zürich propose AutoInject, which uses reinforcement learning to automatically generate prompt injection suffixes, achieving attack success rates on AgentDojo against multiple production models that exceed template attacks and optimization baselines such as GCG and TAP. The method uses a comparison-based feedback model to convert the binary injection success signal into a dense reward, trains Qwen2.5-1.5B with GRPO to generate suffixes, and supports both online querying and offline training of transferable suffixes. On Gemini-2.5-Flash the success rate is 58%, on GPT-5-nano it is 11.49%, while template attacks peak at 23.6% and 1.6%, respectively; on Meta-SecAlign-70B, which is specifically fine-tuned to resist prompt injection, it still achieves a 21.88% success rate, whereas template attacks completely fail. Code is open-sourced on GitHub.

Researchers from ETH Zürich propose AutoInject, which uses reinforcement learning to automatically generate prompt injection suffixes, achieving attack success rates on AgentDojo against multiple production models that exceed template attacks and optimization baselines such as GCG and TAP. The method uses a comparison-based feedback model to convert the binary injection success signal into a dense reward, trains Qwen2.5-1.5B with GRPO to generate suffixes, and supports both online querying and offline training of transferable suffixes. On Gemini-2.5-Flash the success rate is 58%, on GPT-5-nano it is 11.49%, while template attacks peak at 23.6% and 1.6%, respectively; on Meta-SecAlign-70B, which is specifically fine-tuned to resist prompt injection, it still achieves a 21.88% success rate, whereas template attacks completely fail. Code is open-sourced on GitHub.

Why it was selectedThe paper raises prompt injection success rates to 58% on AgentDojo and provides transferable suffixes that require no online access, making it easier for defenders to test the generalization of guardrails.

Related events and news

1 events · 1 news mentions

News that mentions this paper

模安局盘点NeurIPS 2026 AI安全七大研究重点

Paper analysis

6 questions; open one to read the full answer

  1. What problem does this paper attempt to solve?

    Black-box RL turns sparse injection success/failure into comparative rewards, thereby automatically learning injection suffixes.

    How to automatically learn injection suffixes under black-box conditions so that agents issue tool calls with correct parameters, rather than only increasing generalized compliance.

    • Scenario: The authors state agents retrieve documents, process email, browse the web, and call tools; adversarial instructions in external content can cause data exfiltration, unauthorized operations, or manipulated output without the user's knowledge.
    • Existing shortcomings: The authors state injection still relies mainly on manual red teaming and handcrafted prompts, and directly adapting jailbreak optimizers has limited benefit. The authors state compliance probability does not correspond to correct tool parameters, and random suffixes mostly fail, so standard optimizers lack a followable signal.
    • Assumption: Even when both suffixes fail, comparing against the best suffix so far can still indicate which is closer to success, yielding a dense reward.
    • Method: AutoInject uses this comparison reward with GRPO, supporting budget-limited online attacks and offline transferable suffixes that do not need utility access at deployment; when utility feedback is available, it is used as a secondary objective.
    • Threat model:
      • Goal: Execute the specific tool call in the injection goal; when signals are available, also preserve the original user task.
      • Knowledge: The paper writes black-box, with only query access to the victim pipeline; it does not require token probabilities and does not assume observation of the victim's full output.
      • Capability: The suffix is embedded in external content. rsec is available when injection execution can be detected; rutil is optional, and the authors state it suits offline optimization or defender testing, while transfer deployment does not need online utility.
      • Victim system: LLM agents that encounter untrusted external content, with the evaluation environment AgentDojo.
  2. What related research exists?

    Related work is divided into manual injection, jailbreak optimization, and injection-specific optimization, and this paper assumes a weaker setting.

    Manual prompt injection

    • External content hijacking: Greshake et al. (2023) and Willison (2022) describe how adversarial inputs in untrusted web pages, emails, documents, or APIs manipulate models.
    • Manual strategies: Liu et al. (2024b) covers context ignoring, fake completion, and combined attacks; Kang et al. (2024) uses payload splitting and virtualization.
    • Scalability: The paper notes that most injections represented by Liu et al. (2023), Debenedetti et al. (2024), and Yi et al. (2025) rely on trial-and-error manual prompts and are hard to scale to different targets.

    Automated jailbreaks

    • Suffixes and search: GCG (Zou et al., 2023) does gradient-based suffix optimization, TAP (Mehrotra et al., 2024) does LLM tree search, AutoDAN (Liu et al., 2024a) uses genetic algorithms.
    • Direct transfer: The paper notes that Hofer et al. (2025) finds limited benefit from adapting jailbreak optimizers to injection, because injection requires parameterized actions that exactly match ground truth.
    • Comparison feedback: Zhang et al. (2025) uses comparison feedback for black-box attacks; the authors adapt it as a dense reward for GRPO.

    Injection-specific optimization

    • RL-Hammer: Wen et al. (2025) learns a policy on a training split and transfers it, and injects a weaker auxiliary model into the target environment to densify feedback. The paper considers this access assumption strong.
    • Evolutionary search: Nasr et al. (2025) uses LLM mutation for evolutionary search and assumes access to the victim's full output; the paper states this is stronger than the indirect injection it studies.
    • Automated research: Panfilov et al. (2026) automatically discovers injection algorithms but assumes access to token probabilities; the authors state AutoInject does not need this signal.

    Baselines and benchmarks

    • Baseline methods: AgentDojo templates are Direct Instruction, Ignore Previous, Important Instructions, InjecAgent (Zhan et al., 2024), System Message, Tool Knowledge; optimization methods are GCG, TAP, random adaptive attack (Andriushchenko et al., 2024), RL-Hammer, and evolutionary search.
    • Benchmark/dataset: AgentDojo, with domains banking, travel, workspace, Slack. The model-level defense comparison is Meta-SecAlign-70B (Chen et al., 2025).

    The authors position AutoInject as a per-sample black-box method: it uses learned comparison feedback to handle sparse 0/1 signals, supports both online queries and offline transfer, and requires less access to the target environment or victim full output than RL-Hammer and the original Nasr paper.

  3. How does the paper address this problem?

    AutoInject uses a comparison model to turn 0/1 success or failure into dense reward, then uses GRPO to optimize a 1.5B suffix policy.

    AutoInject frames suffix generation as a finite-length token decision, uses a feedback model to turn sparse success/failure into continuous comparison scores, and updates the policy with GRPO.

    Problem setting and formalization

    • MDP: The state contains the injection goal g, user task context c, and generated tokens; the action is the next token, and the transition is deterministic concatenation. After an end token or the length limit T, the suffix x is obtained.
    • Reward: The victim pipeline gives rsec and optional rutil, both in 0 to 1, only at the end of the episode. The goal is to maximize expected reward given g and c.
    • Policy and evaluation: The main text parameterizes the policy as Qwen2.5-1.5B. Appendix Table 7 writes Qwen2-1.5B, Table 9 writes Qwen2.5-1.5B-Instruct, and the paper does not explain the name differences. AgentDojo uses ground-truth functions to determine both whether the user task is completed and whether the injection goal is executed.

    Comparison feedback and composite reward

    • Reference suffix: Training maintains x*, the suffix with the highest composite reward, initially empty, replaced when a higher reward appears.
    • Feedback model: It takes g, c, and two suffixes, first reasons, then outputs a binary label. rpref is obtained by softmax over the log-probabilities of the label token, representing the probability that the candidate is better than x*; it is still defined when both fail. Appendix G gives the full prompt.
    • Composite reward: R(rsec,rutil,rpref)=α· rsec+β· rutil+γ· rpref, corresponding to attack success, utility preservation, and comparison signal respectively. Without rutil, the utility term is removed. The appendix gives α=0.7, β=0.3; γ decreases from 0.8, 0.5, 0.3 to 0.1 according to the proportion of queries used. The feedback model is GPT-4o-mini, except when attacking GPT-4.1-nano as written in Table 7, where the paper does not give a replacement name.

    Policy optimization

    • Within-group advantage: For the same (g, c), sample K suffixes, with advantage Ai=(Ri−mean({Rj}))/std({Rj}). The authors use it to retain relative gradients even when the whole group's rsec is still 0.
    • Update: Maximize the clipped importance-sampling objective with a KL penalty against the reference policy. Algorithm 1 stops when the query count reaches budget B; it stops early when any single suffix satisfies rsec=rutil=1.
    • Training unit: Each (injection goal, user task) pair is updated separately until both scores are 1 or the budget is exhausted.

    Implementation settings and two modes

    • Default hyperparameters: suffix max 30 tokens, temperature 0.9, top-p 0.95, K=8, 5 iterations per task, learning rate 1×10^-5, seed 42, KL coefficient 1.0, B=260 (Table 7, Section 4.1).
    • Prefix: The generated suffix is appended after AgentDojo's fixed important instruction template; the policy optimizes only the suffix. Appendix A.3 gives the full template.
    • Other hyperparameters: When attacking Gemma3-4B and Qwen3-4B, 32 iterations, KL coefficient 0.1, warmup 20 steps; Gemma learning rate 5×10^-6. Meta-SecAlign warmup is 4 steps.
    • Two modes: Online mode queries the victim within budget; transfer mode optimizes offline on proxy tasks and models, and does not need utility signals at deployment.
  4. What experiments did the paper conduct?

    Gemini-2.5-flash full ASR is 58.00%, and on SecAlign's hardest task it is 21.88%.

    Experimental Setup

    • Benchmark: AgentDojo has 97 user tasks, with domains banking, travel, workspace, Slack. Full evaluation n=949; Claude-Sonnet-3.5 uses only the 144 banking tasks due to API cost.
    • Victim models: Gemini-2.5-flash, Gemini-2.0-flash, GPT-4.1-nano, GPT-5-nano, GPT-4o-mini, Claude-Sonnet-3.5, Qwen3-4B, Gemma3-4B, Meta-SecAlign-70B. The main text also reports that Claude Haiku 4.5 first asks for clarification.
    • Attack side: The policy is the Qwen2.5-1.5B mentioned in the main text; the feedback model is GPT-4o-mini, except when attacking GPT-4.1-nano, where the replacement model is not specified in the paper.
    • Baselines: Six AgentDojo templates; optimization methods are GCG, TAP, random adaptive attack, RL-Hammer, and an evolutionary search reimplemented by the authors following Nasr et al. (2025). GCG and TAP numbers are cited from Hofer et al. (2025).
    • Metrics: benign utility is task completion rate without attack; ASR is the proportion of injection goals executed; utility under attack in the main text is task completion rate when the adversarial suffix is present. Appendix B additionally gives four aggregation rules based on whether safety score σ and utility score μ equal 1.
    • Protocol: Online budget B=260, and the authors state optimization baselines use the same budget. Success is determined by AgentDojo's programmatic functions, not an LLM judge. Transfer experiments use 3 seeds; Appendix F gives Wilson 95% intervals.

    Main Results

    The table below shows template comparisons on the full or banking suite. Qwen3-4B, Gemma3-4B, and Meta-SecAlign-70B, which use a different protocol, are omitted; their numbers appear later.

    Swipe horizontally to read the table

    ModelNo-attack utilityAutoInject utilityAutoInject ASRHighest template ASR
    Gemini-2.5-flash (n=949, Table 1)48.45%41.77%58.00%23.60% (Important Instructions)
    GPT-4.1-nano (n=949, Table 1)39.18%60.38%47.97%20.48% (Tool Knowledge)
    GPT-5-nano (n=949, Table 1)80.41%90.20%11.49%1.60% (Direct)
    Claude-Sonnet-3.5 (banking n=144, Table 1)75.00%98.52%12.59%5.69% (Tool Knowledge)
    Gemini-2.0-flash (n=949, Table 14)47.42%64.81%39.62%8.01% (Important Instructions)
    GPT-4o-mini (n=949, Table 14)73.20%64.28%50.37%22.87% (Important Instructions)
    • The authors state template ASR rarely exceeds 25%, and GPT-5-nano and Claude are more robust to templates. In the table, Gemini-2.5-flash and GPT-4o-mini have lower utility under attack than in the no-attack column; the other four rows are higher than the no-attack column.
    • The authors state that once utility enters the reward, the policy tends to favor suffixes that do not interfere with the user task, so utility under attack is sometimes higher than the no-attack baseline.
    • The authors believe Claude-Sonnet-3.5's low ASR may come from Amazon Bedrock Guardrails on OpenRouter. The Table 1 note states that improvements over the baseline are all statistically significant; Appendix F.1 gives p<0.0001 for the three full models and p=0.031 for Claude. The introduction also states that in most cases McNemar p<0.05.

    Optimization-based attacks

    • What was tested: Following the task selection of Hofer et al. (2025), 5 user tasks per suite times 4 injection tasks; Appendix F.2 writes n=80. Targets are Qwen3-4B and Gemma3-4B.
    • Results: In Table 2, AutoInject ASR is 42.50% and 35.00%. In the same table, on Qwen3-4B, Direct 11.20%, GCG 23.00%, TAP 36.60%, Adaptive Attack 30.00%, evolutionary search 40.00%; on Gemma3-4B, GCG 20.20%, Adaptive Attack 26.25%, evolutionary search 35.00%, TAP not reported. On the full banking suite, targeting GPT-5-nano, with generator, judge model, and budget aligned, AutoInject is 36.57% and evolutionary search is 13.9% (Appendix E.4).
    • Authors' interpretation: The authors state the jailbreak optimization targets affirmative tokens, and injection requires the correct tool call structure. The authors state evolutionary search is close to AutoInject on 4B targets; in Table 2, both are 35.00% on Gemma3-4B. The authors state the gap for RL policies is larger when the target is harder.

    Defense evaluation and transfer

    • Meta-SecAlign-70B: The 2 hardest user tasks per suite times 4 injection tasks; the appendix writes n=32. No-attack utility 37.50%; AutoInject utility 39.29%, ASR 21.88%. Among templates, Tool Knowledge ASR is 3.12%, and the rest are 0.00% (Table 3). The authors state preference optimization can resist known templates, while the RL attack is out-of-distribution relative to a fixed attack set; the authors believe the retained utility indicates they found a gap in the preference boundary. Appendix F.3 states McNemar p<0.05.
    • Fixed-injection transfer: Both are trained on GPT-5-nano, then tested on 16 banking user tasks and a fixed injection_task_4, with 3 seeds. AutoInject uses 5 source tasks and at most 260 queries per string; RL-Hammer uses 114 tasks and 3900 queries. Table 4 ASR: GPT-4o-mini 45.0±9.2 vs. 22.9±2.9 (p<0.05), GPT-4.1-nano 7.9±5.8 vs. 4.2±5.9, Gemini-2.0-flash 2.5±3.1 vs. 2.1±2.9, Gemini-2.5-flash 1.7±3.6 vs. 0.0±0.0. The authors state utility is close to the no-attack baseline and that four of five targets match or exceed it; the table lists only four, with GPT-5-nano omitted because it falls largely within RL-Hammer's training distribution.
    • Cross-task transfer: 8 (user task, injection task) pairs, 2 pairs per domain. In Table 5, AutoInject ASR is GPT-4o-mini 48.3±6.5, GPT-5-nano 10.0±7.0, GPT-4.1-nano 20.0±11.4, Gemini-2.0-flash 15.0±8.5, Gemini-2.5-flash 55.8±14.1; RL-Hammer is 25.0±0.0, 25.0±0.0, 4.2±7.2, 4.2±7.2, 0.0±0.0 respectively. The authors state p<0.05 for four targets except GPT-5-nano, and that RL-Hammer's successes on GPT-5-nano are exactly the 2 in-distribution banking task pairs. Cross-task utility drops: GPT-4o-mini is 37.5±8.2, no-attack 75.0; Gemini-2.5-flash is 6.7±8.0, no-attack 50.0.

    Other ablations and analysis

    • Banking suite ablation (Table 6, n=144): AutoInject on GPT-4.1-nano has ASR 97.69%, utility 62.50%; on GPT-5-nano 36.57%, 87.50%; removing GRPO gives 88.32%/51.82% and 19.44%/87.50%; removing feedback gives 95.14%/59.02% and 25.00%/84.03%; removing both gives 90.51%/50.36% and 17.36%/87.50%.
    • The authors state the relative drop from removing GRPO is larger on harder targets, and state it is about 47% vs. 10%; they state feedback contributes an absolute improvement of 11.57% on GPT-5-nano and an absolute drop of 2.5% on GPT-4.1-nano.
    • Search-style adaptation with the same reward and randomly mutating 30% of tokens each round (Table 17): Gemini-2.5-flash ASR 34.04%, Claude-Sonnet-3.5 7.64%, utility 77.08%. On GPT-4o-mini and GPT-5-nano, search-style utility is 67.33% and 93.99%, higher than AutoInject's 64.28% and 90.20%.
    • Mutation rate sweep (Table 16, banking 144 tasks): with mr 0.1/0.2/0.3/0.5, GPT-4o-mini ASR is 84.0%/84.7%/89.6%/84.7%, Gemini-2.5-flash is 55.6%/55.6%/56.9%/53.5%, GPT-5-nano is 12.5%/11.8%/16.0%/16.0%.
    • Suffixes repeating the allelujah token cover at most 70/949 task pairs on Gemini-2.5-flash, 53/949 on GPT-4o-mini, and at most 6/949 on GPT-5-nano (Table 15). The authors believe it may come from few-shot examples in the policy prompt and speculate it relates to statistical patterns of liturgical text in pretraining; the full suffix is in Appendix E.2.
    • Exhausting B=260 on a single NVIDIA Titan RTX takes about 1.5 hours, and the authors state the time is dominated by victim model API latency (Appendix A.4).
  5. What are some points that can be further explored?

    The authors point out that the immediate tool-calling assumption can be bypassed by clarification-seeking behavior and planning-execution separation.

    Limitations and future directions noted by the authors

    • Immediate execution assumption: Section 5 states the attack follows AgentDojo's setting, where the model executes tool calls immediately after receiving instructions. The authors report that Claude Haiku 4.5 consistently asks for clarification in experiments, interrupting this pipeline, and believe that seeking confirmation before sensitive operations may constitute a defense, orthogonal to input filtering or safety fine-tuning.
    • Planning-execution binding: Section 5 states the attack assumes tool call decisions are influenced by processed content. The authors state that CaMeL and IPI-Guard commit to a fixed action sequence before touching untrusted data, thereby bypassing this threat model, while also stating these architectures sacrifice agent flexibility in practice.
    • Policy capacity: Appendix D and Appendix E.4 state attack effectiveness varies with policy capacity, and leave this to future work.

    Experimental coverage

    • Victim models include Gemini-2.5-flash, Gemini-2.0-flash, GPT-4.1-nano, GPT-5-nano, GPT-4o-mini, Claude-Sonnet-3.5, Qwen3-4B, Gemma3-4B, Meta-SecAlign-70B, and Claude Haiku 4.5 discussed in Section 5. The policy is written as Qwen2.5-1.5B in the main text; the feedback model is GPT-4o-mini, except when attacking GPT-4.1-nano as written in Table 7, where the paper does not specify the replacement model name.
    • The evaluation environment is the four AgentDojo domains. Several production models use the full n=949; Claude-Sonnet-3.5 uses the 144 banking tasks; the protocol in Table 2 is written as n=80 in the appendix; Meta-SecAlign-70B uses the hardest tasks, written as n=32 in the appendix.
    • Whether injection succeeds is determined by AgentDojo's programmatic functions. Appendix F reports Wilson 95% intervals; Table 1 uses McNemar, transfer uses two-sided Mann-Whitney U, and transfer uses 3 seeds.
    • The online budget is at most 260 queries per pair. In the comparison with RL-Hammer, the latter uses 114 banking tasks and 3900 queries; GCG and TAP numbers are cited from Hofer et al. (2025).
    • Section 5 explains that CaMeL and IPI-Guard bypass this threat model through planning-execution decoupling; the paper does not report attack results on these two architectures.
  6. Summarize the main content of the paper

    Injection suffixes learned by black-box GRPO outperform templates on AgentDojo and transfer offline.

    AutoInject uses black-box reinforcement learning to automatically generate prompt injection suffixes for LLM agents.

    • Problem: The injection must make the agent issue tool calls with correct parameters. The authors state that the success signal is sparse, and that both manual templates and jailbreak optimization targeting compliance probability are misaligned with this objective.
    • Method: A 1.5B policy samples suffixes conditioned on the injection target and user task; a feedback model gives a comparative score relative to the current best suffix, which is combined with a safety score and an optional utility score into a reward, updated with GRPO. The suffix is appended after a fixed instruction prefix. The online budget is 260 queries; offline optimization and transfer are also possible, and no utility signal is needed at deployment.
    • Main results: On the full AgentDojo (n=949), Gemini-2.5-flash has an ASR of 58.00%, GPT-4.1-nano 47.97%, and GPT-5-nano 11.49% (Table 1). Claude-Sonnet-3.5 achieves 12.59% on the banking 144 tasks with Guardrails.
    • Comparisons: On the Hofer protocol subset, Qwen3-4B achieves 42.50% and Gemma3-4B 35.00%, the latter matching evolutionary search (Table 2). On Meta-SecAlign-70B's hardest task, AutoInject achieves 21.88%, while templates achieve 0.00% or 3.12% (Table 3, n=32).
    • Transfer: When the source model is GPT-5-nano, fixed injections transferred to GPT-4o-mini achieve an ASR of 45.0%±9.2, compared to RL-Hammer's 22.9%±2.9 (Table 4). Across tasks, Gemini-2.5-flash achieves an ASR of 55.8%±14.1 and utility of 6.7%±8.0, with no-attack utility at 50.0 (Table 5).
    • Authors' conclusion: The authors argue that comparative rewards enable GRPO to optimize the sparse injection objective; learned suffixes can maintain or improve task utility in some settings and bypass template-based and preference defenses like Meta-SecAlign. They therefore emphasize the need for defenses that handle utility-preserving automatic injections and note that the immediate-execution assumption can be bypassed by clarifying behavior or plan-execution separation.

Related papers

Show 3 more papers
Read originalNeurIPS 2026