Manuscript Offprint

arXiv:2610.24896

Peer Pressure: Execution-Verified Co-Evolution of Attacker and Defender Populations for Code Security

Khushbu Pahwa, Yubin Ge, Daniele Bonadiman, Xiaofei Ma, Yi Zhang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Khushbu Pahwa, Yubin Ge, Daniele Bonadiman, Xiaofei Ma, Yi Zhang

AWS AI

{pahwakhu, yubinge, dbonadim, xiaofeim, yizhngn}@amazon.com

Figure

Figure 1: PRPO at a glance. Red writes patches that complete a development task while hiding a weakness of a known class; each is executed in an isolated sandbox and reviewed by Blue. Red is paid only when a real exploit fires and Blue misses or, at repository level, mislocates it, and the exploit's path supplies the localization label. (1) One return per peer, the opposing population frozen as a committee. (2) Each peer is credited against its peers on the identical condition, cancelling difficulty and opponent, where a batch-mean baseline mixes conditions. (3) Every 50 rounds the lowest-fitness adapter is evicted and reseeded by mutation or rank-preserving crossover (§3).

Abstract

LLM code agents increasingly ship code with little oversight, yet defenders trained on static vulnerability datasets fall behind adapting adversaries. We co-train attacker and defender instead, and let execution decide every reward: an attacker (Red) edits a real repository and earns nothing unless its patch applies, builds, passes the tests, completes its development task and reproduces a real exploit in an isolated container, whose path also labels the entry point, the critical operation and the trace between them.

Peer-Relative Policy Optimization (PRPO) makes both sides populations of LoRA adapters over one frozen base and credits each against same-role peers that faced an identical condition, placing the population inside the policy-gradient baseline rather than the opponent pool, with a tournament preserving diversity. Matching cancels the condition's difficulty: at equal coverage it is worth 2.3 points of balanced accuracy over a baseline computed on other conditions, and it matches a within-policy control at half the verifier spend.

PRPO's 7B diff reviewer reaches 64.8% balanced accuracy on four unseen applications in three untrained languages, 5.5 points above supervised security fine-tuning and 4.4 above a frozen frontier reviewer (Claude Opus 4.8), which it leads by 15.8 on the application it trains on. Its 9B repository agent recovers 23 of 172 held-out VulnGym advisories, against 10 after supervised fine-tuning and 7 for the same backbone untrained under the same scaffold, and locates 17 of 43 reachable entry points against 13 for mini-swe-agent with GLM-5.2. Run unchanged on jailbreak defense, the same algorithm matches or exceeds WildGuard's static F1F_{1} at equal corpus and model size. Under a judge distinct from its training oracle it cuts attack success from 36.0% to 4.6%, against WildGuard's 8.9%.

1 Introduction

LLMs now write a growing share of production code and increasingly review it. The defenses are themselves LLMs: vulnerability detectors and the guard classifiers that refuse unsafe requests are fitted to static corpora (Ding et al., 2024; Weyssow et al., 2025; Han et al., 2024) and stop improving once they have absorbed that snapshot, while the attack distribution keeps moving. When writer and reviewer come from the same model family their errors also correlate, so the weaknesses a writer introduces are those its reviewer is least able to catch.

We therefore train concealment and detection against each other in a setting where correctness is executable. Known weakness classes are instrumented into containerized copies of real applications, and a site is admitted only when an existing exploit harness fires on it. The pipeline thus yields labelled ground truth about where a catalogued class is reachable rather than new vulnerabilities, in the manner of mutation testing and fuzzer benchmarks. Red writes a patch that conceals a weakness while remaining functional, and Blue reviews it as an LLM code reviewer would: it must not only flag the patch but also point to where the weakness is entered and where it takes effect, the form of output a developer can act on. Two problems make this game unstable. A single Red–Blue pair collapses onto one strategy, after which learning stalls on both sides; and Blue’s training reward keeps rising when Red stops improving, so it cannot distinguish genuine progress from a stalled opponent.

Peer-Relative Policy Optimization (PRPO) addresses both. It maintains a population of same-role LoRA adapters over one frozen base, with a tournament that retires the weakest adapter and reseeds it from strong ones to prevent strategic collapse. Credit is peer-relative: each policy is scored against peers that faced the identical condition, so the peers maintained for diversity also supply the baseline at no extra generation cost. Progress is measured not by the training reward but against a held-out external attacker and historical opponents, neither of which improves when Red stalls.

Five questions follow. Is an LLM attacker reliable enough to train against (RQ1)? Does co-evolution beat static training, and does it need an adapting opponent (RQ2)? Does the detector transfer to unseen applications and languages (RQ3)? Are weight updates necessary (RQ4)? Does a population help at a fixed verifier budget (RQ5)?

Our contributions are threefold. (1) An execution-verified trainer for code security, in which every reward term is decided by building and running code. Because each exploit enters through a reachable handler, the verifier also returns the entry point, critical operation and trace, providing localization supervision at no extra cost. (2) The matched-population advantage (MPA), which places the population in the policy-gradient baseline rather than in the opponent pool, the reward or a learned critic. We derive its advantage variance in closed form, a statement about Var⁡(Ai)\operatorname{Var}(A_i) and not about gradient variance or convergence, and separate its estimator effect from its allocation effect at a fixed verifier budget ( §3.3\S3.3). (3) To our knowledge, the first population-based co-evolutionary trainer for adaptive security, and the first to place the population inside the policy-gradient baseline rather than in the opponent pool, the reward or a learned critic, evaluated with a security-grounded criterion rather than the training reward in two verifiable domains: code security, against supervised, within-policy, frontier-model and published-agent baselines on VulnGym (Ji et al., 2026), and jailbreak safety.

References (27)