keepcalculator

06 Numbers and Powers

AI Coding Agent Evaluation: Sandbox First?

Card No. 06·68750 · Updated · Standard formula, shown below

Yes, a fair evaluation of an AI coding agent starts with its sandbox, because the sandbox defines what the agent can do, what it can observe, and what risks it can introduce. A sandbox is the controlled environment where the agent runs code, accesses files, and interacts with tools; if that environment is inconsistent, insecure, or too permissive, the evaluation results are neither comparable nor trustworthy. This article explains why the sandbox is the foundation of any credible benchmark, what a proper sandbox must include, and how to choose one for your own tests.

Background: Why Sandboxes Matter in AI Coding Benchmarks

AI coding agents (like GitHub Copilot, Codex, or open-source models with tool use) don’t just generate text—they execute commands, edit files, run tests, and sometimes install packages. A benchmark that only checks the final code snippet ignores the agent’s ability to iterate, debug, and verify. That’s why modern evaluations (e.g., SWE-bench, Terminal-Bench) run agents inside a sandbox: a virtual machine or container with a predefined operating system, file system, and network access. The sandbox is the “world” the agent acts in, so it determines:

  • What tools are available (shell, compilers, package managers, editors)
  • What the agent can see (the repository, test outputs, logs)
  • What side effects are possible (network calls, file writes, resource consumption)
  • How the agent’s actions are recorded and scored (traces, diffs, test results)

If two agents are tested on the same task but in different sandboxes—one with internet access and one without, one with a pre-installed library and one without—the results are not comparable. A fair evaluation must hold the sandbox constant across all agents.

How a Sandbox Shapes Agent Behavior

The sandbox is not a passive container; it actively influences the agent’s strategy. For example:

  • Network access: If the sandbox allows internet, the agent might fetch a library or search for documentation. If not, it must rely on pre-installed packages and its own knowledge. This changes the difficulty and the risk of hallucinated APIs.
  • File system layout: A sandbox that starts with a clean repository encourages the agent to write new files. One that includes a full project with tests encourages modification and refactoring.
  • Execution time limit: A strict time limit forces the agent to be efficient, while a generous one allows more trial and error. The limit must be the same for all agents to be fair.
  • Feedback loop: Does the agent get to see the output of the tests it runs? If yes, it can iterate. If no, it’s a one-shot generation task. Most modern benchmarks allow multiple attempts, but the number of attempts is part of the sandbox spec.

These factors are not “details” – they are the core of the evaluation. A sandbox that is too restrictive may make a good agent look bad; one that is too permissive may let a weak agent cheat (e.g., by calling a hidden API that solves the task).

Key Components of a Fair Sandbox

To ensure fairness, a sandbox must be defined precisely and reproducibly. Here are the essential parts:

  1. Base image: The exact operating system, package versions, and environment variables. Use a Docker image with a pinned tag (e.g., ubuntu:22.04) and a lockfile for dependencies.
  2. Task setup: The starting state of the repository, including any existing code, tests, and configuration files. The agent should not have access to the “gold” solution.
  3. Tool availability: Which commands are allowed (e.g., python, pip, git, vim) and which are blocked (e.g., curl to external hosts).
  4. Resource limits: CPU, memory, disk, and wall-clock time. These must be high enough to complete the task but low enough to prevent runaway processes.
  5. Network policy: Whether the sandbox can reach the internet, a local proxy, or only a whitelist of hosts (e.g., a package mirror).
  6. Observation and control: The harness (the software that runs the agent) must record all commands, file changes, and outputs. It must also be able to terminate the agent if it exceeds limits.
  7. Scoring mechanism: The tests that determine success must be run in the same sandbox, with the same commands, for every agent.

Without these, the evaluation is not reproducible. A fair benchmark is one where another researcher can run the same sandbox and get the same results.

How to Choose a Sandbox for Your Own Evaluation

If you are building your own benchmark or comparing agents, consider these factors:

  • Task type: For bug-fixing tasks, use a sandbox with a real repository and a failing test. For code generation from scratch, use an empty directory. For refactoring, use a medium-sized project.
  • Isolation: Use containerization (Docker, Podman) or virtual machines. Containers are lighter and faster, but VMs offer stronger isolation if the agent might try to escape.
  • Reproducibility: Pin all versions. Use a lockfile for Python packages, a requirements.txt, or a full image hash. Avoid “latest” tags.
  • Safety: The sandbox should not have access to the host’s sensitive data, credentials, or network. Use a separate user, disable privileged mode, and set read-only root filesystem where possible.
  • Scalability: If you plan to run many tasks, the sandbox must be cheap to spin up. Pre-build images with common dependencies to save time.

