Skip to content
codeband is pre-release. These docs describe its first release, and some of what they describe is still being built.

Sandbox

A sandbox is the isolation around one attempt of an agent step or one shell step: the place, such as a container, in which it runs together with its workspace, and which limits what it can reach. The workspace is the files of one commit of the target repository. Each attempt and each shell step gets a new sandbox, and the engine, the part of the daemon that runs steps, removes it at the end.

An agent with full permissions can change every file that its process can reach, and a test passes or fails with the compiler that it finds. A sandbox protects the daemon’s machine from the agent and gives an attempt the same programs on every machine.

A sandbox around one attempt or one shell step, with its own repository, and the daemon outside it Daemon reads [sandbox.NAME] of codeband.toml Engine starts and removes sandboxes Bare clone end commits on hidden refs Sandbox new for each attempt or shell step Harness program or the program of a shell step Workspace in a git repository of its own Repository cache read-only history old commits prompt agent transcript start commit end commit, by git transfer

The pipeline implement below names the sandbox definition go. Its agent implementer changes the code, and the shell step tests runs go test ./... on the change.

import codeband as cb
class Issue(cb.Model):
instruction: str
class Fix(cb.Model):
title: str
summary: str
implementer = cb.Agent("implementer", input=Issue, output=Fix, harness=cb.ClaudeCode(model="sonnet"))
@cb.pipeline(sandbox="go")
def implement(instruction: str) -> cb.RunResult | None:
"""Change the code for the issue, and end the run with the change once the tests pass."""
fix = implementer.do(Issue(instruction=instruction))
tests = cb.shell_step(["go", "test", "./..."], name="tests")
if not tests.ok:
raise cb.Stop("the tests fail on the change of the implementer")
return cb.RunResult(code_change=cb.CodeChange(commit=fix.commit, title=fix.output.title, description=fix.output.summary))
codeband.toml
[sandbox.go]
kind = "docker"
image = "ghcr.io/example/go-agents:1.25"
[sandbox.go.docker]
NetworkMode = "agents"
Memory = 8589934592
[sandbox.go.env]
GOFLAGS = { value = "-mod=readonly" }
  1. For attempt 0 of implementer#0, the engine starts a container of the image ghcr.io/example/go-agents:1.25, with the settings of the docker table and the variables of [env] and [sandbox.go.env].
  2. The engine sends the start commit into the sandbox, runs the harness program there and reads the agent transcript from its output.
  3. When the harness ends, the engine fetches the end commit and removes the container.
  4. The shell step tests#0 gets a new sandbox from go too, with the implementer’s end commit in its workspace, so go test runs with the compiler that the agent used.

The step request of implementer#0 records the name go, the kind docker and the ID of the image that ran, but no setting and no value of a variable. The run journal records the same for tests#0. A run fork on an image with another ID shows the change in its step request.

A sandbox definition is a named description from which the engine makes sandboxes: its kind and its settings, in a [sandbox.NAME] table of codeband.toml. A pipeline names one definition, and all its agent steps and shell steps use it, so a test runs where the agent that wrote the code ran. A pipeline that names none uses the definition default, which is of kind host unless the file defines it.

The pipeline names a sandbox, and the installation defines it, so one factory can run go as a process on a laptop and as a container on a server. An attempt whose pipeline names an undefined sandbox fails with the attempt failure kind setup.

Kind An attempt or a shell step runs as What it can reach Its programs
host A process on the daemon’s machine, without isolation Every file that the daemon’s user can read and change Those of the daemon’s machine
docker A program in a new container, started through Docker’s API Its workspace, the repository cache and what the docker table mounts Those of the image

codeband installs nothing in a container and never pulls an image, so the image of a docker sandbox holds git, a shell and the program of every harness that the pipeline’s agents use. The kind docker lists what the image needs.

When someone cancels a run or a step times out, the engine sends SIGTERM to the program and to the programs that it started. It sends SIGKILL to those that still run 10 seconds later, and then removes the sandbox. When a definition is of the kind docker, the daemon removes at start the containers that an earlier daemon of the same state folder left behind.

Each sandbox has a git repository of its own, which holds the workspace, and the engine moves commits in and out with git’s own transfer. Git runs the hooks that an agent writes, so every git command on the workspace runs in the sandbox. A code change leaves codeband only through its run result destination, never by a push from a sandbox.

The sandbox’s repository reads old commits from the read-only repository cache, so the engine sends only the commits that the sandbox lacks. The cache is a Docker volume for the kind docker and the daemon’s bare clone for host.

A sandbox does not keep secrets from the agent

Section titled “A sandbox does not keep secrets from the agent”

Every variable of [env] and of [sandbox.NAME.env], a login among them, reaches the harness program and every command that its agent runs. A program that prints its environment puts each value into the agent transcript. Give a definition only the logins that its agents may use.

A container reaches the network that Docker gives it, unless the docker table limits it, for example with NetworkMode. Limit the network of a Docker sandbox allows only the domains of an allow list.

Files outside the workspace do not carry over

Section titled “Files outside the workspace do not carry over”

Each sandbox starts from its image and its workspace, so an agent step in a run fork sees what it saw in the original run. Only a volume in the Mounts setting of the docker table keeps files from one sandbox to the next. Keep only caches there, such as Go’s build cache, because the step request does not record its files.