Skip to content

Sandbox tasks

A sandbox world gives an agent a real task on a computer (create files, run programs, fix code) instead of a game move. Checks that the agent never sees decide whether it worked (SPEC-014).

You need Docker (or Podman) installed and running. agentplaykit doctor tells you if it is ready. Nothing else in AgentPlay needs it.

Try it

agentplaykit play examples/hello-sandbox/scenario.yaml
finished: agent wins in 4 steps, cost $0.0000 -> runs/hello-sandbox-0.jsonl

The example's agent is scripted, so it needs no model. Swap in a real one by changing its use line, for example {id: agent, use: ollama, config: {model: llama3.2}}. Then run it many times for a pass rate (--runs 10), or compare models with a tournament or a report (Compare agents).

Write a task

agentplay: 1
name: hello-sandbox
world:
  use: sandbox
  config:
    task: "Create a file hello.txt in /work that contains exactly the word hello."
    image: python:3.12-slim          # the default
    files: start                     # optional: folder copied into /work first
    setup: ["python3 -m venv /work/.venv"]   # optional: run before the agent starts
    checks:                          # required: each passes when its command exits 0
      - {name: file exists, run: "test -f /work/hello.txt"}
      - {name: says hello, run: "test \"$(cat /work/hello.txt)\" = hello"}
    check_files: checks              # optional: folder copied into /check for the checks only
agents:
  - {id: agent, use: ollama, config: {model: llama3.2}}
limits: {max_steps: 20, max_cost_usd: 0.10}
Option Default Meaning
task (required) What the agent must do, in plain words
checks (required) {name, run} commands; the task passed when all exit 0
image python:3.12-slim Container image; it needs sh, tar, timeout and realpath (Debian-based images have them)
files none Folder next to the scenario, copied into /work before the run
setup none Commands run in /work before the agent starts (no network)
check_files none Folder copied into /check, visible only to the checks
resources {cpus: 1, memory_mb: 512, pids: 128, disk_mb: 256, tmp_mb: 64} Caps
timeouts {command_s: 30, setup_s: 120, check_s: 60, run_s: 600} Per command, setup, check, and total sandbox time
max_output_chars 8000 Longer output is cut, keeping the start and the end
pull missing never: do not download the image
runtime auto docker, podman or auto

What the agent sees and does

Each turn the agent gets the task, its working directory (/work), the result of its last action, and the image. It answers with one of four tools:

{"tool": "run", "command": "ls -la"}
{"tool": "write_file", "path": "hello.txt", "content": "hello"}
{"tool": "read_file", "path": "hello.txt"}
{"tool": "done"}

Paths must stay inside /work. A command that runs longer than command_s is stopped and reported as timed out; the run goes on.

When the agent says done, runs out of steps, forfeits or uses up its sandbox time, the checks run. An agent that ran out of steps still gets credit for what it finished. The result is in the log's last line: which checks passed, the score (passed checks / all checks), and the exact image digest, so the run can be repeated on the same image.

How it is kept safe

  • No network. The container has no network at all.
  • Not root. The agent's commands run as an ordinary user, with all Linux capabilities dropped and no way to gain new ones. The system files are read-only; only /work and /tmp are writable.
  • Caps on CPU, memory, processes, disk and time.
  • Nothing from your machine. No folders are shared and no environment variables are passed (your API keys included). Task files are copied in, never shared.
  • Fair checks. When the agent is done, every process it started is stopped and verified gone. Its /work folder is copied into a fresh container, and only then are the checks copied in and run. The agent can never read the checks, change them, or leave a program running to fool them.
  • Nothing left behind. Containers are deleted when the run ends, even after an error or Ctrl+C. After a crash or power loss, agentplaykit sandbox prune removes any leftovers (it only touches containers AgentPlay labelled).

A container is a strong barrier against mistakes and ordinary misbehaviour, but it shares your computer's kernel, so it is not a perfect one. For agents that nobody trusts at all, run AgentPlay inside a virtual machine.