Self-Evolving Defense

Continual Security Policy Learning for LLM Agents

Minh Nhat Le2*, Nisarga Gondi1*, Yibo Peng1, Ronghao Ni1, Limin Jia1, Beidi Chen1, Haizhong Zheng1

1Carnegie Mellon University    2University of Massachusetts Amherst

*Equal contribution.

0.42%targeted ASR on AgentDojo
7.8%X-Teaming ASR on HarmBench
8benchmarks tested across three threat surfaces

Introduction

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.

The SED loop: policies are retrieved into the agent's prompt, the agent acts, a judge scores the trajectory, and harmful episodes are synthesized into new policies for later episodes.
Figure 1: The SED loop. Memory is read during an episode and written only after an external judge scores the completed trajectory, so a successful attack can influence later episodes but never the one it appears in.

Why Static Defenses Don't Hold

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.

97.9%/93.4% AutoDAN-Turbo · Llama Guard 3 & SafeHarbor
39.9%/35.2% X-Teaming · Llama Guard 3 & SafeHarbor

This gap motivates a defense that updates from observed failures without retraining the agent.

Bar chart of attack success rate for AutoDAN-Turbo and X-Teaming against no defense, Llama Guard, and SafeHarbor.
Figure 2: Attack success rate of adaptive jailbreaks on HarmBench against an undefended agent and two static jailbreak defenses.

How SED Works

SED wraps a frozen agent with a policy memory that is read during an episode and updated only after the episode has been scored.

01

Retrieve select relevant policies

Rank stored policies for the task, select up to three across policy families, and include their covering parents.

02

Act run the frozen agent

Run the frozen agent with the retrieved policies appended to its system prompt.

03

Judge score the full trajectory

Score the full role-labeled trajectory; retain only harmful episodes and their supporting evidence.

04

Learn store and consolidate failures

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

Experimental Evaluation

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

SED leads six of eight security benchmarks, and the gains are not bought with refusals.

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.

Security benchmarks led 6/ 8 lowest ASR of any defense on WJB, HBdir, HBadv, RedCode, AgentDojo, AgentDyn
RedCode risky execution 95.6%→11.3% specialized defenses leave it at 49% or above
AgentDojo utility under attack 44.4%→87.9% the agent still finishes the task; clean utility unchanged at 89.7%
SWE-bench resolve rate 62.6%→68.8% highest of all evaluated defenses; next best DRIFT at 67.6%

Attack success rate lower is better

WildJailbreak
31.4 Undefended
17.6 SafeHarbor
2.1 SED
RedCode
95.6 Undefended
49.3 SafeHarbor
11.3 SED
AgentDojo
49.0 Undefended
3.7 DRIFT
0.42 SED
AgentDyn
33.0 Undefended
2.1 DRIFT
0.54 SED

Benign utility higher is better

AgentDojo under attack
44.4 Undefended
78.2 SafeHarbor
87.9 SED
SWE-bench resolve rate
62.6 Undefended
67.6 DRIFT
68.8 SED
AgentDyn under attack
49.1 Undefended
66.4 SafeHarbor
69.3 SED
Undefended Strongest baseline on that benchmark SED
Table 1: Attack success rate (%), lower is better. DeepSeek-V4-Flash across eight benchmarks. WJB = WildJailbreak, HB = HarmBench (direct and adversarial), RC = RedCode, AgH = AgentHarm, ADojo = AgentDojo, ADyn = AgentDyn.
DefenseWJBHBdirHBadvRCAgHFCVADojoADyn
Undefended31.4025.9425.5595.6042.6019.1749.0033.04
Llama Guard 329.312.818.1689.123.0020.4349.3229.11
SafeHarbor17.5515.009.6449.281.595.7111.9010.18
DRIFT23.9024.0616.6491.1231.061.483.692.14
GuardAgent35.6523.4418.1682.4018.346.1912.609.82
SED2.100.943.0711.306.202.910.420.54
Table 1b: Benign utility (%), higher is better. DeepSeek-V4-Flash. ADojo = AgentDojo, ADyn = AgentDyn; u = benign utility, ua = utility under attack, res = SWE-bench resolve rate.
DefenseAgHADojouADojouaADynuADynuaFCVres
Undefended67.3089.6944.3673.3349.1162.60
Llama Guard 357.5092.7842.3665.0045.3655.80
SafeHarbor41.8389.6978.1971.6766.4356.00
DRIFT76.7386.6076.0828.3328.2167.60
GuardAgent75.8573.2058.9053.3343.0438.80
SED63.1089.6987.8873.3369.2968.80

Prompt Injection on DTap

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.

Model Y-axis

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.

Figure 3: Security versus capability on DTap. Macro-average attack success (toggle indirect/direct) against benign task success across CRM, workflow, and code. Colored ring = model; corner chip = defense (same badges as the paper figure). Overlapping badges are nudged apart; thin lines mark true data positions. On DeepSeek-V4-Flash, SED lowers indirect attack success from 79–90% to 19–26%, a 60- to 65-point drop in every domain, while benign task success moves by less than 1.2 points.

DTap · 3 models · CRM, workflow, and code agents

Indirect injection success drops by 20 to 65 points in every domain, on every model, while benign task success stays essentially unchanged.

