Skip to content

Tutorial: from the first sandbox to an LLM agent

This tutorial takes you from an empty machine to a model that runs its code in a boxfork sandbox. It is for a person who uses boxfork for the first time. A video of 84 seconds on boxfork.dev shows the same steps. Each output on this page comes from a real run on 5 December 2026. Two examples did not run with a live model yet. The page tells you which.

You do these parts in sequence:

  1. Start the daemon.
  2. Create a sandbox, run a command in it and copy a file into it.
  3. Save the sandbox as a snapshot and fork it.
  4. Do the same steps from Python.
  5. Give a sandbox to an LLM: through MCP, through tool calls or through plain text.
  6. Remove all that you made.

The time for all parts is approximately 20 minutes.

Item Version Reason
A container engine Docker on Linux, or Docker or Podman on a Mac The daemon starts each sandbox as a container.
gVisor (runsc) Any current release It isolates each sandbox. It runs only on Linux. Without it, a sandbox is a plain container.
Go 1.26 or later To build boxfork from the source.
Python 3.9 or later For Part 4 and Part 5.

Caution: Without gVisor, run only code that you trust. A plain container gives less isolation than gVisor.

On a Mac you can do this tutorial with Podman, but the sandboxes are plain containers. On a Linux machine, the installer sets up gVisor for you. install.md gives that procedure.

boxfork has one program that runs all the time: the daemon. The daemon owns all sandboxes on one machine. Each client talks to the daemon through the HTTP API, with the API key. The clients are the CLI, the Python SDK, the MCP server and your own code.

This diagram shows what occurs when a client creates a sandbox and runs a command in it:

sequenceDiagram
participant C as Client (CLI, SDK, MCP, model)
participant D as boxfork daemon
participant E as Engine (Docker + gVisor)
participant H as Helper in the sandbox
C->>D: POST /v1/sandboxes (image, CPU, GPU)
D->>E: create and start a container under gVisor
E-->>D: the container runs, the helper is process 1
D-->>C: sandbox id
C->>D: POST /v1/sandboxes/{id}/exec (command)
D->>E: start the helper in the container
E->>H: the helper runs the command
H-->>D: output and exit code
D-->>C: output and exit code

These facts are important:

  • The daemon puts a small helper program in each sandbox. The helper runs commands and moves files.
  • The daemon reaches the helper through the engine. It does not open a network connection into a sandbox. Thus a sandbox with no network works fully.
  • A snapshot is the saved files of a sandbox. The engine keeps a snapshot as an image.
  • A fork is a new sandbox from a snapshot. A fork has the files of the original, but not its processes.

architecture.md gives the full design.

  1. Get the source and build it:

    Terminal window
    git clone https://github.com/mvplab-ai/boxfork.git
    cd boxfork
    make build
  2. If you use Podman on a Mac, start the Podman machine and give its socket to the daemon:

    Terminal window
    podman machine start
    export DOCKER_HOST=unix://$(podman machine inspect --format '{{.ConnectionInfo.PodmanSocket.Path}}')
  3. Start the daemon:

    Terminal window
    ./bin/boxfork serve
  4. Read the output. On the first start, the daemon prints the API key one time. It also writes the API key to its data directory.

  5. Keep the daemon open. Open a second terminal for the subsequent steps.

The daemon listens on 127.0.0.1:7070. The CLI on the same machine finds the address and the API key itself. A client on a different machine needs BOXFORK_URL and BOXFORK_API_KEY.

  1. Create a sandbox from the image python:3.12:

    Terminal window
    $ ./bin/boxfork create --image python:3.12
    sbx_uulezsidjhktd4lb

    The command prints the ID of the sandbox. The first create of an image pulls the image, so it is slower.

  2. Put the ID in a variable, so that the subsequent steps are shorter:

    Terminal window
    ID=sbx_uulezsidjhktd4lb
  3. Run a command in the sandbox:

    Terminal window
    $ ./bin/boxfork exec $ID -- python3 -c 'print(6 * 7)'
    42
  4. Copy a file from your computer into the sandbox:

    Terminal window
    ./bin/boxfork cp ./data.csv $ID:/work/data.csv
  5. List the sandboxes:

    Terminal window
    $ ./bin/boxfork ls
    ID IMAGE STATE GPUS EXPIRES
    sbx_uulezsidjhktd4lb python:3.12 running - in 4m59s

