A New Reinforcement Learning Paradigm for Frontier Coding and Cybersecurity Agents

    This article explains why long-horizon AI agents become overly conservative under outcome-only reinforcement learning, and how adaptive optimization with counterfactual branch valuation addresses the problem. It covers the failure of credit assignment in long trajectories, the use of verifiable environment feedback instead of subjective scoring, the role of large-scale sandbox infrastructure, reward and data design, evaluation across correctness, stability, security, and cost, and common pitfalls. Readers will gain a practical understanding of how verifiable environments and local credit assignment can improve agent training.

    1. Background: Why Long-Horizon Agents Get More Conservative Over Time

    In software engineering and cybersecurity tasks, a complete assignment often spans dozens of interaction turns: reading the repository structure, retrieving relevant files, reproducing a defect, locating the root cause, modifying code, running tests, and iterating based on errors. These tasks share three key traits: long chains, sparse feedback, and strict end-state judgment.

    A representative scenario from the source material illustrates the issue. Over roughly 30 to 80 interaction turns, a model’s exploration, localization, and architectural understanding in the first 78 steps are nearly perfect. At step 79, it misspells a variable name; at step 80, the unit test fails, and the environment returns a reward of 0. With policy optimization methods that rely only on the final trajectory return, such as common policy gradient algorithms, the gradient penalizes every token from step 1 to step 80 indiscriminately. This resembles the “a loss invalidates the whole game” judgment in Go review: even a brilliant move in the middle cannot be recognized in the final signal.

    This leads to three cascading problems:

    • Broken credit assignment: The method cannot distinguish a critical correct decision from an end-stage slip.
    • Conservative behavior: The model favors low-risk, low-exploration actions and avoids necessary refactoring and trial and error.
    • Higher token cost: To avoid end-state failure, the model repeatedly confirms and redundantly reads files, consuming context and compute.

    2. Why Step-by-Step Scoring Is Not a Free Lunch

    A natural idea is to abandon outcome-only judgment and score every step. The difficulty is that scoring intermediate steps in software engineering or security analysis requires strong domain understanding. If the scorer itself is not capable enough, a deadlock emerges: the model cannot improve because it cannot be scored accurately, and it cannot be scored accurately because it is not strong enough. Manual annotation is also impractical: with massive trajectories and a state space as long as a Go game, neither annotation cost nor consistency can be guaranteed.

    A more practical direction in the industry is therefore to avoid introducing a subjective external scorer and instead use the environment’s own verifiable feedback to construct local counterfactual estimates.

    3. Core Idea: Adaptive Optimization and Counterfactual Branch Valuation

    3.1 From Outcome Reward to Local Value

    Adaptive optimization shifts the optimization target from the final success or failure of an entire trajectory down to whether a specific key state is better. The idea is related to Monte Carlo tree search and counterfactual analysis in causal inference: the value of a step is judged not by whether it directly leads to victory, but by whether, starting from that state, an equally capable executor is more likely to succeed.

    3.2 Counterfactual Branch Valuation Process

    1. Fix the context and environment snapshot for the first k steps (repository, terminal state, test configuration).
    2. Clone multiple parallel branches from step k and step k+1 respectively.
    3. Let the same model continue execution to task termination on each branch with an equal sampling budget.
    4. Collect verifiable metrics for each branch, such as success rate, average interaction turns, and test pass rate.
    5. If a step significantly raises the subsequent success rate, mark it as a critical correct decision and give it a positive local estimate; otherwise, suppress it.

    Illustrative pseudocode:

    1. def counterfactual_value(snapshot, step_a, step_b, rollout_budget=64):
    2. # snapshot: environment snapshot fixed after the first k steps
    3. succ_a = run_branches(snapshot, first_action=step_a, budget=rollout_budget)
    4. succ_b = run_branches(snapshot, first_action=step_b, budget=rollout_budget)
    5. # use verifiable results (whether tests pass) rather than subjective scoring
    6. return succ_b.success_rate - succ_a.success_rate

    3.3 The Boundary of the Go Analogy

    In Go, end-state judgment is objective and complete, whereas “success” in software tasks must be defined by multiple signals such as test cases, static checks, and security policies. Branch valuation must therefore be built on an environment that is executable, reproducible, and decidable. This is also why sandbox capability is a prerequisite.

    4. Engineering Practice: Sandbox Scaling Is the Hidden Foundation

    The source material notes that this generation of capability improvement does not come from a jump in parameter count, but from a several-fold increase in the number of sandbox environments, which can be called “sandbox scaling.” In engineering terms, this means:

    • Environment as data: Each task needs an independent, resettable, snapshot-capable runtime that supports parallel branch cloning.
    • Scheduling and isolation: A container platform handles unified orchestration, with resource quotas, network policies, and a read-only root filesystem to keep branches from contaminating each other.
    • State snapshots: Low-cost snapshots of the filesystem and process state support “replay from step k.”
    • Observability: Logging services and monitoring alerts collect each turn’s commands, return codes, latency, and failure reasons, forming a closed loop for training and troubleshooting.
    • Security boundary: Sandboxes have no external network access by default or use a controlled egress proxy, and secrets are injected through a key management service to prevent real side effects during training.

    Illustrative environment description (neutral pseudo-config):

    1. task_env:
    2. image: base-dev-image
    3. network: restricted-egress
    4. snapshot: enabled
    5. parallel_branches: 32
    6. limits: {cpu: 2, memory: 4Gi, timeout: 900s}

    5. Reward and Data Design

    • Layered rewards: The end-state pass rate is the main reward, supplemented by auxiliary signals such as test pass ratio, static check results, and defect reproduction success rate.
    • Penalize slips without invalidating the whole: Give a small negative reward for end-stage syntax or variable errors to avoid zeroing out the entire trajectory.
    • Length and cost constraints: Apply a mild penalty for redundant turns to suppress meaningless confirmation.
    • Prevent reward hacking: Hide part of the test cases so the model cannot hardcode return values against visible assertions.
    • Curriculum learning: Tier tasks by interaction turns and repository size, starting with short tasks before long ones to stabilize training.

    6. Evaluation: How to Verify “Emergence” Rather Than Overfitting

    Evaluation should cover four dimensions: functional correctness (unit and integration tests), long-horizon stability (the decay curve of success rate as turns increase), security capability (the rate of identifying and fixing vulnerabilities in authorized range environments), and cost efficiency (average tokens and turns to complete a task). It must be emphasized that security-related evaluation must be conducted in isolated ranges with explicit authorization, used only for defensive research and fix validation, and not for attacking real systems.

    The comparison table in the source material (scores of models with different parameter counts on long-horizon agents, vulnerability repair, security benchmarks, and general exam-style benchmarks) shows a trend: with less than half the parameters of a competitor, post-training and environment scaling can achieve comparable or even better performance on multiple verifiable tasks. This suggests that the engineering quality of data and environments is becoming a variable as important as model scale.

    7. Common Pitfalls and Risks

    • Treating branch valuation as a precise value function: It is only a statistical estimate and needs enough branches and variance control.
    • Ignoring environment non-determinism: Network jitter and unstable dependency sources can contaminate success rates, so dependency snapshots must be fixed.
    • Over-optimizing a single benchmark: This easily causes overfitting to the evaluation set, so a private holdout set should be kept.
    • Compliance red lines: Security capability research must be limited to authorized scope, and outputs should serve vulnerability repair and defensive hardening.

    8. Conclusion

    The “emergence” of frontier coding and cybersecurity capabilities essentially comes from three things combined: verifiable environments, a reusable local credit assignment method, and large-scale sandbox infrastructure. When optimization moves from outcome-only judgment to counterfactual local valuation, long-horizon agents have a chance to converge stably while maintaining exploration. For development teams that want to build similar capabilities in their own business, the priority is to build containerized sandboxes and a unified logging and monitoring system, using general-purpose container, object storage, logging, and monitoring capabilities from Baidu AI Cloud as the foundation, first making the “reproducible task environment” solid before pursuing training method innovation.