Use with any LLM
This page is for builders of agents and LLM apps who want the code of the model to run in a sandbox. boxfork has no model of its own and never calls one: your app keeps the model, and boxfork gives it a sandbox. Find the row for your model or app, then open its tab.
| Your model or app | How it gets a sandbox | What boxfork gives |
|---|---|---|
| An agent app that speaks MCP, for example Claude Code, Codex or Cursor | The app starts boxfork mcp |
Ten tools over MCP |
| A model API with tool calls: OpenAI-compatible APIs such as GLM and DeepSeek, Claude, Gemini | Your loop sends the tools, and runs each tool call | Toolkit.tools() and Toolkit.run_tool_call() |
| A model without tool calls | The model writes code blocks in its text | Toolkit.run_code_blocks() |
Add the MCP server to the agent app. In Claude Code, use this command:
claude mcp add boxfork -- boxfork mcpOther MCP clients use the same command, boxfork mcp.
The agent gets a sandbox of its own on its first call, so it needs no setup.
When the agent disconnects, boxfork mcp removes the sandboxes that the agent started, unless you start it with --keep.
Repeated episodes. To try a task many times from the same start, the agent calls sandbox_snapshot once and keeps the snapshot_id.
Before each try, it calls sandbox_reset with that ID:
{"snapshot_id": "snap_d7k2m5xq4w6zr3pa"}The sandbox gets the files of the snapshot back and keeps its ID, so the agent does not have to find a new sandbox.
The tools are plain JSON Schema, so your own loop can send them to the model and run each call that comes back. This loop works with each API that is compatible with the OpenAI Chat Completions API:
from boxfork import Toolkit
with Toolkit(image="python:3.12-slim") as kit: while True: reply = client.chat.completions.create(model=model, messages=messages, tools=kit.tools("openai")) message = reply.choices[0].message messages.append(message) if not message.tool_calls: break for call in message.tool_calls: messages.append(kit.run_tool_call(call).as_openai_message())kit.tools("anthropic")gives the tools for the Anthropic Messages API. Send each result back withas_anthropic_block().kit.tools("gemini")gives the tools for the Gemini API.run_tool_call()reads the tool calls of all these APIs.
Repeated episodes. Prepare the sandbox once, save it as a snapshot, and reset it before each episode.
The toolkit runs the tools for you with run_tool(), and its own sandbox keeps its ID through each reset:
with Toolkit(image="python:3.12-slim") as kit: kit.run_tool("sandbox_exec", {"command": "pip install -q numpy"}) start = kit.run_tool("sandbox_snapshot").data["snapshot_id"] for task in tasks: kit.run_tool("sandbox_reset", {"snapshot_id": start}) # the files of the start again # run the loop above with new messages for this taskIf your code holds a Sandbox object, call sandbox.reset(snapshot) instead. Reset shows that loop.
Some models cannot call tools, so they write code blocks in their answer.
run_code_blocks() runs each Python, shell or JavaScript block in the sandbox 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 messageRepeated episodes. The code blocks run in the sandbox of the toolkit, so the same reset applies. Save the start once, and reset to it before each episode:
with Toolkit(image="python:3.12-slim") as kit: start = kit.run_tool("sandbox_snapshot").data["snapshot_id"] for task in tasks: kit.run_tool("sandbox_reset", {"snapshot_id": start}) output = kit.run_code_blocks(ask_model(task)) # ask_model: your call to the modelThe ten tools
Section titled “The ten tools”| Tool | What it does |
|---|---|
sandbox_create |
Create a sandbox. |
sandbox_exec |
Run a command and return the output and the exit code. |
sandbox_read_file |
Read a file. |
sandbox_write_file |
Write a file. |
sandbox_snapshot |
Save the files of a sandbox. |
sandbox_fork |
Make copies of a sandbox. |
sandbox_reset |
Put a sandbox back to the files of a snapshot, under the same ID. |
sandbox_list |
List the sandboxes. |
sandbox_kill |
Remove a sandbox. |
gpu_list |
List the GPUs and who has them. |
The MCP and tools reference gives each field.
A recorded run with GLM 5.4
Section titled “A recorded run with GLM 5.4”On 5 December 2026, the model z-ai/glm-5.4 did a task through OpenRouter, on a daemon with Podman on a Mac.
It wrote /work/primes.py, ran it, forked its sandbox into 2 copies, ran a command in each copy, and killed both copies.
The answer was correct: there are 9592 primes below 100000. The ten requests cost USD 0.015.
The tutorial gives each tool call.
Rules for the sandboxes of an agent
Section titled “Rules for the sandboxes of an agent”Two rules decide how long a sandbox lives and what an agent can touch:
- A sandbox lives while the agent uses it. The session moves the timeout of a sandbox later at each use.
- One API key opens all sandboxes. So an agent can see and kill the sandboxes of other agents. When it must not touch them, give it a daemon of its own.