Large-Scale Sandbox Training for AI Agents: Environment Construction, Automated Evaluation, and Feedback Loops
This article describes a large-scale sandbox approach for training AI agents that perform multi-step tasks. It outlines a five-stage workflow covering isolated environment construction, task design and randomization, result collection, automated completion judging, and ranking for training signals. It also discusses the shift from human labels to AI feedback, provides example workflow code, and examines key engineering challenges such as cost control, judge bias, reward hacking, and security isolation. Readers will learn how sandbox infrastructure, automated evaluation, and data pipelines work together to support scalable agent training.
1. Background: Environment Scale Determines Training Quality
Training AI models to perform multi-step tasks requires a large number of reusable interactive environments. To learn how to write code, operate files, call command-line tools, and troubleshoot errors, a model must repeatedly attempt these operations in real or near-real systems. Static text corpora cannot cover these capabilities, because task correctness depends on the final system state; fluent text does not prove that the task was completed correctly.
Therefore, the number, diversity, and reproducibility of environments directly affect training quality. Too few environments can lead to overfitting. If environments are not reproducible, evaluation results for the same policy cannot be compared. If environments differ too much from real usage scenarios, the learned capabilities are difficult to transfer.
2. Core Workflow
The system can be divided into five stages.
2.1 Batch Construction of Isolated Environments
Each task runs in an independent sandbox. Common implementations include virtual machines, lightweight containers, and restricted process environments. Isolation serves three goals: tasks do not interfere with one another, failed operations do not affect the host system, and state can be rolled back quickly.
In engineering practice, environments are often generated using an “image template plus configuration injection” approach. The template fixes the operating system, dependency libraries, and base files. Task parameters such as project code, initial files, and port configuration are injected at startup. This supports batch generation while ensuring that every run starts from the same baseline.
2.2 Task Design and Randomization
The same task needs to be sampled multiple times. Keeping a certain sampling temperature when generating model outputs allows the model to take different operation paths for the same problem. Path diversity helps reveal stability issues under different conditions and expands exploration.
Randomization should remain within an explainable range. File names, data content, and error messages can vary, but the task objective and pass criteria must remain fixed. Otherwise, scoring results are not comparable.
2.3 Result Collection
After a task ends, the system needs to collect three types of information:
- Final filesystem state, such as whether target files exist and whether their contents meet requirements;
- Command execution logs, including exit codes, standard output, and error output;
- Runtime metrics, such as elapsed time, resource usage, and whether a timeout occurred.
Collection should be performed outside the sandbox to prevent the model under test from tampering with records.
2.4 Automated Completion Judging
Judging methods can be divided into three categories:
- Rule-based judging: scripts check deterministic conditions such as the number of passing tests or file hashes;
- Model-based judging: another model reads the task description and execution records, then provides a completion score and rationale;
- Hybrid judging: rules set hard thresholds, while a model handles fine-grained evaluation.
Rule-based judging is stable but has limited coverage. Model-based judging is flexible but can be biased. In practice, rules are usually primary and models secondary, with periodic sample checks on the judging model.
2.5 Ranking and Training Signals
Multiple execution trajectories for the same task receive different scores. After sorting by score, preference pairs can be constructed from better and worse trajectories for training a reward model or for direct preference optimization. Keeping only sample pairs with a sufficiently large score gap can reduce the impact of scoring noise on training.
3. From Human Labels to AI Feedback
Traditional reinforcement learning from human feedback relies on humans to compare and rank model outputs. Human labeling is high quality but costly and slow, and it is difficult to cover many long-horizon tasks.
The idea behind AI feedback is to use a judging model to replace part of human labeling. The judging model scores trajectories according to prewritten evaluation criteria, and the results are used as training signals. This approach depends on three prerequisites: clear evaluation criteria, a reliable judging model, and periodic calibration with human samples.
The core value of this approach is scale. When environment execution and scoring can be automated, the amount of training data can expand with available compute.
4. Example Code
The following code only illustrates the workflow structure. Interface names are generic and do not correspond to any specific product.
def run_batch(tasks, samples_per_task, temperature):records = []for task in tasks:for _ in range(samples_per_task):env = create_sandbox(task.template, task.params)try:trajectory = run_agent(env, task.prompt, temperature=temperature)state = collect_state(env)score = judge(task.criteria, trajectory, state)finally:destroy_sandbox(env)records.append({"task": task.id, "score": score, "trajectory": trajectory})return recordsdef build_preference_pairs(records, min_gap):pairs = []for task_id, items in group_by(records, key="task").items():items.sort(key=lambda r: r["score"], reverse=True)for better, worse in zip(items, items[1:]):if better["score"] - worse["score"] >= min_gap:pairs.append((better, worse))return pairs
Key points: environments are destroyed in a finally block to prevent resource leaks; preference pairs are kept only when the score gap reaches a threshold, which reduces noise.
5. Main Engineering Challenges
5.1 Cost Control
Environment startup, task execution, and judging all consume compute resources. Sampling should be stratified by task difficulty: fewer samples for simple tasks and more samples for difficult tasks, with a budget cap in place.
5.2 Judge Bias
A judging model may prefer a certain writing style or give higher scores to longer outputs. The evaluation criteria version should be fixed, and the agreement rate between judged results and human judgment should be checked periodically using a human-labeled set.
5.3 Reward Hacking
A model may learn to cater to the evaluation criteria rather than actually complete the task, for example by generating only surface-level files that satisfy the checks. Mitigation methods include adding hidden tests, checking task side effects, and rotating judging dimensions.
5.4 Security Isolation
Executing model-generated commands carries risk. Sandboxes need to restrict network access scope, filesystem permissions, and system calls, and they should set timeouts and resource quotas. Environments that involve credentials should use temporary, least-privilege test accounts.
6. Deployment Recommendations
- Start with a small-scale pilot to verify the agreement between automated scoring and human judgment before gradually scaling up.
- Put environment templates, task definitions, and evaluation criteria under version control to ensure experiment reproducibility.
- Save complete logs for every trajectory to support later investigation of judging errors.
- Set cost budgets and monitoring alerts to prevent batch jobs from running out of control.
Sandbox infrastructure, automated evaluation, and data pipelines jointly determine the efficiency of agent training. Teams should first build a reliable automated loop, then gradually improve judging quality and environment diversity.