A sandbox has a timeout. When the timeout ends, the daemon kills the sandbox. --timeout 30m gives a longer life. --timeout 0 gives a sandbox that does not expire.

A fork lets you prepare an environment one time and then copy it. For example, an agent can try three solutions from the same state.

  1. Save the files of the sandbox as a snapshot:

    Terminal window
    ./bin/boxfork snapshot $ID

    The command prints the ID of the snapshot.

  2. Create a new sandbox from the snapshot:

    Terminal window
    ./bin/boxfork create --snapshot <the snapshot ID>
  3. Or do the snapshot and the new sandboxes in one step. This command makes three copies:

    Terminal window
    $ ./bin/boxfork fork --count 3 $ID
    sbx_ww35nl5skarr6d2y
    sbx_eq3pjkqbrx3sysm5
    sbx_ba322nviqowim5x4
  4. Run a command in one copy. The copy has /work/data.csv from the original.

A change in one copy does not go to the other copies or to the original. The daemon removes the snapshot of a fork when it kills the last copy.

  1. Install the Python SDK from the repository:

    Terminal window
    pip install ./sdk/python
  2. Write this program. It creates a sandbox, runs a file, installs a package, and forks the sandbox three times:

    from boxfork import Sandbox
    with Sandbox.create("python:3.12-slim") as sbx:
    sbx.files.write("/work/hello.py", "import platform\nprint('hello from', platform.node())\n")
    print(sbx.run("python3 /work/hello.py").stdout, end="")
    sbx.run("pip install --quiet cowsay") # prepare the environment one time
    copies = sbx.fork(3) # three sandboxes with the same files
    for i, copy in enumerate(copies):
    out = copy.run(f"python3 -c \"import cowsay; print(cowsay.get_output_string('cow', 'copy {i}').splitlines()[1])\"")
    print(copy.id, out.stdout.strip())
    copy.kill()
  3. Run the program. This is the output of the real run:

    hello from 6d6b76802216
    sbx_d5xcyvpkpnruphdp | copy 0 |
    sbx_e67pokevqxm7ljjn | copy 1 |
    sbx_l2vjqo5iuciuyt5n | copy 2 |

The package cowsay was installed one time, in the original. Each copy has it. At the end of the with block, the SDK kills the original sandbox. reference/python-sdk.md gives each call of the SDK.

boxfork contains no model, and the daemon never calls a model. A model gets a sandbox in one of three ways:

The model or agent How it gets the sandbox What boxfork gives
An agent app that speaks MCP, for example Claude Code, Codex or Cursor The app starts boxfork mcp Nine tools over MCP
A model API with tool calls, for example GLM, DeepSeek, an OpenAI-compatible API, Claude or Gemini Your loop sends the tools, and runs each tool call that the model returns Toolkit.tools() and Toolkit.run_tool_call()
A model without tool calls The model writes code blocks in its text Toolkit.run_code_blocks()

The nine tools are sandbox_create, sandbox_exec, sandbox_read_file, sandbox_write_file, sandbox_snapshot, sandbox_fork, sandbox_list, sandbox_kill and gpu_list. reference/mcp-and-tools.md gives each tool and its fields.

  1. Add the MCP server to the agent app. In Claude Code, use this command:

    Terminal window
    claude mcp add boxfork -- boxfork mcp
  2. Give the agent a task, for example “Write a script that counts the primes below 100000, and run it.”

The agent gets a sandbox of its own on its first call. When the agent disconnects, boxfork mcp kills the sandboxes that the agent started. boxfork mcp --keep keeps them.

This loop works with each API that is compatible with the OpenAI Chat Completions API. The example uses GLM through OpenRouter. Change base_url and model for a different provider.

