Skip to content

User guide

This page tells you how to use the features of boxfork after the first session. Read the README first. It tells you what boxfork is, how to install it and how to create a first sandbox.

The CLI reference, the Python SDK reference and the HTTP API reference give each flag, call and field. This page tells you how the features work together and what to expect from them.

The start of a sandbox takes about a tenth of a second. A pool removes this time. For a pool, the daemon keeps a number of sandboxes of one kind started. These are the waiting sandboxes. When a client asks for a sandbox of that kind, the daemon hands out a waiting sandbox immediately. Then the daemon starts a replacement in the background.

Terminal window
boxfork pool --image python:3.12 --size 8 # prints a pool id
boxfork pools # READY shows 8/8 once they run
boxfork create --image python:3.12 # one of the eight, already running
boxfork rmpool <pool>
from boxfork import Pool, Sandbox
Pool.create("python:3.12", size=8).wait()
sbx = Sandbox.create("python:3.12") # already running

Nothing changes for a client that creates sandboxes. The client uses the same call and gets the sandbox sooner. Immediately before the daemon hands out a sandbox, it makes sure that the sandbox still runs.

We measured these times on the test machine (Docker with gVisor, 20 rounds for each measurement):

  • Without a pool, a create request took a median of 139 ms.

  • From a pool, a create request took a median of 1.5 ms.

  • The pool was full again 143 ms after a client took a sandbox from it.

  • What a pool serves. A pool serves a create request for the image or the snapshot of the pool. The request must also have the cpus, the memory_mb and the network setting of the pool. Write the image as the pool has it, because ubuntu and ubuntu:24.04 are two kinds. If you omit these values, the request and the pool get the defaults of the daemon. Thus boxfork pool --size 4 serves a plain boxfork create.

  • What a pool does not serve. The daemon starts these sandboxes in the usual way:

    • a sandbox with a GPU
    • a sandbox with environment variables
    • a sandbox with volumes of its own
    • each sandbox that a client creates while the pool is empty

    The daemon does not refuse a create request because the pool has no sandbox that the request can use. The daemon starts that sandbox as if there is no pool.

  • A pool of a snapshot. boxfork pool --snapshot <id> --size 8 keeps copies of a prepared environment ready. This is the fast way to give many identical environments to parallel runs. You cannot delete the snapshot while it has a pool.

  • The cost of a waiting sandbox. A waiting sandbox is a started container. It holds the memory that its idle processes use, not the memory limit that it got. We measured eight waiting ubuntu:24.04 sandboxes on the test machine under gVisor. Docker counted about 11 MiB for each sandbox. The used memory of the machine increased by about 27 MB for each sandbox.

    The list of sandboxes does not show waiting sandboxes, and waiting sandboxes do not expire. The timeout of a sandbox starts when the daemon hands out the sandbox.

  • The number of waiting sandboxes. Waiting sandboxes do not count against --max-sandboxes. The limit for waiting sandboxes is boxfork serve --max-pooled <n>. This is the maximum number of sandboxes that the host keeps ready in all its pools together. The default is 64. The daemon refuses a pool that goes above this limit, and --max-pooled 0 keeps no waiting sandboxes.

  • What does not change. The daemon started a waiting sandbox from its image as the image was at that time. After you pull a newer image with the same name, delete the pool and create it again. The things that the daemon itself gives to a sandbox are different. You can restart the daemon with a different build, isolation, --dns or --volume. Then the daemon replaces the waiting sandboxes and does not hand them out.

  • A waiting sandbox that died. The daemon asks the engine about a waiting sandbox at the moment when it hands out the sandbox. If something killed the container, or the container had no more memory, the daemon removes the sandbox and replaces it. The request gets a different waiting sandbox.

If you ask for a pool that exists, the daemon changes the size of that pool. Pools and their waiting sandboxes stay after a restart of the daemon. If the daemon cannot start a sandbox for a pool, boxfork pools shows the cause in its last column. The daemon tries again each half minute.

For the first command in a sandbox, the engine starts the helper in the sandbox. The daemon keeps the connection to the helper open. This is the kept connection. The daemon sends each subsequent command through the kept connection, and the helper starts the command. The engine does not start a new process for these commands.

We measured these median times on the test machine (Docker with gVisor, 30 rounds for each measurement):

  • The first command in a sandbox took 17 ms.
  • Each subsequent command took 4 ms.
  • Without the kept connection, each command took 13 ms.

Nothing changes for a client that runs commands. The client uses the same call and gets the same answer sooner.

