Long-Horizon Agent Reinforcement Learning: How Sandbox Scaling and Process Rewards Address the Credit Assignment Problem
This article explains how reinforcement learning is used to train long-horizon AI agents. It covers why outcome-only rewards struggle with credit assignment in multi-step software engineering and cybersecurity tasks, how counterfactual branch valuation estimates the value of individual decisions, and why scaling the number of sandbox environments may matter as much as scaling model parameters. It ends with practical guidance for developers and enterprises evaluating and deploying agent models.
Recent releases from an open-source large language model developer have drawn wide discussion among developers. The most notable aspect of the new model is not parameter growth. It has less than half the parameters of the previous flagship, yet it outperforms that model on long-horizon software engineering and cybersecurity attack-and-defense evaluations. This result points to a broader shift in how large models are trained: from “model scaling” to “environment and data scaling,” and from outcome rewards to process rewards in reinforcement learning.
This article sets aside the specific product and examines three core questions behind this trend from a general technical perspective.
1. Evaluating Coding Ability: From Single-Pass Generation to Long-Horizon Interaction
Early code evaluations focused on whether a model could generate correct code in one pass, such as completing a function body from a given signature. These tests are not very representative of real development work. The benchmarks that attract the most attention now are two long-horizon agent benchmarks:
- Software engineering agent evaluations: The model must locate defects in a real code repository, understand the project architecture, modify multiple files, and pass unit tests. A single task often requires dozens of rounds of “think, execute, observe” interaction.
- Cybersecurity range evaluations: The model completes attack and defense tasks in an isolated simulated environment, including vulnerability analysis, exploit construction, and defensive remediation. These tasks also depend on long chains of decisions.
Both types of evaluation share one key trait: the final outcome depends heavily on the quality of every decision in a long sequence. A task may take 30 to 80 interaction steps, and a mistake at any step can cause the entire task to fail. This leads directly to the central training problem.
2. The Reinforcement Learning Dilemma in Long Tasks: Credit Assignment
Mainstream post-training methods, including variants of Group Relative Policy Optimization (GRPO), typically use outcome rewards. After an entire task trajectory finishes, a successful trajectory receives a positive reward, and a failed trajectory receives zero.
Consider a concrete example. Suppose the model performs well in the first 78 steps, covering exploration, defect localization, and architecture understanding. At step 79, it writes an incorrect variable name while modifying code, and the test at step 80 fails. The environment returns a reward of 0. The policy gradient then penalizes all 80 steps equally, including the exploration steps that were actually good.
This is like judging a chess game only by whether you won or lost. Once the game is lost, every strong move made along the way is dismissed. The consequences are:
- Extremely sparse learning signals: Long tasks have low success rates, so many training rounds produce no useful positive feedback.
- Overly conservative behavior: The model learns to do less to avoid mistakes. It tends to stop exploring early, which can increase wasted token consumption.
- Risk of degradation over training: Good intermediate behaviors are penalized repeatedly, and the policy may deteriorate.
The intuitive fix is to score each step, which is known as process rewards. This approach runs into a circular dependency. To judge whether a code change at a given step is good, the scorer must be an expert in software engineering. If the scorer is another model, the quality of its scores is limited by that model’s current capability. A model that does not improve cannot score accurately, and without accurate scores, it cannot improve.
3. Approach One: Adaptive Optimization and Counterfactual Branch Valuation
Drawing on ideas from Monte Carlo tree search and causal inference, a technical approach called adaptive optimization proposes Counterfactual Local Branching. Its core logic is as follows:
- At key decision points in a long trajectory, derive several candidate branches from the same state, similar to node expansion in board game search.
- Let each branch continue for a number of steps, and observe the subsequent outcomes.
- Compare the differences in outcomes that follow from different choices made in the same state to estimate the local value of a single decision, rather than relying on the final success or failure of the whole trajectory.
With this approach, the error at step 79 is attributed only to step 79. The strong exploration in steps 1 through 78 keeps its positive gradient. In essence, counterfactual comparison replaces absolute scoring. This avoids the circular dependency, because the scorer no longer needs to understand all the semantics of software engineering. It only needs to compare the relative quality of sibling branches.
This approach follows the same logic as the self-play mechanism in Go AI. Instead of relying on annotated human game records, the system estimates the value of board positions through large numbers of simulated games. Some people in the community argue that reinforcement learning may repeat the leap that game-playing AI made years ago. That view rests on this similarity.
4. Approach Two: Sandbox Scaling as a New Scaling Law
Traditional scaling laws describe the relationship between parameters, data volume, and compute. The recent open-source model work shows a different scaling axis: the number of sandbox environments. According to public discussion, the number of training sandbox environments for the new version increased by dozens of times.
This matters for several reasons:
- Data comes from interaction, not static corpora: The model trial-and-errors across a large number of executable environments and gains experience with feedback. This information is much denser than static code text.
- Environment diversity determines generalization: Environments that cover more languages, frameworks, defect patterns, and attack scenarios directly determine how well an agent performs on unfamiliar tasks.
- Returns on scaling have not plateaued: A model with half the parameters outperforming a larger model suggests that there is still substantial room to improve training efficiency through environment scaling.
Some people call this the “sandbox scaling” path. Model size stays the same or shrinks, while capability improves by expanding the breadth and depth of interactive environments. For teams with limited compute, this is an important takeaway. Investment in training infrastructure may shift from adding GPUs and parameters toward building large-scale, high-fidelity executable environment clusters.
5. Why Cybersecurity Capability Emerges Alongside Coding Ability
Another notable pattern is that training focused on programming also improves cybersecurity attack and defense capabilities. This is not a coincidence. The two share deep structural similarities:
- Vulnerability discovery ≈ defect localization: Both require tracing data flow and identifying dangerous patterns in large codebases.
- Vulnerability exploitation ≈ precise state manipulation: Both require an accurate causal model of runtime behavior.
- Defensive remediation ≈ code modification and verification: These are the same core actions that software engineering agents perform.
In other words, security capability is a natural extension of three foundational abilities, code understanding, long-horizon reasoning, and environment interaction, applied to a specific domain. For enterprise users, this suggests that evaluating an agent’s security attack and defense performance can serve as a highly discriminating probe of its underlying engineering capability.
6. Practical Recommendations for Developers and Enterprises
As training methods evolve quickly, technical teams can consider the following strategies:
- Choose evaluations that test long-horizon work: Prioritize engineering and security benchmarks that require multiple rounds of interaction over single-turn code generation scores. These benchmarks better reflect how a real development assistant performs.
- Monitor token efficiency: Training methods directly shape how a model behaves at inference time. Conservative or redundant exploration increases actual usage costs. Before deployment, measure the average number of interaction rounds and token consumption on representative tasks.
- Use cloud infrastructure for deployment: When deploying an open-source model privately, you can build inference and evaluation pipelines with general-purpose container platforms, object storage, log services, and monitoring and alerting tools. When you build your own sandbox evaluation environment, container isolation and resource orchestration are key to security and reproducibility.
- Apply security capabilities in both directions: The attack and defense capabilities of a model can support defensive work such as code auditing and vulnerability discovery. They also require strict permission boundaries and audit mechanisms to prevent misuse.
Conclusion
The competition among next-generation open-source models is shifting from a race in parameter scale to a race in training methods. Counterfactual branch valuation addresses the credit assignment problem in long-horizon tasks, and sandbox scaling opens a new dimension for scaling. Together, they make it possible for a smaller model to outperform much larger ones. For developers, understanding this paradigm offers more lasting value than tracking any single version number. The next major leap in agent capability will likely come from coordinated innovation in environments and algorithms, not from compute scaling alone.
