When AI Agents Attack and Defend Each Other: Rethinking AI Security Evaluation
As AI agents become capable of reading code, running tests, analyzing logs, and modifying programs, the way we evaluate security capabilities must evolve. This article explains why static capture-the-flag benchmarks are no longer sufficient, how dual-agent adversarial evaluation introduces dynamic, stateful attack-and-defense scenarios, and what a fair evaluation framework requires: comparable environments, minimized permissions, unified resource budgets, multi-dimensional scoring covering attack effectiveness, patch quality, reliability, and boundary compliance, plus sandbox isolation and a phased path for enterprises to turn evaluation results into production-ready engineering capabilities.
1. What Really Needs Measuring Goes Beyond “Can It Find Vulnerabilities”
As AI systems become able to read code, execute tests, analyze runtime logs, and modify programs, the target of security evaluation is shifting. In the past, evaluation mainly examined whether a model could answer security questions. Today, the more important question is whether an agent can complete tasks continuously within a constrained environment and remain reliable when conditions change.
Here, an agent refers to a system that works toward a goal by calling tools, observing feedback, adjusting plans, and executing actions. Its performance depends not only on model reasoning, but also on tool permissions, context management, the execution environment, and resource limits.
If a system performs well in a fixed target range, can we conclude that it has real-world offensive and defensive capability? The answer is no—not directly.
Fixed challenges typically test a relatively clear chain: understand the task, identify the flaw, construct a verification method, and capture the success marker. Real security work, however, also involves adversary behavior changes, services that must keep running, verification of patch quality, and trade-offs between time and resources.
Evaluation therefore needs to expand from “did a single operation succeed” to “how does the system make decisions under continuous change.”
2. The Value and Limits of Static Target Ranges
Traditional capture-the-flag (CTF) style evaluation places vulnerabilities in a pre-built environment and requires the evaluated system to capture a designated flag to prove the target was breached. This approach has clear advantages:
- Clear task boundaries and easily verifiable success conditions;
- Reproducible environments that support repeated experiments;
- Identical challenges for all evaluated systems;
- Easier attribution of individual capabilities, such as code auditing, input analysis, or permission logic.
These strengths mean static evaluation remains worthwhile. The issue is not that it is ineffective, but that its coverage is limited.
2.1 Targets usually don’t change on their own
If the service logic, access conditions, and flaw locations remain fixed, the agent mainly faces technical difficulty rather than adversarial strategy. Once a defender patches an issue, adjusts validation logic, or changes accessible paths, an attacker must reassess whether previous conclusions still hold. Fixed ranges rarely allow this adaptive capability to be observed.
2.2 Success paths can be replaced by memorization
Public, repeatedly used challenges may enter a model’s knowledge through training data, public discussion, or past experiments. In that case, a correct result may come less from live analysis and more from recognizing a known solution. A high score alone cannot prove data contamination, but private tasks, structural variants, and regenerated targets can reduce this risk.
2.3 Defensive quality is hard to assess fully
Finding a vulnerability and fixing it are different capabilities. A proper fix must answer:
- Does it address the root cause of the defect?
- Does it preserve normal business functionality?
- Does it introduce new security issues?
- Can it withstand variations of similar inputs?
Checking only whether the attack succeeded cannot answer these questions.
3. Dual-Agent Adversarial Evaluation: Putting the Target in a Dynamic Environment
A more complete approach is to have two agents each maintain an independent service instance with identical initial conditions. Each side is responsible for protecting its own service while attempting to breach the opponent’s within an explicitly authorized scope.
This mechanism does more than raise attack difficulty—it introduces continuous feedback: one side’s actions change the conditions the other side faces next.
A general evaluation workflow can include the following stages:
- Initialize two equivalent service instances, each with its own protected target.
- Provide both sides with task descriptions, permission boundaries, and available resources.
- Allow analysis, verification, and patching within a limited time window.
- Have an independent judge review attack evidence, service status, and rule compliance.
- Update targets for the next round, preserving patches where the rules allow.
- Aggregate multi-round trajectories rather than only counting final wins and losses.
Round count and duration should be determined by task scale, service complexity, and resource budget. No particular time configuration should be treated as a universal standard.
Why target rotation and patch persistence matter
If each round uses a new success flag or authorized target, agents must produce fresh valid evidence rather than resubmitting old results. However, a target update does not automatically mean the vulnerability path has changed—“evidence invalidation” and “attack method invalidation” must be clearly distinguished.
If patches persist across rounds, evaluation can observe continuous hardening: whether previously exposed flaws were resolved, whether later modifications caused regressions, and whether the agent can maintain a gradually changing system.
Combining both mechanisms brings evaluation closer to a stateful attack-and-defense process.
4. Fair Adversarial Evaluation Starts with Environment Design
Dynamic adversarial evaluation is closer to real work, but it also introduces more confounding variables. With sloppy environment design, final rankings may reflect resource differences or rule loopholes rather than security capability.
4.1 Initial services must be comparable
Both sides should receive the same service version, configuration baseline, task description, and initial permissions. Writable directories, restart privileges, and network access should be identical. Random data may differ, but difficulty distribution should be as close as possible—one side’s target should not be naturally easier to reach while the other must satisfy complex extra conditions.
4.2 Permissions should be minimized per task
Agents should only access authorized target instances and the necessary tooling environment. Evaluation should not allow access to unrelated public network systems, and should never permit probing the host machine, judge services, or other participants’ control channels. Attack targets and evaluation infrastructure must be separated, or “breaching the judge” could be miscounted as “breaching the service.”
4.3 Resource budgets must be recorded uniformly
Time limits are only one dimension. Compute resources, tool call counts, concurrent task numbers, and context budgets should also be controlled or logged. If one side has more execution opportunities, its advantage may come from search scale rather than better reasoning. The sounder approach is to compare performance under a unified budget while reporting resource consumption separately.
4.4 Service availability must be a hard constraint
Defenders must not gain a security advantage by shutting down all interfaces, deleting core functionality, or rejecting all requests. Evaluation should continuously run normal business tests. Only when functionality and availability meet predefined requirements can a patch be considered valid. The goal of security defense is to reduce risk, not to eliminate the service itself.
5. Scoring Should Cover Attack, Repair, and Reliability
Using win/loss as the only metric masks the capability structure of different systems. One system may attack effectively but fail at patching; another may defend reliably but consume excessive resources. At minimum, report the following dimensions separately.
Attack effectiveness
Attack success must be confirmed by an independent mechanism, not by agent self-reporting. Valid evidence must show the authorized target of the current round was achieved, ruling out stale flags, log leakage, or accidental judge-channel exposure. Beyond success counts, record time to first valid breach, coverage across different targets, and whether the agent can re-accomplish the task after the opponent patches.
Patch correctness
A fix must pass at least three checks:
- The previously working security exploit no longer succeeds;
- Normal business flows remain usable;
- Input variants related to the defect are handled sensibly.
The first check only proves one path was blocked—it does not prove the root cause is gone. Defensive evaluation should avoid rewarding temporary blocks that only target a single sample.
Operational reliability
Record service anomalies, failed modifications, restart counts, recovery time, and sustained availability. A system that relies on frequent restarts or leaves incomplete patches is hard to use in a continuously running business environment, even if it occasionally stops an attack.
Boundary compliance
Unauthorized access, attempts to obtain host credentials, or probing non-authorized addresses should be handled as separate violation events, not dressed up as extra attack capability. For a security agent, “capable” and “controllable” are both indispensable.
You can use multi-metric reporting or compute a composite score with explicit weights. But weights must serve the evaluation goal: enterprise defense scenarios typically value availability and patch quality more, while research-oriented experiments may focus on adaptability. No single weighting fits every scenario.
6. Attack Trajectories and Patch History Are More Valuable Than a Single Score
A key output of dynamic evaluation is the complete decision and execution trajectory. Record when the agent formed a hypothesis, which authorized tests it ran, what feedback it observed, why it modified code, and how it verified the result.
These records distinguish several superficially similar outcomes:
- Locating a flaw quickly through accurate analysis;
- Hitting the target by chance after massive trial and error;
- Misunderstanding the problem but happening to submit a valid result;
- Patching the current sample while leaving the same root cause in place;
- Proactively stopping when a risk of crossing boundaries appeared.
Timing relationships also matter. If an attack occurred before a patch was deployed and the result reached the judge after deployment, the patch cannot simply be declared ineffective. Deployment time, request arrival time, and evidence verification time all need to be recorded.
This is also why dynamic evaluation is harder to reproduce than static challenges: outcomes depend not only on program state but also on event ordering.
7. Sandbox Isolation Is a Prerequisite, Not an Add-On
An agent that can modify programs and run security tests should always be treated as an execution subject requiring strict constraints. Security boundaries cannot exist only in prompts—they must be enforced by the runtime environment.
Network isolation
Open only the necessary target communication paths, and deny access to external networks and unrelated internal services by default. Network rules must be maintained by an independent control layer that participating agents cannot modify.
Credential isolation
The runtime environment should contain no real business keys, production access tokens, or host credentials. Evaluation data should be synthetic or anonymized, and task credentials should be short-lived, narrowly scoped, and revocable.
Process and file isolation
Restrict high-privilege operations, host directory access, and shared file writes. The two sides’ workspaces, log directories, and judge storage should be managed separately to avoid unintended information leakage through shared resources.
Resource limits and emergency termination
Set caps on memory, storage, process count, and execution time, and provide externally controlled pause, termination, and environment reclamation. When a violation is detected, stop execution first, then preserve necessary evidence and assess the impact—do not let the task keep running in pursuit of a higher completion rate.
8. How Enterprises Can Turn Evaluation into Engineering Capability
Enterprises should not interpret a high adversarial win rate as “ready for production.” A safer adoption path expands permissions and task complexity step by step.
Step 1: Establish an offline capability baseline
Use static tasks first to confirm foundational capabilities such as code comprehension, vulnerability localization, patch suggestions, and test generation, with human review retained.
Step 2: Move into an isolated dynamic range
Select services that resemble your business’s technical structure but contain no production data, and introduce multi-round target changes, patch persistence, and functional regression checks.
Step 3: Observe stability across repeated runs
The same system may vary significantly under different random conditions and against different opponents. Run repeated experiments and report result distributions, failure types, and resource consumption—never let a single win represent overall capability.
Step 4: Integrate into a controlled development workflow
Initially, let the agent submit candidate patches, test descriptions, and risk analyses, with humans deciding whether to merge. As evidence accumulates, gradually authorize revocable, low-risk operations with clearly bounded impact.
Step 5: Continuously monitor capability drift
When models, tool environments, or service structures change, earlier conclusions may no longer hold. Run regression evaluations regularly and watch for signals such as tool failure rates, patch regressions, and permission violations.
For cloud deployments, general capabilities such as compute resources, isolated networks, object storage, logging services, and monitoring alerts can support experiments—but security configuration responsibilities must be explicit. Infrastructure availability must never be equated with safe agent execution.
9. Conclusion: Dynamic Adversarial Evaluation Supplements Rather Than Replaces Static Evaluation
AI security capability cannot be summarized as “how many vulnerabilities it found.” The fuller question is: can it keep making sound judgments while an adversary continuously adapts, patch effectively, maintain service availability, and always stay within authorized boundaries?
Static evaluation measures foundational capabilities. Dynamic adversarial evaluation observes adaptability and continuous decision-making. Business workflow validation determines engineering readiness. The three should form a progression, not replace one another.
Only by placing attack evidence, patch quality, operational reliability, and behavioral constraints within a single evaluation framework can we truly distinguish a system that can solve a security challenge from an agent that can reliably perform security work in a changing environment.
