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

Limit the network of a Docker sandbox

A sandbox of kind docker reaches the whole internet, because codeband sets no network rules. Limit it when an agent reads text that you don’t control, such as a ticket, because it can tell the agent to send your code to another server. Here you put the sandboxes of one definition behind a proxy that lets through only the domains of an allow list. At the end, a shell step gets 200 from pypi.org, a request to example.com fails with CONNECT tunnel failed, response 403, and the proxy log shows that Claude Code connected to api.anthropic.com. If a step fails, see Troubleshooting.

  • You did Run a program in the target repository, so build/codeband and the pipeline py-factory/run_program exist.
  • Docker: docker version shows a Server section.
  • An image with curl and Claude Code, here codeband-sandbox: docker run --rm --entrypoint curl codeband-sandbox --version prints the version of curl.
  • CLAUDE_CODE_OAUTH_TOKEN or ANTHROPIC_API_KEY in the daemon’s environment, for the agent step of the check.

Run each command from the codeband folder.

The sandbox containers run on the internal Docker network codeband-sandboxes, which has no route out. The tinyproxy container codeband-proxy is on that network and on Docker’s default network bridge, and forwards only requests to domains of the allow list ~/codeband-proxy/allowed. The definition [sandbox.default] puts each container on the network and sets HTTPS_PROXY, which curl, git, pip, Go and Claude Code read. For a pipeline that names another sandbox definition, put the keys of step 4 there.

  1. Make a network without a way out

    Terminal window
    docker network create --internal codeband-sandboxes

    Docker prints the ID of the network. Your ID is different:

    Output
    5f8219eebdf2d2ce5e6ab4d23831566025d71e947a7d8b68ab2de5968176e6dc
  2. Write the allow list

    Make a folder with the config file of the proxy and its allow list:

    Terminal window
    mkdir ~/codeband-proxy
    cat > ~/codeband-proxy/tinyproxy.conf <<'EOF'
    Port 8888
    Timeout 600
    LogLevel Connect
    Filter "/etc/tinyproxy/allowed"
    FilterType ere
    FilterDefaultDeny Yes
    ConnectPort 443
    EOF
    cat > ~/codeband-proxy/allowed <<'EOF'
    ^api\.anthropic\.com$
    ^pypi\.org$
    ^files\.pythonhosted\.org$
    EOF

    With FilterDefaultDeny Yes, the proxy answers 403 to a request whose domain matches no line of allowed. The tinyproxy manual describes the other settings. ^ and $ make a line match the whole domain, so ^pypi\.org$ lets no pypi.org.example.net through. Claude Code needs api.anthropic.com, and pip needs pypi.org and files.pythonhosted.org. Add the domains of your model provider and package registries, such as proxy.golang.org and sum.golang.org for Go.

  3. Start the proxy

    Build an image with tinyproxy, start it on the internal network, and connect it to bridge too:

    Terminal window
    docker build --tag codeband-proxy - <<'EOF'
    FROM alpine:3.20
    RUN apk add --no-cache tinyproxy
    USER nobody
    CMD ["tinyproxy", "-d"]
    EOF
    docker run --detach --name codeband-proxy --restart unless-stopped \
    --network codeband-sandboxes --volume ~/codeband-proxy:/etc/tinyproxy:ro codeband-proxy
    docker network connect bridge codeband-proxy

    docker run prints the ID of the container. -d keeps tinyproxy in the foreground, so its log goes to docker logs. Check that the proxy is on both networks:

    Terminal window
    docker ps --filter name=codeband-proxy --format 'table {{.Names}}\t{{.Status}}\t{{.Networks}}'
    Output
    NAMES STATUS NETWORKS
    codeband-proxy Up Less than a second bridge,codeband-sandboxes
  4. Point the sandbox definition at the network and the proxy

    In ~/.config/codeband/codeband.toml, add the network and the proxy to [sandbox.default]. Make the file if it does not exist, and keep its other tables:

    ~/.config/codeband/codeband.toml
    [sandbox.default]
    kind = "docker"
    image = "codeband-sandbox"
    [sandbox.default.docker]
    NetworkMode = "codeband-sandboxes"
    [sandbox.default.env]
    HTTPS_PROXY = { value = "http://codeband-proxy:8888" }
    HTTP_PROXY = { value = "http://codeband-proxy:8888" }

    NetworkMode puts each container on codeband-sandboxes only, where Docker resolves the name codeband-proxy. The variables reach the agent, its commands and every shell step, as the codeband.toml reference lists. Both addresses use http://, because a program talks plain HTTP to the proxy.

    When the steps need no network, NetworkMode = "none" is simpler and needs no proxy, but an agent step on Claude Code then cannot reach its model provider.

  5. Start the daemon again

    The daemon reads the sandbox definitions when it starts. Stop codeband dev with Ctrl-C if it runs, and start it in examples/py-factory:

    Terminal window
    just examples/py-factory/dev

    The daemon logs the config file that it read, then Listening:

    Output
    Nov 29 21:38:21.237 INF Read the config file comp=daemon path=…/.config/codeband/codeband.toml
    …
    Nov 29 21:38:21.697 INF Listening comp=daemon socket=…/codeband/daemon.sock
  6. Request a domain of the allow list

    In the first terminal, run curl in a shell step:

    Terminal window
    build/codeband run -v py-factory/run_program --input '{"argv": ["curl", "-sS", "-o", "/dev/null", "-w", "%{http_code}\\n", "https://pypi.org/simple/codeband-sdk/"]}'

    curl prints only the status code. PyPI answers 200, so codeband run exits with code 0. Your run ID is different:

    Output
    Started run ectj2pwmn6
    ▸ program#0 shell step: curl -sS -o /dev/null -w %{http_code}\n https://pypi.org/simple/codeband-sdk/
    200
    ✓ program#0 exit code 0 after 1.9s
    no code change
  7. Request another domain

    Terminal window
    build/codeband run py-factory/run_program --input '{"argv": ["curl", "-sS", "-o", "/dev/null", "-w", "%{http_code}\\n", "https://example.com/"]}'

    The proxy refuses the tunnel to example.com with 403, so curl prints 000 and exits with code 56, and codeband run exits with code 3:

    Output
    Started run n31k8bnhjz
    ▸ program#0 shell step: curl -sS -o /dev/null -w %{http_code}\n https://example.com/
    ✗ program#0 exit code 56 after 2.0s
    │ curl: (56) CONNECT tunnel failed, response 403
    │ 000
    stopped: the program exited with code 56:
    curl: (56) CONNECT tunnel failed, response 403
    000

    The proxy log names the refused domain:

    Terminal window
    docker logs codeband-proxy 2>&1 | grep refused
    Output
    NOTICE Nov 29 20:38:46.415 [1]: Proxying refused on filtered domain "example.com"