The kept connection applies to commands that the daemon answers in one piece. These are run() in the Python SDK without on_stdout or on_stderr, sandbox_exec for an agent, and POST /v1/sandboxes/{id}/exec without stream. A command whose output the daemon streams still gets a connection of its own. boxfork exec in the CLI streams the output, so it does not use the kept connection. A file operation also gets a connection of its own.

  • The cost. While the kept connection is open, the helper holds about 15 MB of the memory of the sandbox.
  • When the daemon closes it. The daemon closes the kept connection a minute after the last command of the sandbox. Then an unused sandbox runs only its first process. boxfork serve --connection-idle <time> changes the minute. --connection-idle 0 gives each command a connection of its own, as before.
  • What a sandbox can do to it. The helper runs in the sandbox, so a process in the sandbox can kill the helper or stop it. If a process kills the helper, you lose the commands that ran at that time, and the next command opens a new connection. If a process stops the helper, the next command gets an error after ten seconds. The command after that opens a new connection. The daemon does not trust the data that the helper sends.

The files of a sandbox go when the sandbox goes. A volume is storage that stays. Create a volume, and mount it at a path in any sandbox. The data that a sandbox writes there stays for the next sandbox that mounts the volume.

Terminal window
boxfork mkvolume data
boxfork create --volume data:/data # read and write
boxfork create --volume data:/data:ro # read only
boxfork volumes # which exist, and who has them mounted
boxfork rmvolume data # refused while a sandbox has it mounted
from boxfork import Sandbox, Volume
data = Volume.create("data")
with Sandbox.create(volumes=[data.at("/data")]) as sbx:
sbx.run("echo kept > /data/note")
with Sandbox.create(volumes=["data:/data:ro"]) as sbx:
print(sbx.run("cat /data/note").stdout) # kept
  • Sandboxes that mount the same volume share it. The volume is one directory, not one copy for each sandbox. The copies that a fork makes mount the same volumes as the original sandbox, so the copies also share them.
  • A snapshot does not contain the data of a volume. The snapshot lists the mount paths as excluded_paths. A suspended sandbox gets its volumes back when it wakes.
  • A volume is a volume of the engine, and boxfork creates it. You cannot give a directory of the host to a sandbox in this way. Also, boxfork does not mount or delete a volume that it did not create.
  • The daemon makes the user that runs the commands of the sandbox the owner of a new volume. Thus an image that does not run as root can write to the volume. This occurs one time, while the volume is still empty. If one user fills a volume first, the volume belongs to that user. Then it is possible that a sandbox whose image runs as a different user cannot write there.
  • If something outside boxfork deleted the volume of a suspended sandbox, the sandbox cannot wake. The daemon refuses the calls of the sandbox with sandbox_stuck. This continues until a volume with that name exists again or you kill the sandbox.
  • A volume has no size limit of its own. The daemon does not delete a volume when you kill sandboxes. Delete the volume yourself when you do not need it.

serve --volume models:/models:ro mounts one volume read-only in each new sandbox. Thus you download the model weights one time for the machine, and not one time for each sandbox. To fill the model cache, create a sandbox that mounts the same volume at the same path without :ro. That sandbox can write to the volume.

Terminal window
# once: download into the shared volume
id=$(boxfork create --image python:3.12-slim --volume models:/models \
--env HF_HUB_CACHE=/models/hub)
boxfork exec $id -- pip install -q huggingface_hub
boxfork exec $id -- python3 -c \
"from huggingface_hub import snapshot_download as d; d('hf-internal-testing/tiny-random-bert')"
boxfork kill $id
# every sandbox after that: the model is there, read-only
id=$(boxfork create --image python:3.12-slim --env HF_HUB_CACHE=/models/hub)

Set HF_HUB_CACHE to the shared path. Then the library of Hugging Face finds a model that is in the cache and does not download it. With HF_HUB_OFFLINE=1 or --no-network, the library does this without the network. A read-only sandbox cannot add a model that is not in the cache: the download fails with “Read-only file system”. We ran this with huggingface_hub 2.6.0 on real containers. For a different library, set the variable of that library to the shared path.

A sandbox that you create with --gpu 1 (gpu=1 in the SDKs) gets a whole GPU for itself. A sandbox that you create without this option gets no GPU.

  • The check when the daemon attaches a GPU. The daemon asks each new GPU sandbox which GPUs it sees. If the answer is not the GPUs that the sandbox got, the daemon removes the sandbox and the create request fails. A sandbox that gave exactly its own GPUs shows gpu_verified.

    If nvidia-smi is not in the sandbox, the daemon counts the GPU device files of the sandbox as an alternative. With an incorrect number, the create request fails. With the correct number, the create request passes, but the sandbox is not verified.

    serve --gpu-check require accepts only verified sandboxes. With off, the daemon asks nothing. The answer comes from the sandbox. Thus the check protects against a defective GPU setup, but not against an image that somebody built to lie.

  • Health. When a GPU does not answer the nvidia-smi of the host, the daemon does not give that GPU to a sandbox. boxfork gpus shows that the GPU does not answer. If a sandbox failed the check above on a GPU, the daemon gives that GPU only when no other GPU is available. This continues until a sandbox sees that GPU again.

  • An idle sandbox releases its GPU, if you ask for this. create --suspend-after 10m suspends a sandbox that ran nothing for that time. serve --gpu-idle-suspend 15m does the same for each GPU sandbox. The daemon saves the files of the sandbox and removes its container. Then the GPU is free for other sandboxes.

    The next command, file operation, snapshot or fork wakes the sandbox with its files, on free GPUs that match its first request. Processes do not stay after a suspension. The daemon does not suspend a sandbox in which a process still runs. This function is off unless you ask for it.

    The daemon does not suspend these two kinds of sandbox:

    • A sandbox whose image keeps a directory in a volume of its own, because the suspension does not save that directory. Database images do this. The sandbox lists these directories as unsaved_paths.
    • A sandbox that the daemon already suspended about a hundred times, because the engine does not stack more saved layers.

    For the first kind, mount a volume of your own at that directory. Then the directory stays on the volume, and the daemon can suspend the sandbox.

