SPEC-014: Sandbox worlds¶
- Status: Accepted
- Milestone: v0.6.0
- Owners: lead maintainer
1. Purpose¶
Let an agent do a real task on a computer (create files, run programs, fix code) instead of a game move, and check the result fairly. The task runs inside a throwaway container with no network, capped CPU, memory, processes and disk. A checker that the agent never sees runs only after the agent has finished, in a fresh container, so the agent cannot read it, change it or fool it while it runs. Everything the agent did is in the run log, like any other world.
The first task is the plan's example: "create hello.txt containing hello".
2. Terms¶
Keywords MUST, SHOULD and MAY follow RFC 2119. - Sandbox: the container one run's agent works in. It exists only for that run. - Container runtime: the program that runs containers: Docker, or Podman as a drop-in. - Task: what the agent must do, in plain words, plus the files and setup it starts with. - Tool action: one thing the agent asks for: run a command, write a file, read a file, or say it is done. - Check: a command that decides whether the task was done. It exits 0 if that part passed. - Check container: a fresh container, started from the agent's finished files after every agent process has stopped, in which the checks run.
3. Requirements¶
The world¶
- SBX-001 The framework MUST ship a built-in world
sandboxwith one agent, idagent. ItsconfigMUST accepttask(text, required),image(defaultpython:3.12-slim),files(a folder next to the scenario, copied into/workbefore the run),setup(commands run before the agent starts),checks(required: a list of{name, run}),check_files(a folder copied into/checkfor the checks only),resources,timeouts,max_output_chars,pull(missingornever, defaultmissing) andruntime(docker,podmanorauto, defaultauto). The image MUST providesh,tar,timeoutandrealpath(GNU coreutils, as in Debian-based images); the default image does. - SBX-002 Each turn the observation MUST include the task, the working directory (
/work), the result of the previous action (output, exit code, whether it timed out or was cut short) and the image with its digest; the steps left reach the agent in the request'slimits(SPEC-004).actions()MUST return a JSON Schema (ENV-008) for exactly these tool actions: {"tool": "run", "command": "<shell command>"}runs in/workwithsh -c;{"tool": "write_file", "path": "<path>", "content": "<text>"};{"tool": "read_file", "path": "<path>"};{"tool": "done"}ends the agent's work. Any other action is illegal (ENV-012), with an error naming the four tools.- SBX-003 The episode MUST end when the agent sends
done, when it forfeits, when the sandbox time limit is reached, or when a run limit is reached (SPEC-004). The checks run in all of these cases, so an agent that ran out of steps still gets credit for what it finished. The world declaresoutcome_on_limit: trueindescribe()for this (RUN-022). - SBX-004 Command output returned to the agent MUST be cut to
max_output_chars(default 8000, keeping the start and the end, with a marker saying how much was cut). Each command MUST be stopped aftercommand_s(default 30 seconds) and reported as timed out, without ending the run. - SBX-005 File paths in
write_fileandread_fileMUST be inside/work; anything else (absolute paths elsewhere,.., symlinks that leave/work) MUST be an illegal action.
Isolation¶
- SBX-006 The sandbox MUST run with no network (
--network none). v0.6 has no option to turn the network on. - SBX-007 The sandbox MUST run as a non-root user, with all Linux capabilities dropped,
no-new-privileges, a read-only root file system, and writable/workand/tmponly. - SBX-008 Resource caps MUST apply, with these defaults that
resourcesmay change: 1 CPU, 512 MB memory (no swap), 128 processes, 256 MB of disk in/workand 64 MB in/tmp. A whole run MUST also stop attimeouts.run_s(default 600 seconds) of sandbox time. - SBX-009 Nothing from the host MAY be shared with the sandbox: no host folder mounted, no
container-runtime socket, no host environment variables (API keys included), no extra devices.
Task files MUST be copied in, never mounted. The sandbox gets only
AGENTPLAYKIT_SEED. - SBX-010 The sandbox and every check container MUST be removed when the run ends, whatever
the reason: done, limits, world or agent errors, Ctrl+C. Each container MUST carry the labels
agentplaykit=sandboxandagentplaykit.sandbox=<random id>, so leftovers (after a crash or power loss) can be found and removed (SBX-018).
Checking¶
- SBX-011 After the agent's work ends, the world MUST stop every process the agent started
(agent commands run as their own user, so they can all be stopped and their absence verified),
copy out
/work, remove the sandbox, then run each check in a check container that starts from those files. The check container has the same isolation as SBX-006 to SBX-009, and the check commands and any check files MUST be copied in only at that point, so the agent can never see or change them. - SBX-012 A check MUST count as passed when its command exits 0 within
timeouts.check_s(default 60 seconds). The outcome MUST be:winners: ["agent"]if every check passed, otherwise[];scores: {"agent": passed checks / all checks};checks: a list of{name, passed, exit_code, timed_out, output}, with output cut as in SBX-004; andsandbox: the image, its digest and why the agent's work ended. - SBX-013 The built-in
outcomeevaluator MUST work unchanged on sandbox runs ("did the agent win" means "did every check pass"); summaries, reports and pass rates (SPEC-010, SPEC-013) therefore work for sandbox tasks with no further changes.
The log¶
- SBX-014 Every tool action and its result MUST be in the log through the usual
observation,actionandstep_resultevents: thestep_result.infoof every tool action MUST include what it did and its result (forrun:exit_code,timed_outand the cut output). The image MUST be recorded with its digest (observations and outcome), so a run can be repeated on the same image, and the check results are inrun_end.outcome. A failed setup is visible throughrun_end.error(LOG-024). - SBX-015 The run MUST end with reason
world_errorwhen the container runtime fails (image missing and cannot be pulled, runtime not running, setup command fails), with an error that names the cause and the fix, for example "Docker is not running: start Docker Desktop".
Running it¶
- SBX-016 The world MUST use the runtime's command-line program through a subprocess with an
argument list (no shell on the host), and MUST NOT need a Python SDK for Docker or Podman.
With
runtime: auto, it usesdockerif available, elsepodman. - SBX-017
agentplaykit doctorMUST report whether a container runtime is available and running, and how many leftover sandbox containers exist. - SBX-018
agentplaykit sandbox pruneMUST remove every container (and temporary image) labelled by AgentPlay, and print what it removed. It MUST NOT touch anything else. - SBX-019 The framework MUST ship the example
examples/hello-sandbox(the hello.txt task, solved by a scripted agent with no model) and a scripted agentscripted/shellthat runs a given list of tool actions, for tests and demos.
Changes to other specs on acceptance¶
- SPEC-001, ENV-018: add "except the built-in
sandboxworld, which controls containers through SPEC-014 and never touches host files beyond its task folder". ENV-001 to ENV-004 (same seed, same state) are relaxed forsandbox: programs inside a container may use the clock. - SPEC-003, new LOG-024:
run_end.outcomeMAY carrychecksandsandbox(SBX-012), andrun_endMUST carryerror(redacted) when the run endedworld_errororaborted, so the cause is in the log. Additive;log_versionstays 1. - SPEC-004, new RUN-022: a world that declares
outcome_on_limit: trueindescribe()getsoutcome()called when the run ends by a limit, andrun_end.outcomerecords it (the reason stays the limit). RUN-021 also applies to worlds: the runner MUST call the world'sclose(), when it has one, when the episode ends, including on errors and Ctrl+C. - SPEC-007, new CLI-015:
agentplaykit sandbox prune(SBX-018) and thedoctorlines (SBX-017). - SPEC-011, new SEC-014: the isolation rules SBX-006 to SBX-010, and the warning that a container is a strong boundary but not a perfect one: for agents you do not trust at all, run AgentPlay inside a virtual machine.
4. Acceptance criteria¶
| Requirement | Test ID | Notes |
|---|---|---|
| SBX-001..005 | SBX-001..SBX-005 |
a fake runtime (recorded calls) for unit tests; tool schema; path escapes; output cut; command timeout |
| SBX-006..010 | SBX-006..SBX-010 |
the exact runtime arguments; with real Docker: no network, non-root, read-only root, caps hit, nothing left after Ctrl+C |
| SBX-011..013 | SBX-011..SBX-013 |
an agent that edits or deletes the checks, or leaves a background process, cannot change the result |
| SBX-014..015 | SBX-014, SBX-015 |
events and digest in the log; runtime missing, image missing, setup failing |
| SBX-016..019 | SBX-016..SBX-019 |
no shell on the host; doctor and prune; the example passes |
Tests that need a real container runtime are skipped where none is running; a Linux CI job with Docker MUST run them (as the browser job does for the viewer).
5. Examples¶
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
checks:
- {name: file exists, run: "test -f /work/hello.txt"}
- {name: says hello, run: "test \"$(cat /work/hello.txt)\" = hello"}
agents:
- {id: agent, use: ollama, config: {model: llama3.2}}
limits: {max_steps: 20, max_cost_usd: 0.10}
One turn, as the agent sees it and answers:
{"observation": {"task": "Create a file hello.txt ...", "cwd": "/work", "steps_left": 19,
"last": {"tool": "run", "command": "ls", "exit_code": 0, "output": ""}},
"action": {"tool": "write_file", "path": "hello.txt", "content": "hello"}}
agentplaykit play examples/hello-sandbox/scenario.yaml # one run
agentplaykit play examples/hello-sandbox/scenario.yaml --runs 10 # pass rate over 10 runs
agentplaykit sandbox prune # remove any leftovers
6. Open questions¶
- Network access for tasks that need it, limited to an allow-list of hosts (a later version, with its own security review).
- Several agents in one sandbox (pair programming, attacker and defender).
- A
terminalview type so the replay page shows commands and output like a terminal. - Running sandboxes on a remote machine instead of the user's own.
7. Change log¶
- 2026-12-01: Initial draft.
- 2026-12-01: Accepted by the lead maintainer, with details found while building it: the image needs
sh,tar,timeoutandrealpath; agent processes run as their own user so they can be stopped before/workis copied out (containers cannot copy files out of an in-memory folder); tool results go instep_result.infoand failures inrun_end.errorinstead of a new event type; RUN-022 lets checks run on a limit; labels renamed.