Check that an agent step on Claude Code reaches its model provider. Press Ctrl-C in the terminal of codeband dev and start it in examples/hello, whose pipeline hello runs such a step:

Terminal window
just examples/hello/dev

In the first terminal, run hello:

Terminal window
build/codeband run hello/hello --patch /tmp/hello.patch

codeband run prints the text of the agent and the path of the patch. Then read the connections of Claude Code in the proxy log:

Terminal window
docker logs codeband-proxy 2>&1 | grep api.anthropic.com
Output
CONNECT Nov 29 20:39:22.145 [1]: Request (file descriptor 5): CONNECT api.anthropic.com:443 HTTP/1.1
CONNECT Nov 29 20:39:22.145 [1]: Request (file descriptor 6): CONNECT api.anthropic.com:443 HTTP/1.1
CONNECT Nov 29 20:39:22.167 [1]: Established connection to host "api.anthropic.com" using file descriptor 7.
CONNECT Nov 29 20:39:22.168 [1]: Established connection to host "api.anthropic.com" using file descriptor 8.
…

Claude Code connected to no other domain in our runs. When an agent step fails, a refused line from the time of its attempt names the domain that the agent or a command needed.

The proxy reads its files when it starts, so add a line to allowed and restart it:

Terminal window
echo '^registry\.npmjs\.org$' >> ~/codeband-proxy/allowed
docker restart codeband-proxy

docker restart prints codeband-proxy. The daemon needs no restart. Start codeband dev in examples/py-factory again as in step 5, and request the new domain:

Terminal window
build/codeband run -v py-factory/run_program --input '{"argv": ["curl", "-sS", "-o", "/dev/null", "-w", "%{http_code}\\n", "https://registry.npmjs.org/"]}'

The shell step prints 200:

Output
Started run wx4nyxy6fa
▸ program#0 shell step: curl -sS -o /dev/null -w %{http_code}\n https://registry.npmjs.org/
200
✓ program#0 exit code 0 after 1.9s
no code change
Limit Detail
A program that ignores the proxy variables gets no connection curl --noproxy '*' https://pypi.org/simple/codeband-sdk/ prints curl: (6) Could not resolve host: pypi.org. curl reads only the lowercase http_proxy for an http:// address. Set the variable that it reads in [sandbox.default.env]
An allowed domain is a way out too The proxy checks only the domain. An agent can send your code to the model provider with another login. Allow only the domains that your steps need, and none where anyone can store data without your login, such as a paste site
The run journal records no refused request A refusal shows only in the proxy log, the output of a shell step and the agent transcript
Every definition on codeband-sandboxes gets the same list For a second list, make another network and proxy

Remove the proxy, its image, its network and its folder:

Terminal window
docker rm --force codeband-proxy
docker image rm codeband-proxy
docker network rm codeband-sandboxes
rm -rf ~/codeband-proxy /tmp/hello.patch

Delete the tables [sandbox.default.docker] and [sandbox.default.env] of step 4, or all of [sandbox.default] if you had none before: without it, default is of kind host. Then stop codeband dev with Ctrl-C.

codeband: start the sandbox: start container: Error response from daemon: network codeband-sandbox not found

Section titled “codeband: start the sandbox: start container: Error response from daemon: network codeband-sandbox not found”

NetworkMode names a network that Docker does not have, here with a typo, so the container does not start:

Output
✗ program#0 failed after 0.1s
│ codeband: start the sandbox: start container: Error response from daemon: network codeband-sandbox not found
stopped: the program did not run to its end:
codeband: start the sandbox: start container: Error response from daemon: network codeband-sandbox not found

Correct NetworkMode or make the network as in step 1, then start the daemon again.

curl: (5) Could not resolve proxy: codeband-proxy

Section titled “curl: (5) Could not resolve proxy: codeband-proxy”

The proxy does not run, and the docker ps command of step 3 prints only its header. Start it with docker start codeband-proxy.

curl: (56) CONNECT tunnel failed, response 500

Section titled “curl: (56) CONNECT tunnel failed, response 500”

The proxy is not on bridge, so it reaches no server, and the docker ps command of step 3 shows only codeband-sandboxes. Run docker network connect bridge codeband-proxy.

curl: (56) CONNECT tunnel failed, response 403 for a domain that you allowed

Section titled “curl: (56) CONNECT tunnel failed, response 403 for a domain that you allowed”

No line of allowed matches the whole domain: ^pypi\.org$ does not match www.pypi.org. The refused line in docker logs codeband-proxy names the domain. Add a line for it, as in Optional: Allow another domain.