Over MCP. boxfork mcp serves the sandbox tools on standard input and standard output. In Claude Code, use this command:

Terminal window
claude mcp add boxfork -- boxfork mcp

All other MCP clients use the same command. The agent gets a sandbox of its own on its first call.

  • When the agent disconnects, boxfork mcp removes the sandboxes that the agent started.
  • This does not occur with --keep, or when something kills the boxfork mcp process or stops the machine. Then each sandbox stays until its own timeout. A sandbox with timeout_seconds 0 has no timeout.
  • While the agent uses a sandbox that it started, the session moves the timeout of that sandbox later. A sandbox_exec command that still runs counts as use. A command in the background does not count.
  • The session does not change a timeout that the agent chose.
  • The agent can see, use and kill all sandboxes of the daemon, not only its own. One API key gives access to all sandboxes. Give an agent its own daemon when it must not touch the sandboxes of other agents or persons.

With any model that calls tools. The tools are plain JSON Schema. Thus they are compatible with these APIs:

  • OpenAI-compatible APIs (GLM, DeepSeek, local servers and others)
  • the API of Anthropic
  • the API of Gemini
from boxfork import Toolkit
with Toolkit() as kit:
reply = client.chat.completions.create(model=..., messages=messages,
tools=kit.tools("openai"))
for call in reply.choices[0].message.tool_calls or []:
messages.append(kit.run_tool_call(call).as_openai_message())

With a model that cannot call tools. kit.run_code_blocks(reply_text) runs the fenced code blocks in a reply. It returns the output of the blocks as text.

These are the nine tools:

  • sandbox_create
  • sandbox_exec
  • sandbox_read_file
  • sandbox_write_file
  • sandbox_snapshot
  • sandbox_fork
  • sandbox_list
  • sandbox_kill
  • gpu_list
  • The internet. A sandbox can reach the internet, unless you created it with the network off (--no-network).

  • Not the other sandboxes, on Docker. On Docker, a sandbox cannot reach the other sandboxes. Podman does not support this setting. boxfork info shows which of the two applies.

  • Not the metadata service of the cloud. On a cloud machine, this service is at 169.254.169.254. The service gives the start-up script of the machine to each program that asks. If the machine has a role or a service account, the service also gives credentials for it. The daemon keeps sandboxes away from the service with a rule in the firewall of the machine.

    For this rule, the daemon must run as root on the machine on which Docker runs. The installer sets up the daemon in this way. boxfork info shows if the rule is in position. With serve --block-metadata require, the daemon does not start where it cannot set the rule. With this option, the daemon also does not put a sandbox on the network where it cannot set the rule.

    The daemon cannot set the rule when it runs as a container or on Podman. install.md tells you what to do then.

    The rule applies to the traffic that the machine forwards to the cloud. A program that gives credentials can run on the machine itself and answer at such an address. The agent on an Amazon ECS instance is an example. Such a program is a service of the machine itself, and the last item of this list applies to it.

  • Names resolve. Under gVisor, a sandbox cannot reach the built-in name server of Docker. Thus the daemon gives each sandbox the name servers that Docker itself asks. serve --dns <address> gives different name servers.

  • The services of the machine itself. A sandbox can reach these services where they listen on more than 127.0.0.1. For a sandbox, the machine is one hop away. This includes the boxfork API when the daemon serves it to other machines. The API still asks for the API key.

  • A snapshot or a fork contains files, not processes that run. It also does not contain the data in memory (/dev/shm). It also does not contain a directory that the image keeps in a volume of its own. A snapshot lists these paths as excluded_paths.
  • Volumes have no size limit. A model that has the tools above cannot create or mount a volume. The person or the program that creates the sandbox sets up the volumes.
  • boxfork runs on one machine only, with one daemon for each engine.
  • You cannot run Docker in a sandbox.
  • The daemon has one API key. Each client of the daemon sees all sandboxes.