EvoSafeHarness: Evolving Model- and Domain-Specific Harnesses for Securing Agents

Nanxi Li, Yingzi Ma, Yulong Cao, Edward Suh, Bo Li, Dawn Song, Chaowei XiaoarXiv 2026

TL;DR

One-size-fits-all safety defenses often fail for LLM agents, either by over-blocking capable models or failing to protect weaker ones across different applications. This paper introduces EvoSafeHarness, an optimization framework that automatically evolves custom safety harnesses—combining natural language policies and executable code—tailored to specific models and domains. By optimizing for the exact deployment context, it drastically reduces attack success rates while preserving agent utility.

What Problem Does This Paper Address?

As Large Language Model (LLM) agents gain autonomous access to files, financial accounts, and APIs, securing them becomes an operational necessity. Agents face two primary attack vectors: direct attacks (malicious user requests) and indirect prompt injections (malicious instructions embedded in external data like emails or web pages).

While system-level "safety harnesses" can intercept these threats outside the model itself, existing solutions are static and expert-designed. This creates a major dilemma: a strict, rigid harness might completely tank the utility of a highly aligned model by over-blocking benign actions, while a general harness might leave a weaker model completely vulnerable. Furthermore, safety is highly domain-dependent; an OS-filesystem agent needs to monitor shell commands and file paths, whereas a finance agent must track multi-step transaction histories to prevent complex scams. This paper tackles the challenge of automatically engineering specialized, deployment-dependent defenses.

Methods

EvoSafeHarness treats harness design as an open-ended optimization problem, automatically synthesizing a custom defense consisting of a natural-language policy ($P$) and executable code logic ($C$).

The framework operates in a closed optimization loop driven by four core components:

  • Designer: An agentic LLM that drafts and iteratively refines the harness code and prompts based on feedback.
  • Criticizer: A fresh-context adversarial LLM that stress-tests candidate harnesses. It ensures the rules don't just overfit to specific benchmark tokens (like exact filenames) but instead enforce robust, generalized security invariants.
  • Cascade Test Environment: A multi-stage evaluation pipeline (Static $\rightarrow$ Smoke $\rightarrow$ Confidence Gate $\rightarrow$ Full Search) that prunes weak candidates early, saving significant compute.
  • Analyzer: Examines failed execution traces and distills them into actionable feedback to guide the Designer's next iteration.

To prevent the system from starting completely from scratch, the search is warm-started with distilled insights from existing expert defenses.

The closed-loop optimization framework of EvoSafeHarness.

Datasets

The authors evaluated EvoSafeHarness across four distinct agent benchmark families:

  • DecodingTrust-Agent (DTAP): A multi-domain benchmark (OS-filesystem, finance, telecom) featuring both direct and indirect attacks.
  • Agent-SafetyBench: Focuses on broader safety-critical tasks, including unsafe user requests and misinformation.
  • AgentDojo & AgentDyn: Used to test zero-shot transfer. Harnesses are evolved on AgentDojo (banking, Slack, travel, workspace) and tested completely unchanged on AgentDyn (shopping, GitHub, daily life).
  • AgentCanary: Used to evaluate robustness against adaptive, PAIR-style prompt rewriting attacks.

Key Insights and Ideas

  • Model-Specific Enforcement: Different models fail in different ways. Highly aligned models (like Claude Sonnet 4.6) only need lightweight semantic checks, whereas weaker models (like GLM-5) require deep, layered deterministic filters and data-flow tracking.
  • Domain-Specific Semantics: Security invariants cannot be generalized across domains. OS security revolves around commands and paths, while financial security requires stateful ledgers to catch malicious multi-step behaviors like wash trading.
  • Action-Boundary Authorization: Instead of trying to solve the open-world problem of detecting malicious text, the evolved harnesses often discover a closed-world solution: verifying at the action boundary whether the proposed tool effect matches the trusted user request.
EvoSafeHarness customizes defenses based on model behaviors and domain semantics.

Key Results

  • Frontier Dominance: EvoSafeHarness consistently outperforms fixed expert defenses (CaMeL, DRIFT, Progent) on the safety-utility trade-off across all benchmarks.
Figure 1. EvoSafeHarness dominates the utility–security trade-off on all four benchmarks. Each panel plots utility against safe rate (100 −ASR), so higher is better on both axes and the ideal defense sits in the top-right corner. Large markers show cross-model method averages and small dots show individual evaluation cells (model×domain cells on DecodingTrust-Agent, victim models elsewhere). The Agent-SafetyBench panel reports utility under attack; the AgentDojo panel reports held-out test results and the AgentDyn panel zero-shot transfer of the AgentDojo harness.
  • DTAP Grid: Evolved harnesses cut the average attack success rate (ASR) from 45.6% to 10.0% while incurring only a minor 3.3-point utility cost.
  • Zero-Shot Transfer: On AgentDojo, it achieved 82.8% utility at 0.0% ASR (double the utility of CaMeL). When transferred zero-shot to the unseen AgentDyn suites, it maintained 75.0% utility and 0.0% ASR, proving it doesn't just overfit to benchmark artifacts.
  • Adaptive Robustness: Against adaptive PAIR attacks, the frozen harness kept the mean ASR below 20%, showing resilience even when an attacker actively optimizes against it.
  • Compute Efficiency: The nested cascade evaluation strategy successfully eliminated 43.6% of evaluation tokens during the search process.

Limitations and Future Work

  • Semantic-Only Harms: The framework struggles with risks that lack an observable runtime safety violation, such as client-targeted scams or fabricated claims. If an action is perfectly in-scope (e.g., emailing a recipient), the harness cannot easily verify the truthfulness of the content without risking high false-positive rates.
  • Interface Gaps: The current hook architecture (system-prompt, pre-tool, post-tool) means the executable code never sees the final tool-free text answer generated by the agent. The authors suggest adding an evidence-aware egress and pre-response integrity hook in future iterations to close this gap.

Summary updated

BibTeX
@misc{li2026evosafeharness,
  author = {Nanxi Li and Yingzi Ma and Yulong Cao and Edward Suh and Bo Li and Dawn Song and Chaowei Xiao},
  title = {{EvoSafeHarness: Evolving Model- and Domain-Specific Harnesses for Securing Agents}},
  year = {2026},
  eprint = {2609.05903},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2609.05903},
}
Figure