Repository navigation
docker sandbox
The sandboxed code runs in a micro-VM of Docker Sandboxes (sbx): its own
guest kernel, a template as the root. The VM boundary is the isolation; nothing of the host is in the guest unless a
rule exposes it. The provider is Linux only.
python-sb and the daemon start a launcher (docker_sandbox_launcher.py) that follows a plan the provider computed:
-
sbx create shellwith the template, the mounts, the published port and the CPU and memory limits. -
sbx policy allow|deny network --sandbox <name>for each translatednet=rule, thensbx policy checkof every allowed destination and of a canary name no profile allows. Any mismatch removes the sandbox and stops the start. - One
sbx exec -u rootthat checks the Python version, masks whatignore=names, creates the usersandbox(uid and gid 2000) and runs the payload throughsetprivwith no capability andno_new_privs, underenv -i. - A second
sbx execheld open as a reaper: if the launcher dies, it kills the payload. The launcher removes the sandbox when the run ends.
-
Guest template:
pysandboxes-guest:<python minor>, built bymake build-image-docker-sandbox. It holds the interpreter (installed withuv python install) and the dependencies of pysandboxes, nosudo, and a/etc/ssl/cert.pemso the interpreter finds the certificates. The package of the host is mounted read-only at its host path (or at/opt/pysb/pysandboxeswhen that path lies in a directory the image owns), so what runs is the code of the host. The guest must run the Python minor of the host: another one stops with exit 72. -
Files:
expose-rois a read-only mount enforced by the host side,expose-rwa read-write mount at the same path. The first read-write directory is the primary workspace of the sandbox; without one, a private empty directory of the run. A directory the image owns (/usr,/etc, ...) and a path that does not exist are not mounted.ignore=hides files withmount(2)from the root step, before the privileges are dropped: the payload cannot undo it. -
Channel: the HTTP and SSE port chosen by the daemon is published by
sbx(-p 127.0.0.1:port:port, loopback only) and the guest listens on0.0.0.0.remote-endpoint=unixis an error,autouses TCP. The config goes from the host FIFO to the standard input of the payload, never to a disk. -
Environment: the payload runs under
env -iwith the variables the rules grant. Its home is the one of thesandboxentry of/etc/passwd, soos.path.expanduserandgetpass.getuserwork.
-
sbx0.51.0 or later, signed in (sbx login), its daemon running, a network policy preset (sbx policy init deny-all).unavailable_reason()checks them without prompting. - KVM for the micro-VM, as
sbxneeds. - The guest template:
make build-image-docker-sandbox.
os-sandbox=docker-sandbox
docker-sandbox.cpus=2
docker-sandbox.mem=2g
docker-sandbox.template=pysandboxes-guest:3.15
docker-sandbox.python=/usr/local/bin/python
docker-sandbox.proxy=false
| Key | Default | Meaning |
|---|---|---|
template |
pysandboxes-guest:<python minor>, or PYSANDBOXES_DOCKER_SANDBOX_TEMPLATE
|
OCI reference of the guest template |
python |
/usr/local/bin/python |
Interpreter of the template |
cpus, mem
|
those of sbx
|
Limits of the micro-VM |
proxy |
false |
Go through the HTTP proxy of the sandbox (gateway.docker.internal:3128, CONNECT for HTTPS) |
With proxy=true the payload keeps HTTP_PROXY, HTTPS_PROXY, NO_PROXY and the certificate variables of the sandbox,
and the Python guard gets an implicit rule for the proxy address. sbx then replaces the placeholder of a stored secret
(sbx secret) with its value in the request headers, so the code can use a key it never holds. Traffic that goes
through the proxy is decrypted with the Docker Sandboxes Proxy CA, which the guest trusts. With proxy=false, which
is closer to the other providers, no variable is passed and no secret is injected. Code that sets the proxy itself can
still use it in both modes.
| Rule | Result |
|---|---|
net=ALLOW|TCP|host|port|OUT |
sbx policy allow network: host:port; an address that has a pinned name is opened under both |
net=DENY|... |
sbx policy deny network (a deny wins over an allow) |
| any host, with or without a port |
**:port, or **
|
a runtime name rule (net-resolve=runtime) |
name and **.name, =name for the name alone, *.name as **.name
|
| UDP, ports beyond 64 per rule | not translated, reported |
| incoming rules, DNS | not translated; DNS goes through the resolver of sbx
|
-
The network drops, it does not refuse.
sbxaccepts every handshake and drops what no rule allows: the connection succeeds, then the first read ends at once; a name without a rule fails at DNS. A destination counts as reached only when the server answers. IP and CIDR rules only apply to connections that name no host. -
Name based. A TLS or HTTP connection is judged by its SNI or
Host, so a name rule is stricter than the profile's address rule. TheHostheader inside an undecrypted stream is not checked. -
UDP stays closed, and ICMP is blocked, unless the settings of
sbxenable UDP egress. - A Docker account and daemon are prerequisites. The provider does not run in a pod. In a container it needs the conditions of In a container.
-
Every start reads the manifest of the
shellkit from Docker Hub, even with a local template (sbx createprintsresolving docker.io/sbx/shell:latest). The pull limit of the Docker account then applies: a few hundred starts in hours end with429 toomanyrequests, and the launcher stops with exit code 70 and the message ofsbx. A test run of the integration suite is about 60 starts. -
Start-up costs about 3.3 s per sandbox, and a second
sbx execper run for the reaper. -
Credentials: see the
proxyoption; the injected headers are the only ones changed, not the query or the body. - Another sandbox with a denied name that shares an address with an allowed one can still be reached in the cases Docker lists.
make build-image-docker-sandbox
PYSANDBOXES_FAIL_ON_SKIP=1 uv run pytest -rs tests/integration_tests/remote/test_docker_sandbox.py \
tests/integration_tests/test_usage_with_providers.py tests/integration_tests/test_guards_with_providers.py \
-k docker-sandboxprovider_skip_reason() skips the rows when the template is missing. Hosted CI runners are not covered: run these
suites locally before a release, as for smolvm.
tests/containers_tests/test_containers.py::test_container_docker_sandbox runs the provider in a Docker container:
the sbx daemon, the login, the guest template, then tst_usage with and without --py-sandbox. Each condition below
comes from a measured failure of sbx:
-
--privilegedand/dev/kvm. The micro-VM needs the device, and the daemon mounts its image layers. -
Loop device nodes. A container has no udev:
scripts/container_docker_sandbox.shcreates/dev/loop0..255before the daemon starts, orsbx createfails withcould not open loop device. -
The glibc of the host.
/usr/bin/sbxand/usr/libexecare mounted read-only from the host and need its glibc (2.43 on Ubuntu 26.04), soDockerfile-docker-sandboxstarts fromubuntu:26.04, not frompython:*-slim. -
ca-certificatesin the image, orsbx loginfails without a message. -
A Docker account.
DOCKER_USERandDOCKER_PAT(an access token, not the password) come from the environment of the test; the script reads the token on stdin only. With no keychain,sbxstores the secret on disk in the container, which is removed with it. Use a dedicated token and revoke it afterwards.
make build-container-image-docker-sandbox
DOCKER_USER=<account> DOCKER_PAT=<token> uv run pytest -rs tests/containers_tests/test_containers.py -k docker_sandboxThe test is skipped without DOCKER_USER, DOCKER_PAT, /usr/bin/sbx or /dev/kvm. The template is built in every
run (a few minutes): the state of sbx lives in the container.
PySandboxes | Home | Source code | Security policy | Known weaknesses
Copyright (c) 2026, Philippe PRADOS. Licensed under Apache V2. A sandbox reduces risk, it does not remove it: read the known weaknesses before running untrusted code.