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

Run a pipeline in a Docker sandbox

Move a pipeline into a Docker sandbox when its agents must not change files on the daemon’s machine, or when its tests must find the same compiler on every machine. You build an image with Go and make it the sandbox go of the example pipelines run_program and write_hello. At the end, go test runs with the Go of the image, and the step request of the agent step writer#0 names the image ID that docker image inspect prints. If a step fails, see Troubleshooting.

  • You did the Quickstart: you have a clone of codeband with the binary at build/codeband.
  • Docker runs on your machine: docker version shows a Server part.
  • jq for the check at the end.
  • Run each command from the codeband folder.

For a sandbox of the kind docker, the engine runs each attempt of an agent step and each shell step in a new container of the image, and removes it at the end. codeband installs nothing and pulls no image, so the image holds git, sh, cat, mktemp, sleep, tr, grep, your toolchain and the program of every harness that your agents use.

  1. Add your toolchain to the example image

    examples/docker-sandbox holds a Dockerfile with git, Claude Code, Codex CLI and the user agent, as which every program in the container runs. Copy the folder:

    Terminal window
    cp -R examples/docker-sandbox /tmp/go-agents

    In /tmp/go-agents/Dockerfile, replace the four comment lines below # Add the toolchain of your target repositories here, as root, for example: with the step that they show, without the #. It installs Debian’s Go:

    /tmp/go-agents/Dockerfile
    # Add the toolchain of your target repositories here, as root, for example:
    RUN apt-get update \
    && apt-get install --yes --no-install-recommends golang-go \
    && rm -rf /var/lib/apt/lists/*

    A Debian package goes before USER agent, where the build runs as root. A tool for one user, such as rustup, goes at the end.

  2. Build the image

    Terminal window
    docker build --tag go-agents /tmp/go-agents

    The build ends with the name of the image:

    Output
    #10 writing image sha256:eac71bfcecd43c0270eeba34c5391f5892097ddbbdda5861b1c611ff603eef85 done
    #10 naming to docker.io/library/go-agents done
    #10 DONE 1.6s

    Check that the image has Go, git and Claude Code, and runs as agent:

    Terminal window
    docker run --rm go-agents sh -c 'go version && git --version && claude --version && id -un'
    Output
    go version go1.24.4 linux/arm64
    git version 2.47.3
    2.1.332 (Claude Code)
    agent
  3. Define the sandbox in codeband.toml

    Add a [sandbox.go] table to ~/.config/codeband/codeband.toml. Create the folder with mkdir -p ~/.config/codeband if it does not exist:

    ~/.config/codeband/codeband.toml
    [sandbox.go]
    kind = "docker"
    image = "go-agents"

    image is the tag of docker build --tag.

  4. Name the sandbox on the pipelines

    Give the decorators of run_program and write_hello the argument sandbox="go":

    examples/py-factory/py_factory/program.py
    @cb.pipeline(sandbox="go")
    def run_program(argv: Argv, env: Env = (), timeout_seconds: int = 600) -> cb.RunResult | None:
    examples/py-factory/py_factory/hello.py
    @cb.pipeline(stages=[build], sandbox="go")
    def write_hello(instruction: str = "add a file hello.txt that says hello") -> cb.RunResult | None:

    We recommend one name per toolchain, such as go, so that each installation decides where it runs.

  5. Start the daemon and the code server

    The daemon reads codeband.toml only at start, so stop a running codeband dev with Ctrl-C. In a second terminal, in the codeband folder, run:

    Terminal window
    just examples/py-factory/dev

    The daemon logs the file that it read, the address of the web interface, and Listening when it is ready:

    Output
    Nov 29 21:57:38.922 INF Read the config file comp=daemon path=~/.config/codeband/codeband.toml
    …
    http://127.0.0.1:8765/?token=R4OB2CZ6PNUFA6LV7YJOWURBJS
    …
    Nov 29 21:57:39.321 INF Listening comp=daemon socket=~/.local/state/codeband/daemon.sock
  6. Make a Go target repository

    Back in the first terminal, make a git repository with a Go package and its test:

    Terminal window
    mkdir /tmp/greet-go
    cd /tmp/greet-go
    git init --quiet .
    cat > go.mod <<'EOF'
    module example.com/greet
    go 1.24
    EOF
    cat > greet.go <<'EOF'
    package greet
    // Hello greets name.
    func Hello(name string) string {
    return "hello, " + name
    }
    EOF
    cat > greet_test.go <<'EOF'
    package greet
    import "testing"
    func TestHelloGreetsAda(t *testing.T) {
    if got := Hello("Ada"); got != "hello, Ada" {
    t.Errorf("Hello(%q) = %q", "Ada", got)
    }
    }
    EOF
    git add go.mod greet.go greet_test.go
    git commit -m "Add greet and its test"
    cd -

    The commit prints 3 files changed, and cd - takes you back to the codeband folder.

  7. Run a shell step in the container

    Docker writes the file /.dockerenv into every container, so this test passes only in a container:

    Terminal window
    build/codeband run --repo /tmp/greet-go py-factory/run_program --input '{"argv": ["sh", "-c", "test -f /.dockerenv"]}'

    The shell step is ok. Your run ID is different:

    Output
    Started run 3qyxr1vkht
    ▸ program#0 shell step: sh -c test -f /.dockerenv
    ✓ program#0 exit code 0 after 1.4s
    no code change

    Run the tests of the target repository with the Go of the image. -v prints the output of the program:

    Terminal window
    build/codeband run -v --repo /tmp/greet-go py-factory/run_program --input '{"argv": ["go", "test", "./..."]}'
    Output
    Started run 2bkn4ys8hp
    ▸ program#0 shell step: go test ./...
    ok example.com/greet 0.003s
    ✓ program#0 exit code 0 after 5.1s
    no code change

    Most of the 5.1 seconds go to compiling Go’s standard library in the new container. A volume for the build cache saves that time.

  8. Run an agent step in the container

    write_hello runs one agent step on the fake harness, which needs no login, and ends the run with a patch file:

    Terminal window
    build/codeband run --repo /tmp/greet-go py-factory/write_hello --patch /tmp/greet-go.patch

    The fake agent writes hello.txt in the container, and the engine fetches its commit before it removes the container:

    Output
    Started run 8g73bqf4nb
    ▸ writer#0 agent step of writer
    writer#0: writing hello.txt
    ✓ writer#0 finished after 1.2s, $0.00
    /tmp/greet-go.patch

    An agent on Claude Code runs the claude of the image. codeband check does not test it, so an image without claude fails only when an attempt starts.

The step request of an agent step records its sandbox. Print it for the run of write_hello, with the run ID that step 8 printed in place of RUN_ID:

Terminal window
jq -c '.stepStarted.agentStep.request.sandbox // empty' \
~/.local/state/codeband/store/runs/RUN_ID/journal.jsonl

The command prints one line:

Output
{"name":"go","kind":"SANDBOX_KIND_DOCKER","imageId":"sha256:eac71bfcecd43c0270eeba34c5391f5892097ddbbdda5861b1c611ff603eef85"}

The image ID is the one of go-agents:

Terminal window
docker image inspect go-agents --format '{{.Id}}'
Output
sha256:eac71bfcecd43c0270eeba34c5391f5892097ddbbdda5861b1c611ff603eef85

In the web interface, the page of the run shows the same under Step request. docker ps --all --filter label=codeband.sandbox=go lists no container, because the engine removed each one.

Optional: Keep Go’s build cache in a volume

Section titled “Optional: Keep Go’s build cache in a volume”

A volume in the docker table keeps files from one container to the next. Add one at /home/agent/.cache, where Go keeps its build cache, and set GOFLAGS:

~/.config/codeband/codeband.toml
[sandbox.go]
kind = "docker"
image = "go-agents"
[[sandbox.go.docker.Mounts]]
Type = "volume"
Source = "gocache"
Target = "/home/agent/.cache"
[sandbox.go.env]
GOFLAGS = { value = "-trimpath" }

Docker creates the volume gocache at the first mount. The target must be a folder of the image that belongs to agent. Without -trimpath, Go runs the tests again, because the workspace is in a new folder in each sandbox.

Restart codeband dev and run the tests twice:

Terminal window
build/codeband run -v --repo /tmp/greet-go py-factory/run_program --input '{"argv": ["go", "test", "./..."]}'
build/codeband run -v --repo /tmp/greet-go py-factory/run_program --input '{"argv": ["go", "test", "./..."]}'

The second run takes a second, and Go prints (cached):

Output
Started run pxkhawnsd4
▸ program#0 shell step: go test ./...
ok example.com/greet 0.003s
✓ program#0 exit code 0 after 4.9s
no code change
Started run 600j619yjh
▸ program#0 shell step: go test ./...
ok example.com/greet (cached)
✓ program#0 exit code 0 after 1.0s
no code change

Keep only caches in a volume: the step request does not record its files, so an agent step in a run fork can see other files there.

Stop codeband dev with Ctrl-C, remove the tables of go from codeband.toml, and run:

Terminal window
git checkout -- examples/py-factory/py_factory/program.py examples/py-factory/py_factory/hello.py
rm -rf /tmp/go-agents /tmp/greet-go /tmp/greet-go.patch

The daemon never removes the repository cache of /tmp/greet-go. docker volume ls --filter name=codeband-cache- lists the caches of all target repositories; remove this one with docker volume rm. docker volume rm gocache and docker image rm go-agents remove the build cache and the image.

For an error that this page doesn’t cover, see Run problems.

start the sandbox: the image … is not on this machine, and codeband pulls no image: …

Section titled “start the sandbox: the image … is not on this machine, and codeband pulls no image: …”

The image of [sandbox.go] names an image that your Docker does not have, here go-agents:1.24. An agent step fails with the attempt failure kind setup, and a shell step is not ok:

Output
▸ writer#0 agent step of writer
writer#0 attempt 0 failed: setup: start the sandbox: the image go-agents:1.24 is not on this machine, and codeband pulls no image: run docker pull go-agents:1.24 (no retry)
✗ writer#0 failed after 0.1s: setup: start the sandbox: the image go-agents:1.24 is not on this machine, and codeband pulls no image: run docker pull go-agents:1.24

Build the image with the name of the message, as in step 2, or run the docker pull command of the message for an image of a registry. The next run finds it without a restart. When the name in codeband.toml is wrong, fix image and restart codeband dev.

the pipeline names the sandbox go, which the daemon does not define: it read no config file, …

Section titled “the pipeline names the sandbox go, which the daemon does not define: it read no config file, …”

The daemon read no codeband.toml, or one without [sandbox.go]. The line Read the config file or Read no config file of codeband dev names the file or the places it searched. Add the table there and restart codeband dev.

Start Docker, and check that docker version in the terminal of codeband dev shows a Server part. Docker not reached has the details.