TL;DR
This paper introduces Defense-as-Skill, a novel security paradigm that implements runtime safety guardrails for AI agents as installable, inspectable, and editable skills. By deploying their guard—SkillSonar—alongside untrusted third-party skills and optimizing it via Monte-Carlo Tree Search (MCTS), the authors significantly reduce attack success rates while maintaining high task utility across multiple LLM architectures.
What Problem Does This Paper Address?
Modern AI systems are transitioning from simple tool-use loops to Skill-Augmented Agents (SAAs) (like Claude Code and OpenClaw) that load reusable packages of instructions, scripts, and workflows. While these "skills" drastically improve capability, they also introduce a massive supply-chain risk: a compromised or malicious skill can act as a persistent, dormant threat.
Traditional static package scanning or pre-installation vetting falls short here. A malicious skill doesn't need to misbehave at install time; it can wait until a specific user task and workspace state make an unsafe action (like exfiltrating an API key or bypassing an approval gate) look completely benign or necessary. Existing runtime defenses typically rely on external classifiers or platform-specific permission gates, which are difficult to inspect, edit, or port across different agent runtimes.
Methods
The authors propose Defense-as-Skill, treating the runtime guard itself as a native skill artifact. Their implementation, SkillSonar, is installed exactly like any other skill but is given an explicit instruction assigning it a persistent safety responsibility.
During execution, SkillSonar intercepts proposed actions (tool calls, shell commands, file modifications) and triages them into four risk levels (R0 to R3), mapping them to one of three outcomes: allow, narrow/replan, or require user confirmation.
To prevent the guard from being too restrictive or missing adaptive attacks, the authors introduce runtime guard-skill evolution. This framework uses Monte-Carlo Tree Search (MCTS) to optimize the guard skill directly on disk. The algorithm iteratively:
- Evaluates a candidate guard skill in concrete agent rollouts.
- Collects multi-dimensional feedback (attack success, task utility, token cost, and confirmation friction).
- Uses an LLM-based refiner to make localized text edits to the guard skill's instructions based on execution failures.
Datasets
To rigorously evaluate this setup, the authors constructed SCOPE-R, a task-conditioned safety dataset spanning 6 major risk families (Specification Integrity, Capability Control, Operational Side Effects, Privacy & Data Flow, Execution Safety, and Resource & Reliability) across 21 sub-categories.
SCOPE-R contains:
- 206 attack-confirmed malicious instances: Created via an automated adversarial loop where an attacker agent rewrites benign skills until they successfully execute a target exploit against a victim agent.
- 43 benign tasks: Sourced from PinchBench to ensure defenses do not break legitimate agent functionality.
The authors also validated SkillSonar's robustness on two independent external benchmarks: SkillSafetyBench and WildClawBench.
Key Insights and Ideas
- Safety Requires Explicit Responsibility Assignment: Unlike capability-focused skills, safety guards cannot rely on standard semantic matching. Because a user's prompt rarely explicitly mentions safety, an agent will simply overlook a safety skill unless it is explicitly instructed to consult it before taking action.
- Modular Skill Representations Beat Flat Prompts: In an illuminating ablation study, the authors compared SkillSonar against a "flattened" system prompt containing the exact same safety instructions. SkillSonar achieved lower attack success, higher task utility, and a 21% reduction in token costs, proving that modular, skill-native architectures are inherently more context-efficient for LLMs.
- Strong Zero-Shot Cross-Model Transfer: A guard skill optimized entirely on a single model backbone (e.g., GLM-5) transfers robustly to completely different open and closed models (like GPT-5.4 and Claude Haiku) without needing any model-specific retraining or labeled attack data.
Key Results
Evaluated on repeated runs with the GLM-5 model, SkillSonar achieved exceptional safety gains while preserving the agent's operational utility:
- In-Distribution (ID) Safety: Reduced the Attack Success Rate (ASR) from 0.482 (no guard) to 0.104.
- Out-of-Distribution (OOD) Safety: Reduced OOD ASR from 0.606 to 0.115, demonstrating strong generalization to entirely unseen risk families.
- The Safety-Utility Trade-off: While strict platform permission gating (like Claude Code's
AcceptEdits) can also suppress attacks, it severely degrades task utility. SkillSonar maintains a much higher utility profile (0.779 vs 0.650 on ID tasks) by intelligently replanning or narrowing actions instead of flatly denying them.
Limitations and Future Work
Despite its strong performance, SkillSonar relies on soft instruction-following (Markdown policies). A highly sophisticated or adversarial skill might still find ways to override or ignore the guard instructions during execution. Additionally, the optimization process relies heavily on the accuracy of an LLM-based runtime judge to evaluate rollouts, meaning judge errors could skew the evolution path.
The authors emphasize that Defense-as-Skill should not replace hard, mechanism-level security controls (like OS sandboxing, taint tracking, or strict permission gates) but should instead serve as an inspectable, adaptable policy layer on top of them.
Summary updated