Manuscript Offprint

arXiv:2610.25916

Secure Agentic Coding through Counterexample-Grounded Feedback

Tue Le, Anh Nguyen Hoang, Gabriel Sasseville, Doseok Jang, Pierre-Luc Bacon, Nghi D. Q. Bui

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

Abstract

As coding models and agent harnesses become more capable, reliable security verification is becoming a central bottleneck. Improving secure code generation requires a signal whose reported progress remains aligned with actual program behavior under optimization; otherwise, an optimizer can improve the signal's verdict without removing the underlying vulnerability. Existing model-based approaches require models to either infer program behavior from source code or specify correct outcomes for adversarial tests, placing substantial reasoning demands on the security signal. We introduce FALCON, a counterexample-grounded verification framework that separates attack exploration from behavioral verification and connects them through execution traces of the program under test. In test-time repair, FALCON yields substantially stronger held-out functional-security gains than alternative security signals across secure code generation benchmarks, while preserving or improving functionality. As an RL reward, FALCON also outperforms static-analysis and learned rewards on held-out functional-security, even when all policies successfully optimize their respective training rewards. Combining FALCON with either proxy reward further improves held-out performance, suggesting that execution-grounded feedback can mitigate reward overoptimization while preserving useful guidance from existing security signals.

Code: https://github.com/FSoft-AI4Code/FALCON.

Project: https://falcon-secure.github.io/

1 Introduction

Coding agents now edit real repositories, navigating projects and running commands to validate their work [11, 22, 62], yet patches that pass functional tests can still contain security vulnerabilities [7, 43, 65]. Reliable security feedback is therefore essential both for evaluating generated code and for improving it through test-time repair [8, 35, 52] or reinforcement learning [19, 34, 53, 60, 63].

†^{\dagger}Work done while at FPT.

In both settings, improving the feedback signal must translate into safer program behavior; otherwise, optimization may reward edits that satisfy the signal without removing vulnerabilities. Providing such feedback requires both inputs that expose unsafe behavior and reliable criteria for judging the resulting executions, which are often unavailable for generated code.

Existing automated security signals rely on different forms of evidence. Static analyzers apply predefined rules and program abstractions [4, 15, 44, 48, 53, 63], but may miss vulnerabilities beyond the behaviors their analyses capture [3, 55]. Learned detectors and source-code LLM judges infer vulnerabilities without observing executions [12, 54, 64, 66]. Attacker-generated tests execute the program, but model-generated oracles can capture actual rather than intended behavior [25]. As Figure 1(a) illustrates, these model-based approaches place substantial reasoning demands on the model: a source-code judge must infer behavior and assess its security implications, while a test generator must both discover adversarial inputs and specify correct outcomes. Errors in these judgments can allow a candidate to satisfy the feedback signal while retaining unsafe behavior. This motivates a narrower judgment task grounded in observed execution.

We introduce FALCON, a verification framework designed to reduce the reasoning demand of security judgment through two narrower processes: exploration and verification (Figure 1(b)). Given a candidate program, the attacker generates deterministic Proof-of-Concept probes: executable scripts that invoke the target with adversarial inputs or a crafted environment, without specifying expected outputs or verdicts. The verifier judges their execution traces against security requirements, separating attack discovery from judgment of observed behavior. However, the attacker may generate probes that manipulate the execution by replacing the target function or directly performing the sensitive operation they are supposed to test. Such probes can create an apparent violation even when the code under test is secure. FALCON therefore applies faithfulness checks to reject these probes and require evidence that the target code produced the reported behavior.

(a) Prior approaches: high reasoning demands

Figure

(b) FALCON: reduced reasoning demands

Figure

Separate exploration from verification through execution evidence.

Figure 1 Comparison with prior security assessment approaches. (a) Source-code judges must infer program behavior and assess security, while test generators must propose inputs and define correct expected outcomes. Both place substantial reasoning demands on the model. (b) FALCON reduces the reasoning demand of security judgment by separating attack exploration from verification and connecting them through an execution process that produces concrete traces for the verifier.

We evaluate whether FALCON provides reliable feedback under optimization. In a repair loop on CWEval [43], four security signals guide the same coding model with ground-truth tests hidden. All report progress, but their held-out outcomes differ: FALCON improves FUNC-SEC@1 by 25.2 points, while LLM-as-a-judge and attacker-only feedback yield almost no improvement or a decline, and CodeQL [15] yields smaller gains. Thus, satisfying a security signal does not necessarily improve independently evaluated security. Further experiments show gains across coding models on CWEval and SecCodeBench-V2 [7], and across three coding-agent harnesses on SusVibes [65], with functionality largely preserved or improved. As an RL reward, FALCON outperforms REAL [63] and SecCodePRM [64] on held-out FUNC-SEC@1 at both model scales. Interestingly, combining FALCON with either reward further improves held-out performance over either component alone, suggesting that execution-grounded feedback can mitigate reward overoptimization while retaining useful guidance from the original proxy rewards.

Our main contributions are:

• We show that reported security progress can diverge from held-out functional-security under both iterative test-time repair and reinforcement learning, motivating evaluation of security signals under optimization.

• We introduce FALCON, a verification framework designed to reduce reasoning demands by separating attack generation from behavioral judgment and grounding verification in replayable execution evidence attributable to the code under test.

• We demonstrate that FALCON improves secure code generation across benchmarks, coding models, and agent harnesses. As an RL reward, it improves held-out performance both independently and in combination with static-analysis or learned rewards.

References (59)