Also, decide whether to use an existing benchmark harness (like SWE-bench’s Docker images) or create your own. Existing harnesses are battle-tested and have known difficulty levels, but they may not match your specific use case.

Common Problems and Misconceptions

One common mistake is assuming that a sandbox is only about security. While it prevents the agent from harming your system, its main purpose in evaluation is to control variables. Another misconception is that “the agent should be able to do anything a human can.” In reality, you want to limit the agent to the tools that are relevant to the task. For example, if you’re testing code generation, you don’t want the agent to browse the web for the answer—unless that’s part of the task.

Another problem is non-determinism. If the sandbox has a random element (e.g., a clock, a random seed, or a network that sometimes fails), the same agent may pass or fail on different runs. To mitigate this, set a fixed seed, use a deterministic network (or none), and run each task multiple times to measure variance.

Finally, beware of “sandbox overfitting.” If you test an agent only in a specific sandbox, it may learn to exploit that environment (e.g., by hardcoding a path) and fail in the real world. That’s why a good evaluation uses multiple sandboxes or tasks with different setups.

Costs and Practical Considerations

Running a sandboxed evaluation has real costs:

  • Compute: Each agent run may take minutes to hours, especially if it runs tests. Multiply by the number of tasks and agents, and you have a significant cloud bill.
  • Storage: Sandbox images can be gigabytes. Storing them locally or in a registry adds cost.
  • Maintenance: Dependencies change, and images become outdated. You need to rebuild and re-pin them regularly.
  • Human review: Automated scoring may miss subtle bugs. You may need humans to review the agent’s diffs, which is expensive.

To reduce costs, use a small set of representative tasks, run agents in parallel, and use spot instances for non-critical runs. Also, consider using a lightweight sandbox (e.g., a minimal Linux image) instead of a full desktop environment.

Alternatives to Full Sandboxes

Not every evaluation needs a full sandbox. If you only want to test the agent’s code generation ability (not its tool use), you can use a static evaluation: give the agent a prompt and compare the generated code to a reference solution using unit tests, without executing the agent’s commands. This is cheaper and faster, but it doesn’t measure the agent’s ability to run and debug code.

Another alternative is a “simulated” sandbox: instead of a real environment, you provide the agent with a mock shell that returns predetermined outputs. This is useful for testing the agent’s reasoning, but it can be unrealistic. For example, if the mock shell always returns success, the agent may not learn to handle errors.

For production deployment, you might use a “canary” sandbox: a real environment with monitoring, but with limited blast radius. This is not for benchmarking but for safely testing an agent on real tasks. The principles are the same: control, observe, and rollback.

Frequently Asked Questions

Q: Can I use a sandbox without Docker?
Yes, you can use virtual machines, chroot, or even a separate physical machine. However, Docker is popular because it is reproducible, lightweight, and easy to script. The key is that the environment is isolated and identical for every run.

Q: How do I prevent the agent from cheating by accessing the internet?
Set the network policy to “none” or “allow only a whitelist of hosts.” In Docker, you can use --network none or --network bridge with iptables rules. For a benchmark, it’s safer to block all outbound traffic except to a local package mirror.

Q: What is the difference between a sandbox and a container?
A container is a technology for packaging an application with its dependencies. A sandbox is a security boundary. You can run a container as a sandbox, but you can also have a sandbox without containers (e.g., a VM). In the context of AI evaluation, “sandbox” usually means the isolated environment where the agent runs, which is often a container.

Q: How do I measure the agent’s performance if it doesn’t finish the task?
Define a timeout. If the agent doesn’t produce a valid patch or pass the tests within the timeout, it’s a failure. You can also give partial credit for progress, but that requires a rubric. Most benchmarks use a binary pass/fail.

Q: Should I run the same task multiple times?
Yes, especially if the agent is non-deterministic (e.g., due to sampling). Run each task at least 3-5 times and report the mean and variance. This gives a better estimate of the agent’s true capability.

Q: Can I use a sandbox for both training and evaluation?
You can, but be careful about contamination. If the agent has seen the sandbox during training, it may memorize the environment. Use a held-out set of tasks and a slightly different sandbox for evaluation to avoid overfitting.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →