# Learning to Inject: Automated Prompt Injection via Reinforcement Learning

*Xin Chen, Cynthia, Jie Zhang, Florian Tramer*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/152341) · [OpenReview](https://openreview.net/forum?id=TmeVCourtc) · [alphaXiv](https://www.alphaxiv.org/abs/2602.05746) · [Open on the map](../papers.html#p152341)

Category: [AI Safety, Security & Alignment](../pcat/16.md) › [LLM Safety Attack Strategies](../pgroup/451.md) · Type: new method · Keywords: prompt injection, LLM agent security, reinforcement learning, adversarial suffix generation, black-box attack, automated jailbreak

Areas: [AI Agents](../areas/agents.md) › Agent Robustness › LLM Agent Attacks; [Safety & Security](../areas/safety.md) › Language Model Security › Prompt Injection and Resource Attacks; [RL for LLMs & Agents](../areas/llm-rl.md) › Language Model Alignment › Reward Hacking

## Summary
AutoInject is a black-box reinforcement learning framework that learns adversarial suffixes for prompt injection by converting binary success signals into a dense comparison-based reward.

## Explained to a 5-year-old
Some computer programs can talk to each other and help us, but bad guys can trick them by adding hidden words. Finding those hidden words by hand is slow and hard. This paper teaches a computer to guess the hidden words by playing a game that gives it hints. The computer learns tricks that work even on special security models that try to stop tricks. This helps make the talking programs safer.

## Explained to a 5-year-old, longer
Some computer programs can talk to each other and do things for us. But sometimes bad people can trick them by adding secret words at the end of a message. It is very hard to find those secret words automatically because they almost never work by chance. Existing methods that try to find tricks for other problems do not work well here. This paper creates a new way to teach a computer to guess the secret words using a game-like learning process. The computer learns to compare different guesses and picks the best ones. It can be used both when the computer is online and when it is trained offline. The method also tries to make sure the tricks still help the program do its job. On a test set called AgentDojo, the new method beats many old tricks. It also breaks a special security model called Meta-SecAlign-70B that was made to resist tricks. This shows how much better the new method is compared to the old ones. Overall, it gives researchers a reliable way to test how safe these talking programs really are.

## For a technical reader
The paper addresses the challenge of automatically generating adversarial suffixes that trigger prompt injection in LLM agents, where binary success signals provide little gradient for conventional optimizers. It proposes a black-box reinforcement learning framework that uses a comparison-based reward to turn the sparse binary feedback into a dense learning signal, supporting both online query-based attacks and offline transferable suffix generation. The approach also incorporates a utility objective when task-completion feedback is available, ensuring that injected prompts still achieve the intended functionality. Evaluations on the AgentDojo benchmark show statistically significant improvements over baseline attacks (p<0.05) and the learned suffixes successfully compromise a dedicated defense model (Meta-SecAlign-70B) where template attacks fail. The work establishes an automated baseline for prompt injection research and highlights a gap between preference-based defenses and adaptive optimization-based attackers.

## Problem
LLM agents are vulnerable to prompt injection attacks that require specific tool calls, but the binary success signal makes it difficult for random suffixes to provide learning gradients. This creates a core challenge of automatically discovering effective injection suffixes without human-crafted prompts.

## Method
The approach uses a black-box reinforcement learning loop where a comparison-based reward scores candidate suffixes against the best seen so far, turning the sparse binary feedback into a dense learning signal. It supports both online query-based attacks and offline training of transferable suffixes, and adds a utility objective when task-completion feedback is available.

## Results
AutoInject achieves statistically significant improvements over baseline attacks on AgentDojo (p<0.05) and successfully breaks the Meta-SecAlign-70B defense model where template attacks fail.

## Contributions
Introduces a black-box RL framework that learns adversarial suffixes for prompt injection using a comparison-based reward, supports online and offline attack modes, and incorporates a utility objective when task-completion feedback is available.

## Practical relevance
Provides an automated baseline for evaluating prompt injection defenses and highlights the gap between preference-based defenses and adaptive optimization-based attackers.

## Research questions this paper is counted under

- [How can we robustly detect and mitigate prompt injection attacks in autonomous LLM agents?](../q/182.md)

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/152341)
