Retrieve select relevant policies
Rank stored policies for the task, select up to three across policy families, and include their covering parents.
Continual Security Policy Learning for LLM Agents
1Carnegie Mellon University 2University of Massachusetts Amherst
*Equal contribution.
LLM agents read private data, call tools, and edit software, exposing them to direct jailbreaks, indirect prompt injections, and insecure code-generation attacks. Existing defenses typically cover one interface and remain fixed after deployment.
Self-Evolving Defense (SED) instead treats each judged failure as training data for an external policy memory. It converts harmful trajectories into reusable security policies and retrieves the relevant policies on later tasks, while keeping the agent's model weights frozen.
Adaptive attackers revise their prompts after each failure, while static defenses retain nothing from prior attempts. The result is a defense that looks strong on a single shot and collapses once the attacker can iterate.
This gap motivates a defense that updates from observed failures without retraining the agent.
SED wraps a frozen agent with a policy memory that is read during an episode and updated only after the episode has been scored.
Rank stored policies for the task, select up to three across policy families, and include their covering parents.
Run the frozen agent with the retrieved policies appended to its system prompt.
Score the full role-labeled trajectory; retain only harmful episodes and their supporting evidence.
Distill the failure into enforceable policies, then merge or organize them in the policy tree.
Auto-advances · hover to pause · click a step to jump
We evaluate three open-source models on eight chat, tool-use, and coding benchmarks. Each benchmark starts from an empty memory, evolves over its own stream, and uses its official grader.
Main results · DeepSeek-V4-Flash · 8 benchmarks, 5 defenses
Compared against the undefended agent and the strongest static baseline on each benchmark. Attack success rate (ASR) is lower-is-better; utility is higher-is-better.
| Defense | WJB | HBdir | HBadv | RC | AgH | FCV | ADojo | ADyn |
|---|---|---|---|---|---|---|---|---|
| Undefended | 31.40 | 25.94 | 25.55 | 95.60 | 42.60 | 19.17 | 49.00 | 33.04 |
| Llama Guard 3 | 29.31 | 2.81 | 8.16 | 89.12 | 3.00 | 20.43 | 49.32 | 29.11 |
| SafeHarbor | 17.55 | 15.00 | 9.64 | 49.28 | 1.59 | 5.71 | 11.90 | 10.18 |
| DRIFT | 23.90 | 24.06 | 16.64 | 91.12 | 31.06 | 1.48 | 3.69 | 2.14 |
| GuardAgent | 35.65 | 23.44 | 18.16 | 82.40 | 18.34 | 6.19 | 12.60 | 9.82 |
| SED | 2.10 | 0.94 | 3.07 | 11.30 | 6.20 | 2.91 | 0.42 | 0.54 |
| Defense | AgH | ADojou | ADojoua | ADynu | ADynua | FCVres |
|---|---|---|---|---|---|---|
| Undefended | 67.30 | 89.69 | 44.36 | 73.33 | 49.11 | 62.60 |
| Llama Guard 3 | 57.50 | 92.78 | 42.36 | 65.00 | 45.36 | 55.80 |
| SafeHarbor | 41.83 | 89.69 | 78.19 | 71.67 | 66.43 | 56.00 |
| DRIFT | 76.73 | 86.60 | 76.08 | 28.33 | 28.21 | 67.60 |
| GuardAgent | 75.85 | 73.20 | 58.90 | 53.33 | 43.04 | 38.80 |
| SED | 63.10 | 89.69 | 87.88 | 73.33 | 69.29 | 68.80 |
DTap evaluates indirect prompt injection against CRM, workflow, and coding agents on three models. Figure 3 places every defense on the security–capability plane; the card below gives the per-domain numbers.
Macro-average indirect attack success (%) across CRM, workflow, and code
Model outer ring
Defense corner chip; no-defense shows the model only
Ideal defenses sit in the lower-right: high benign utility, low attack success. Hover a badge to zoom and focus it; nearby points fade back. SED badges cluster toward the ideal corner across models.
DTap · 3 models · CRM, workflow, and code agents
Headline number is indirect-injection ASR, undefended → SED. Direct-injection ASR and benign task success are shown underneath each chip.
| Defense | CRM | Workflow | Code | ||||||
|---|---|---|---|---|---|---|---|---|---|
| ind ↓ | dir ↓ | ben ↑ | ind ↓ | dir ↓ | ben ↑ | ind ↓ | dir ↓ | ben ↑ | |
| DeepSeek-V4-Flash | |||||||||
| Undefended | 86.67 | 96.67 | 87.12 | 78.85 | 83.12 | 91.34 | 89.70 | 95.04 | 99.70 |
| Llama Guard 3 | 66.67 | 67.42 | 82.42 | 54.81 | 45.45 | 92.12 | 43.64 | 41.67 | 98.48 |
| SafeHarbor | 58.67 | 80.00 | 39.39 | 62.50 | 67.53 | 88.06 | 83.64 | 68.60 | 91.21 |
| DRIFT | 33.33 | 83.33 | 86.06 | 57.69 | 72.73 | 92.81 | 20.86 | 90.91 | 99.09 |
| GuardAgent | 48.32 | 88.89 | 80.00 | 66.35 | 64.94 | 90.70 | 27.95 | 92.56 | 99.39 |
| SED | 21.48 | 22.47 | 86.59 | 19.23 | 31.17 | 90.15 | 26.06 | 23.97 | 99.09 |
| GLM-5.2 | |||||||||
| Undefended | 41.33 | 32.22 | 72.12 | 32.38 | 47.30 | 92.33 | 49.70 | 57.85 | 97.88 |
| Llama Guard 3 | 18.67 | 17.78 | 75.15 | 8.74 | 32.00 | 93.94 | 47.56 | 51.67 | 98.78 |
| SafeHarbor | 12.00 | 13.33 | 58.18 | 26.00 | 28.00 | 92.60 | 19.39 | 28.10 | 98.78 |
| DRIFT | 10.67 | 20.00 | 75.76 | 21.20 | 37.30 | 93.20 | 14.55 | 43.80 | 98.78 |
| GuardAgent | 36.00 | 32.22 | 73.33 | 30.50 | 50.70 | 90.50 | 36.65 | 53.72 | 98.18 |
| SED | 8.26 | 12.20 | 75.78 | 9.62 | 17.33 | 91.78 | 3.66 | 2.50 | 97.87 |
| Kimi K3 | |||||||||
| Undefended | 41.33 | 42.22 | 88.48 | 25.81 | 26.32 | 89.22 | 36.59 | 51.28 | 99.62 |
| Llama Guard 3 | 21.33 | 34.44 | 88.48 | 8.08 | 16.88 | 93.67 | 33.94 | 43.48 | 100.00 |
| SafeHarbor | 15.33 | 17.78 | 70.30 | 4.30 | 11.69 | 91.64 | 9.76 | 30.25 | 98.18 |
| DRIFT | 16.67 | 30.00 | 87.88 | 21.43 | 30.67 | 93.41 | 9.09 | 40.68 | 99.62 |
| GuardAgent | 25.33 | 41.11 | 81.82 | 19.35 | 28.57 | 87.58 | 18.18 | 46.90 | 100.00 |
| SED | 3.33 | 7.78 | 88.18 | 5.88 | 10.39 | 88.18 | 2.28 | 4.39 | 99.63 |
On DeepSeek-V4-Flash, SED lowers AutoDAN-Turbo and X-Teaming success from 98.0% and 50.0% to 17.8% and 7.8%. The same advantage remains on GLM-5.2 and Kimi K3.
| Attack | NoDef | LG | SH | DR | GA | SED |
|---|---|---|---|---|---|---|
| DeepSeek-V4-Flash | ||||||
| AutoDAN-Turbo | 98.00 | 97.92 | 93.44 | 79.70 | 87.80 | 17.82 |
| X-Teaming | 50.00 | 39.90 | 35.21 | 50.73 | 47.40 | 7.81 |
| GLM-5.2 | ||||||
| AutoDAN-Turbo | 30.31 | 29.25 | 23.12 | 27.81 | 38.44 | 7.10 |
| X-Teaming | 15.62 | 14.90 | 10.10 | 13.12 | 15.94 | 8.50 |
| Kimi K3 | ||||||
| AutoDAN-Turbo | 19.38 | 16.56 | 12.19 | 19.06 | 19.18 | 10.43 |
| X-Teaming | 28.13 | 15.58 | 13.90 | 20.76 | 20.92 | 10.51 |
AutoDAN-Turbo jailbreaks 98 of 100 undefended behaviors at a median of 3 iterations. Against SED, it succeeds on 10 of 100 and requires a median of 11.5 iterations for those successes.
We test whether the gains come from extra prompt text or from the judge alone.
| Variant | AutoDAN-Turbo | X-Teaming | RedCode |
|---|---|---|---|
| No memory (undefended) | 98.00 | 50.00 | 95.60 |
| + episodic recall | 42.27 | 19.69 | 25.60 |
| + policy synthesis | 28.12 | 14.00 | 13.70 |
| + consolidation (full SED) | 17.82 | 7.81 | 11.30 |
Episodic recall already cuts attack success, policy synthesis lowers it further, and tree consolidation yields the full result. Because synthesis and consolidation compress the retrieved text, prompt length does not explain the ordering. GuardAgent also uses a model for safety decisions but remains at 87.8% and 47.4% under the two adaptive attacks, showing that the judge alone is insufficient.
Freezing the memory after 100 behaviors lowers cumulative ASR from 23.4% to 13.4%; continued evolution reaches 9.4%. Applying the frozen attack-derived library to disjoint benign data costs at most 2.2 utility points.
| Benign benchmark | No memory | Attack-derived policies |
|---|---|---|
| WildJailbreak benign | 97.60 | 96.00 |
| AgentHarm benign | 66.90 | 64.68 |
@inproceedings{le2026sed,
title = {Self-Evolving Defense: Continual Security Policy Learning
for LLM Agents},
author = {Le, Minh Nhat and Gondi, Nisarga and Peng, Yibo and Ni, Ronghao
and Jia, Limin and Chen, Beidi and Zheng, Haizhong},
year = {2026},
note = {Preprint},
url = {https://infini-ai-lab.github.io/SED/},
}