Headline number is indirect-injection ASR, undefended → SED. Direct-injection ASR and benign task success are shown underneath each chip.

DeepSeek-V4-Flashmost exposed undefended
CRM −65 pts
86.7→21.5%
direct 96.7 → 22.5 · benign 87.1 → 86.6
Workflow −60 pts
78.9→19.2%
direct 83.1 → 31.2 · benign 91.3 → 90.2
Code −64 pts
89.7→26.1%
direct 95.0 → 24.0 · benign 99.7 → 99.1
GLM-5.2
CRM −33 pts
41.3→8.3%
direct 32.2 → 12.2 · benign 72.1 → 75.8
Workflow −23 pts
32.4→9.6%
direct 47.3 → 17.3 · benign 92.3 → 91.8
Code −46 pts
49.7→3.7%
direct 57.9 → 2.5 · benign 97.9 → 97.9
Kimi K3
CRM −38 pts
41.3→3.3%
direct 42.2 → 7.8 · benign 88.5 → 88.2
Workflow −20 pts
25.8→5.9%
direct 26.3 → 10.4 · benign 89.2 → 88.2
Code −34 pts
36.6→2.3%
direct 51.3 → 4.4 · benign 99.6 → 99.6
Table 2: DTap prompt-injection results (%). ind and dir are indirect and direct injection ASR (lower is better); ben is benign utility (higher is better).
DefenseCRMWorkflowCode
ind ↓dir ↓ben ↑ind ↓dir ↓ben ↑ind ↓dir ↓ben ↑
DeepSeek-V4-Flash
Undefended86.6796.6787.1278.8583.1291.3489.7095.0499.70
Llama Guard 366.6767.4282.4254.8145.4592.1243.6441.6798.48
SafeHarbor58.6780.0039.3962.5067.5388.0683.6468.6091.21
DRIFT33.3383.3386.0657.6972.7392.8120.8690.9199.09
GuardAgent48.3288.8980.0066.3564.9490.7027.9592.5699.39
SED21.4822.4786.5919.2331.1790.1526.0623.9799.09
GLM-5.2
Undefended41.3332.2272.1232.3847.3092.3349.7057.8597.88
Llama Guard 318.6717.7875.158.7432.0093.9447.5651.6798.78
SafeHarbor12.0013.3358.1826.0028.0092.6019.3928.1098.78
DRIFT10.6720.0075.7621.2037.3093.2014.5543.8098.78
GuardAgent36.0032.2273.3330.5050.7090.5036.6553.7298.18
SED8.2612.2075.789.6217.3391.783.662.5097.87
Kimi K3
Undefended41.3342.2288.4825.8126.3289.2236.5951.2899.62
Llama Guard 321.3334.4488.488.0816.8893.6733.9443.48100.00
SafeHarbor15.3317.7870.304.3011.6991.649.7630.2598.18
DRIFT16.6730.0087.8821.4330.6793.419.0940.6899.62
GuardAgent25.3341.1181.8219.3528.5787.5818.1846.90100.00
SED3.337.7888.185.8810.3988.182.284.3999.63

Holding Up Under Adaptive Attack

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.

Table 3: Attack success rate (%) under adaptive attack, lower is better. NoDef = undefended, LG = Llama Guard 3, SH = SafeHarbor, DR = DRIFT, GA = GuardAgent.
AttackNoDefLGSHDRGASED
DeepSeek-V4-Flash
AutoDAN-Turbo98.0097.9293.4479.7087.8017.82
X-Teaming50.0039.9035.2150.7347.407.81
GLM-5.2
AutoDAN-Turbo30.3129.2523.1227.8138.447.10
X-Teaming15.6214.9010.1013.1215.948.50
Kimi K3
AutoDAN-Turbo19.3816.5612.1919.0619.1810.43
X-Teaming28.1315.5813.9020.7620.9210.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.

Heatmap of attack iterations to jailbreak for each defense, one column per behavior and one row per attack iteration.
Figure 4: Attack iterations to jailbreak. AutoDAN-Turbo against DeepSeek-V4-Flash, one panel per defense. Each column is one of 100 behaviors in attacker order; each row is an attack iteration. Color is the judge score, light green (safe) to dark red (jailbroken); white marks iterations after the attack has already succeeded and stopped.

Where Does the Robustness Come From?

We test whether the gains come from extra prompt text or from the judge alone.

Table 4: Memory ablation on DeepSeek-V4-Flash. Attack success rate (%), lower is better. Each row adds one component to the undefended agent.
VariantAutoDAN-TurboX-TeamingRedCode
No memory (undefended)98.0050.0095.60
+ episodic recall42.2719.6925.60
+ policy synthesis28.1214.0013.70
+ consolidation (full SED)17.827.8111.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.

Table 5: Benign utility under policy transfer (%), higher is better. A frozen policy library learned on harmful episodes is applied read-only to a disjoint benign split.
Benign benchmarkNo memoryAttack-derived policies
WildJailbreak benign97.6096.00
AgentHarm benign66.9064.68
Cumulative attack success over an X-Teaming stream, comparing the undefended agent, SED frozen after 100 behaviors, and SED evolving continuously.
Figure 5: Frozen versus evolving policy memory. Cumulative X-Teaming attack success against a GLM-5.2 agent on HarmBench.

BibTeX

@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/},
}