import os
from openai import OpenAI
from boxfork import Toolkit
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"])
messages = [{"role": "user", "content": "Count the primes below 100000 with a Python script. Run it."}]
with Toolkit(image="python:3.12-slim") as kit:
while True:
reply = client.chat.completions.create(model="z-ai/glm-5.4", messages=messages,
tools=kit.tools("openai"))
message = reply.choices[0].message
messages.append(message)
if not message.tool_calls:
print(message.content)
break
for call in message.tool_calls:
messages.append(kit.run_tool_call(call).as_openai_message())

The tool kit gives the same tools in other formats:

  • kit.tools("anthropic") for the Anthropic Messages API. Send each result back with as_anthropic_block().
  • kit.tools("gemini") for the Gemini API.
  • kit.tools("openai") for each OpenAI-compatible API, for example GLM and DeepSeek.

run_tool_call() reads the tool calls of all these APIs.

Note: We did not run this loop with the tools field of a live API yet. Issue #7 is that test. The next section gives the run that we did.

On 5 December 2026 the model z-ai/glm-5.4 did a task through OpenRouter. The tool kit ran each tool call on a daemon with Podman on a Mac.

The model got the nine tools as text in its prompt, not in the tools field. It sent each tool call as one JSON object, for example {"name": "sandbox_fork", "arguments": {"count": 2}}. The loop gave each object to run_tool_call() and sent the result back to the model.

This was the task:

In your sandbox, write /work/primes.py, which prints how many primes are below 100000. Run it. Then fork your sandbox into 2 copies. In the first copy run python3 /work/primes.py and in the second copy run python3 -c "print(sum(range(10)))". Then kill both copies and give a short final answer with the results.

These were the tool calls of the model and the results:

Step The model asked for The result
1 sandbox_write_file of /work/primes.py The tool kit started a sandbox for the session and wrote 89 bytes.
2 sandbox_exec: python3 /work/primes.py Exit code 0, output 9592
3 sandbox_fork with count 2 Two new sandboxes with the same files
4 sandbox_exec in the first copy: python3 /work/primes.py Exit code 0, output 9592
5 sandbox_exec in the second copy: python3 -c "print(sum(range(10)))" Exit code 0, output 45
6 sandbox_kill of the first copy The daemon removed it.
7 sandbox_kill of the second copy The daemon removed it.

The final answer of the model was correct: there are 9592 primes below 100000. A check on a different computer gave the same number. When the loop closed the tool kit, the session sandbox stopped too. No sandbox, snapshot or container stayed. The ten requests to the model cost USD 0.015.

On its first reply, the model sent two calls in a different format. After one message that gave the correct format again, each reply was correct. A model with the tools field does not have this problem, because the API gives the format.

Some models cannot call tools. Such a model writes code blocks in its answer. run_code_blocks() runs each Python, shell or JavaScript block in the sandbox of the tool kit, and returns the output as text.

from boxfork import Toolkit
with Toolkit(image="python:3.12-slim") as kit:
output = kit.run_code_blocks(model_reply_text) # None if the reply has no code block
# send output back to the model as the next message

On 5 December 2026, GLM 5.4 wrote one code block for the Fibonacci number F(30) and the SHA-256 digest of the text boxfork. run_code_blocks() ran it and returned this output:

[block 1, python]
exit code: 0
stdout:
832040
467755dfe2d9de1c82d0fb4f7b5a1fd1dbb0c48c698b5f5bb2b83129f00fcdcc

Both values are correct. A check on a different computer gave the same digest.

  1. Kill each sandbox that you created:

    Terminal window
    ./bin/boxfork kill $ID
  2. List the snapshots, and delete each snapshot that you do not need:

    Terminal window
    ./bin/boxfork snapshots
    ./bin/boxfork rmsnapshot <the snapshot ID>
  3. Stop the daemon with Ctrl+C in its terminal.

The daemon kills each sandbox when its timeout ends, so a sandbox that you forget does not stay.

  • The tool-call loop with the tools field of a live API did not run yet. The recorded run gave the tools as text in the prompt. Issue #7 is that test.
  • No live run used the MCP server with an agent app.
  • The runs on this page used Podman on macOS. The sandboxes were plain containers, not gVisor.
  • No run on this page used a GPU.

guide.md gives pools, volumes, GPUs and the network of a sandbox. troubleshooting.md gives solutions to problems.