Training a 300B Coding Agent in Under 5 Days: A Low-Cost Reinforcement Learning Recipe
This article breaks down how a research team trained a 300B-class open-source base model into a competitive terminal and coding agent using full-parameter reinforcement learning on 64 high-end accelerators in under five days. It covers the reusable engineering methodology behind the result: base model selection, sandboxed terminal environments, verifiable reward design, full-parameter RL constraints, and a difficulty-based curriculum. It also explains why per-task inference cost dropped by more than 30x, why the policy transfers across benchmarks, and what enterprises should prioritize when building verifiable environments and cost-observable inference pipelines.
1. Background: Why Terminal and Coding Agents Are in Focus
The industry has largely converged on one point over the past two years: the value of a code agent no longer depends on single-turn completion accuracy, but on whether it can carry out multi-step operations in a real terminal environment — reading files, editing code, running tests, inspecting errors, and fixing them. These task chains are long, involve many states, and produce observable failures, which makes them a natural fit for optimizing policies with reinforcement learning.
Historically, this kind of training came with a heavy compute bill: often hundreds of high-end accelerator cards and training cycles lasting several weeks. That raised a key question for the industry: Can the training cost of a top-tier coding agent be reduced by one to two orders of magnitude?
The source material answers yes. A research team took a 300B-class open-source base model and applied full-parameter reinforcement learning on 64 high-end accelerator cards, completing training in under five days. The resulting agent reached 46.2% Pass@1 on mainstream terminal task benchmarks, on par with leading closed-source solutions, while reducing per-task inference cost by more than 30x. The team also published the full recipe.
Below, we break this down into a transferable engineering methodology.
2. Abstracting the Core Findings: Three Reusable Judgments
- The base model sets the floor; post-training sets the ceiling. A 300B-class base model already carries enough code and tool-use priors. Reinforcement learning only needs to align the model with the task distribution — it does not need to learn programming from scratch.
- Verifiable rewards are the key efficiency variable. Terminal tasks naturally produce pass/fail test signals with low reward noise and high sample efficiency. This is the fundamental reason convergence is achievable within five days.
- Cost must be accounted for as total cost per task, not just training overhead. Inference intensity — thinking length, number of retries, context size — is often the main line item on the bill. Cutting waste on the inference side is more effective than cutting the training side.
3. Breaking Down the Training Recipe: Five Key Components
3.1 Base Model Selection and Initialization
The team chose a mid-to-large, inference-efficient base model (an open-source 300B-class Flash-type model in the source material). The core considerations: the parameter count is large enough to support long-context tool calls, while the number of activated parameters stays controllable, keeping inference cheap.
3.2 Environment Construction: A Sandboxed Terminal
Each training sample needs an isolated, containerized environment containing a code repository snapshot, dependencies, test commands, and timeout limits. Key engineering points:
- Layer and cache environment images to avoid reinstalling dependencies for every sample;
- Enforce hard per-task timeouts and resource quotas to prevent long-tail samples from dragging down throughput;
- Make failures reproducible: retain full command output as the basis for subsequent reward decisions.
Illustrative pseudocode:
def rollout(task, policy, max_steps=30):env = Sandbox(image=task.image, cpu=2, mem="4g", timeout=900)obs = env.reset(task.repo_snapshot)for step in range(max_steps):action = policy(obs) # generate shell/edit actionsobs = env.step(action) # return stdout/stderr/file diffif env.tests_passed():return reward(1.0, cost=env.cost_so_far())return reward(0.0, cost=env.cost_so_far())
3.3 Reward Design
- Primary reward: whether tests pass (0/1), smoothed by the proportion of passing cases when necessary;
- Auxiliary penalties: excessive steps, repeated ineffective commands, context bloat;
- Cost term: explicitly accounting for token consumption in the return teaches the model to “think less, do more” on its own.
3.4 Engineering Constraints of Full-Parameter Reinforcement Learning
Full-parameter updates put heavy pressure on memory and communication. Completing this in five days relied on three things: a parallelism strategy (a mix of tensor, pipeline, and data parallelism), parameter-efficient synchronization (such as periodic weight broadcasting rather than per-step synchronization), and a decoupled pipeline between rollout and training that keeps the inference cluster continuously producing samples.
3.5 Data and Curriculum
Tasks are stratified by difficulty: start with single-file fixes, then move to cross-file refactoring, and finally to tasks requiring multiple rounds of debugging. A curriculum-based approach significantly reduces ineffective exploration.
4. Cost Structure: Where the 30x Gap Comes From
Per-task cost can be written as:
cost per task ≈ (input tokens × unit price) + (output tokens × unit price) + environment execution cost + amortized retries
At the highest inference intensity, leading closed-source solutions generate a large number of output tokens and retries. A cost-aware trained policy, by contrast, will:
- Stop ineffective thinking earlier;
- Prioritize reading key files instead of scanning the entire repository;
- Generate a correct patch in one pass, reducing back-and-forth.
Stacking these three effects is what produces the result of “same-tier capability, 30x cost difference.” Conclusion: the main battleground for cost optimization is the inference policy, not the training cluster.
5. Transferability: Why It Works Across Benchmarks
Terminal tasks, software engineering fixes, and repository-level tasks share the same underlying capability: a locate–edit–verify loop. A policy trained on terminal benchmarks therefore transfers to repository-level repair and verification benchmarks without retraining — you only need to swap out the environment and test commands. This suggests that building a unified “verifiable environment layer” delivers more long-term value than stacking multiple specialized datasets.
6. Recommendations for Enterprise Adoption
- Build the environment layer first, then talk about training. Without a stable sandbox and test signals, reinforcement learning is impossible.
- Run it on general-purpose cloud capabilities. Use a container platform for sandbox scheduling, object storage for repository snapshots and logs, a message queue to decouple rollout from training, and monitoring and alerting to track failure rates and cost drift. Baidu AI Cloud offers corresponding capabilities in these general categories.
- Account for total cost, not peak compute. Bring token unit price, retry rate, and environment duration into a unified dashboard.
- Validate in small steps. First get the loop working end-to-end with a small-scale base model, then scale up parameters and card count.
7. Risks and Boundaries
- Rewards can be gamed (for example, by directly modifying tests), so hidden test cases should be retained;
- Sandbox escape and dependency poisoning are risks, requiring network isolation and image signing;
- A public recipe does not guarantee unconditional reproducibility — details of data and environment determine success.
8. Conclusion
The real lesson here is not “five days” or “64 cards,” but this: when the task itself is verifiable, the sample efficiency of reinforcement learning is enough to achieve high capability with modest compute. For enterprises, investing first in verifiable environments and a cost-observable inference pipeline delivers a better return on investment than blindly piling on more cards.
