Evaluating Long-Horizon Coding Agents: Sandbox Design, Metrics, and Engineering Practices
This article presents a practical framework for evaluating AI systems that autonomously complete multi-step software engineering tasks. It explains why single-turn code benchmarks are insufficient, how to design reproducible terminal-based sandbox evaluations, which metrics should be tracked, common pitfalls in interpreting results, and concrete steps for building an internal evaluation program.
Long-horizon coding agents are AI systems that can autonomously complete multi-step software engineering tasks over extended periods. They need to read codebases, execute commands, observe outputs, correct errors, and remain goal-consistent after dozens or even hundreds of operations. Compared with single-turn code completion, evaluating this capability is considerably harder, because a judgment error at one step can be amplified in later steps.
I. Why Long-Horizon Capability Needs Dedicated Evaluation
Single-turn code generation evaluations usually focus only on whether a function passes test cases. Long-horizon tasks involve environment state, file changes, dependency installation, and repeated trial and error. An agent may misunderstand the requirement at step three and only expose the problem at step forty. If evaluation looks only at final pass/fail, it cannot show where the failure occurred.
Evaluation needs to answer three questions: Can the agent complete the task? Is the completion process reliable? Is the cost acceptable? A conclusion missing any one of these is incomplete.
II. Basic Design for Terminal-Based Evaluation
In a real terminal environment, evaluation is closer to engineering reality than in a plain-text setting. The agent needs to use the command line, edit files, and run tests. This design has three advantages:
- Observable behavior: Every command and output is recorded, making replay and retrospective analysis possible.
- Verifiable results: Test scripts or state checks serve as criteria, reducing subjective scoring.
- Realistic constraints: Disk, memory, runtime, and network permissions can all be explicitly limited.
2.1 Environment Isolation and Reproducibility
Each task should start in an isolated environment with an identical initial state. A common practice is to prepare a fixed-version image or snapshot for each task and verify its hash before execution. If multiple tasks share caches or global configuration, residual files from a previous task can contaminate the results of the next one.
Reproducibility also requires recording random seeds, model parameters, and tool versions. Otherwise, when the same batch of tasks is rerun two weeks later, results may differ substantially, and the team cannot determine whether the change comes from the model or the environment.
2.2 Task Definition and Success Criteria
Task descriptions should include a clear goal, the scope of accessible resources, and prohibited actions. Success should ideally be determined by an executable check script. The following pseudo-code illustrates the flow only:
task = load_task("fix_import_error_003")sandbox = create_sandbox(snapshot=task.snapshot_id, cpu=2, mem_gb=4, timeout_s=1800)trajectory = agent.run(task.prompt, sandbox, max_steps=120)result = sandbox.run(task.verify_script)record(task_id=task.id, passed=result.exit_code == 0, steps=len(trajectory), cost=trajectory.cost)sandbox.destroy()
The verification script checks only outcomes, not the agent’s specific implementation. For example, when fixing a dependency conflict, the criterion is that the program starts normally and all tests pass, not that a particular file was modified. This allows multiple reasonable solutions and reduces false judgments.
2.3 Resource Constraints
Resource constraints determine the scope in which evaluation conclusions apply. Time limits, step limits, compute resources, and network permissions all change an agent’s strategy. An agent allowed to search online and a fully offline agent may differ significantly in success rate even if their coding ability is the same. When reporting results, these constraints must be stated.
III. Metrics
A single pass rate can easily hide problems. At minimum, the following four categories of metrics are recommended:
- Task pass rate: The proportion of tasks whose verification scripts pass.
- Average and median steps: These reflect execution efficiency and help identify ineffective loops.
- Per-task cost: This includes inference calls, compute duration, and storage overhead.
- Failure attribution distribution: Failures are grouped into requirement misunderstanding, tool usage errors, context forgetting, timeouts, environment anomalies, and other categories.
Failure attribution is the most valuable because it points directly to improvement directions. If most failures come from context forgetting, the optimization focus should be on recording intermediate results and managing context, rather than simply increasing compute investment.
In addition, the same task should be run multiple times. In systems with strong randomness, a single result is only one sample. Reports can provide the mean and range of variation across multiple runs.
IV. Common Pitfalls in Interpreting Results
First, small gaps on a leaderboard are not necessarily statistically significant. If two systems differ by only one or two percentage points, and the number of tasks is limited and runs are insufficient, conclusions should be cautious.
Second, the evaluation set may overlap with training data. Once public tasks are widely circulated, they may enter training corpora and inflate scores. Internal evaluation sets should be updated regularly, and a portion of private tasks should be retained.
Third, ignoring cost can lead to poor system selection. If a system’s success rate is a few percentage points higher but its per-task cost is double, it may not be more reasonable for teams using it at scale.
Fourth, evaluation scores should not be equated with production performance. Production codebases are larger, requirements are more ambiguous, and permission management is stricter. Evaluation scores can serve as a reference, but small-scale pilots in real workflows are still needed.
V. Engineering Recommendations for Enterprise Adoption
To build an internal evaluation system for long-horizon coding capability, teams can proceed in the following steps:
- Step 1: Extract tasks from the team’s historical tickets, covering categories such as defect fixes, dependency upgrades, test additions, and small refactors.
- Step 2: Write verification scripts for each task category, and have humans review the correctness of the scripts themselves.
- Step 3: Build a unified execution environment. The sandbox can be implemented on a container platform. Run artifacts and trajectory logs should be written to object storage or a logging service for long-term retention and retrieval.
- Step 4: Track key metrics through monitoring and alerting, such as a sudden drop in pass rate, a rise in timeout rate, or abnormal per-task cost.
- Step 5: After each model change or prompt strategy adjustment, run the same regression tasks and compare changes in failure attribution.
Data security also requires attention. The sandbox should restrict external network access. Credentials should be injected through a secret management service and must not be written into task images or logs. Execution permissions should follow the principle of least privilege, and the agent should only be able to access directories required for the current task.
VI. Conclusion
The core of evaluating long-horizon coding capability is to break “whether the task can be completed” into a process that is observable, reproducible, and attributable. Environment isolation makes results trustworthy, verification scripts make judgments objective, and multidimensional metrics make conclusions complete. Once this infrastructure is in place, teams can make stable and explainable choices as models and tools continue to update.
