Skip to content

MCP server and tools reference

This page describes the MCP server boxfork mcp and the nine tools that it gives to an agent. It also describes the HTTP routes and the tool kit of the Python SDK. They give the same tools to a model that makes tool calls. The page is for a person who connects an agent or a model to boxfork, and for a contributor who changes this code.

Terms on this page:

Term Meaning
agent The program that starts boxfork mcp and sends MCP messages to it. In the MCP specification, this program is the client.
model The AI model that selects the tool calls.
session One run of boxfork mcp, or one Toolkit object of the Python SDK.
session sandbox The sandbox that a session creates for itself. The session uses it for each call that has no sandbox_id.
sandboxes of the session The session sandbox, and each sandbox and fork that the agent created through the session.
managed sandbox A sandbox of the session whose timeout the session controls.
idle time The value of --idle-timeout (MCP server) or idle_timeout (tool kit).

Source:

The tools have one definition, in internal/tools. The daemon does each tool call in its own process. The MCP server and the tool kit add the rules of a session. They contain no sandbox logic. The daemon contains no code for a model and calls no model. See decision 10 in decisions.md.

flowchart LR
AGENT["Agent"] -->|"MCP on stdin and stdout"| MCP["boxfork mcp: session rules"]
PROG["Your program with a model"] -->|"Python calls"| KIT["Toolkit: session rules"]
CODE["Your code"] -->|"HTTP, no session"| API
MCP -->|"POST /v1/tools/name"| API["Daemon: tools.Kit"]
KIT -->|"GET /v1/tools and POST /v1/tools/name"| API
API --> MGR["sandbox.Manager"]

The MCP server takes the list of tools from its own program, not from the daemon. Thus tools/list works also when the daemon does not run. The tool kit gets the list from GET /v1/tools of the daemon. architecture.md shows where these clients stand in the system.

boxfork mcp [flags]

The command reads MCP messages on its standard input and writes the answers on its standard output. It writes its log on the standard error output. The standard output has only protocol messages. The command calls the daemon through the HTTP API. It does not start a daemon.

Flag Default Meaning
--url <address> BOXFORK_URL, then http://127.0.0.1:7070 The address of the daemon.
--key <key> BOXFORK_API_KEY, then the key file of a local daemon The API key.
--image <image> The default image of the daemon The image of the session sandbox.
--gpu <n> 0 The number of GPUs of the session sandbox.
--idle-timeout <duration> 30m The time that a managed sandbox lives without use. The value must be more than zero.
--max-sandboxes <n> 16 The maximum number of sandboxes of the session at one time. 0 means no limit.
--keep off Do not kill the sandboxes of the session when the session ends.

Rules:

  • Put only flags after boxfork mcp. The command stops at the first argument that is not a flag. It ignores that argument and all arguments after it.
  • -h prints the flags and gives status 0. A flag error gives status 2.
  • An --idle-timeout of zero or less gives status 1.
  • If the command finds no API key, it stops with status 1 before it reads a message.
  • The command does not connect to the daemon when it starts. If the daemon does not answer, each tool call gives an error result. tools/list still works.
  • A wrong API key shows at the first tool call. The result text then starts with The boxfork daemon refused the call:.
Variable Meaning
BOXFORK_URL The address of the daemon when you do not give --url.
BOXFORK_API_KEY The API key when you do not give --key.
BOXFORK_DATA_DIR The data directory in which the command looks for the file api-key.
BOXFORK_PIN_CERT A certificate file in PEM format. The command then trusts an HTTPS daemon only if it gives exactly this certificate.

The command reads the file api-key only when the host in the address is localhost, 127.0.0.1 or ::1. The page cli.md gives the full sequence in which the command looks for the key.

The agent starts boxfork mcp as a child process. It sends the messages on the standard input of the process.

  1. Start the daemon. See install.md.
  2. Find the API key. A daemon that the installer set up keeps it in /var/lib/boxfork/api-key. A daemon that runs as your user keeps it in ~/.boxfork/api-key by default.

Caution: Do not put the API key in a file that other persons can read. A person with the key can see and kill all sandboxes of the daemon.

  1. If the daemon is on a different machine, put the key in BOXFORK_API_KEY.
  2. If boxfork mcp cannot read the key file of the daemon, put the key in BOXFORK_API_KEY.
  3. Add boxfork mcp to the configuration of the agent.
  4. Start the agent. Make sure that its list of tools has the nine tools of this page.

A daemon that the installer set up runs as root, and only root can read its key file. Thus an agent that runs as a different user needs step 4.

For Claude Code, this command does step 5:

Terminal window
claude mcp add boxfork -- boxfork mcp

Many agents read a JSON file with an object mcpServers. The name of the file and its exact form come from the agent. Read the documentation of your agent. This example gives a fixed image, a longer idle time and the key:

{
"mcpServers": {
"boxfork": {
"command": "boxfork",
"args": ["mcp", "--image", "python:3.12", "--idle-timeout", "1h"],
"env": {
"BOXFORK_URL": "http://127.0.0.1:7070",
"BOXFORK_API_KEY": "abx_<48 hexadecimal characters>"
}
}
}
}

You can do a check of the server without an agent:

Terminal window
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | boxfork mcp

The command writes one line with the list of tools. Then its input ends, and the command stops.

  • The agent sends one JSON-RPC 2.0 message on one line. A newline character ends the line.
  • The server writes each answer as one line on its standard output. The examples on this page use more lines to make them easy to read.
  • The server ignores an empty line.
  • The maximum length of one line is 9 MiB. The daemon accepts the arguments of a tool call up to 8 MiB. The other 1 MiB is for the envelope of the message. The server reads a longer line to its end and does not use it. Then it sends error -32600 with the id null and continues with the next line.
  • The server accepts a batch: a JSON array of messages on one line. It sends the answers of a batch together, as one array on one line, when the last answer is ready.
  • A batch that contains only notifications gets no answer. An empty batch gets error -32600.
  • The server sends no requests and no notifications to the agent. It ignores a message that has no method, for example an answer.

The server knows two eras of the protocol. From 2026-07-28, the protocol has no handshake, and each request gives its version. Before that version, the agent starts with initialize.

Version Era How the agent selects the version
2026-07-28 Without handshake The key io.modelcontextprotocol/protocolVersion in params._meta of each request.
2025-11-25 With handshake protocolVersion in the initialize request.
2025-06-18 With handshake The same.
2025-03-26 With handshake The same.
2024-11-05 With handshake The same.

Rules:

  • If initialize asks for one of the four older versions, the answer has that version.
  • If initialize asks for a different version, 2026-07-28 included, the answer has 2025-11-25. The same applies when initialize gives no version.
  • The server examines io.modelcontextprotocol/protocolVersion in each request other than initialize. If the value is not a string with one of the five versions, the answer is error -32022.
  • A request without this key gets no check. Thus an older agent continues without _meta after initialize.
{"error":{"code":-32022,"message":"Unsupported protocol version","data":{"requested":"1900-01-01","supported":["2026-07-28","2025-11-25","2025-06-18","2025-03-26","2024-11-05"]}},"id":1,"jsonrpc":"2.0"}
Method Answer
initialize protocolVersion, capabilities ({"tools": {}}), serverInfo and instructions.
ping An empty object, {}.
server/discover supportedVersions (the five versions), capabilities ({"tools": {}}), instructions, ttlMs (3600000) and cacheScope ("public").
tools/list tools, ttlMs (3600000) and cacheScope ("public"). The server ignores cursor and sends no nextCursor. The list is always complete.
tools/call content, an array with one item {"type": "text", "text": ...}, and isError.
notifications/cancelled No answer. The server cancels the tools/call with the id in requestId.
a different notification No answer. The server ignores it.
a different method Error -32601 with the message Method not found: and the name of the method.

A message without id, or with the id null, is a notification.

The answers to server/discover, tools/list and tools/call also have these two fields. Older agents ignore them.

Field Value
resultType "complete"
_meta {"io.modelcontextprotocol/serverInfo": <serverInfo>}

serverInfo is {"name": "boxfork", "title": "boxfork sandboxes", "version": <version>}. The version is the version of the boxfork program. A build without a version gives dev.

The instructions field has this text for the agent:

boxfork runs code in isolated Linux sandboxes on the user's own machine or server. sandbox_exec, sandbox_read_file, sandbox_write_file, sandbox_snapshot and sandbox_fork work with no sandbox_id: this session gets a sandbox of its own on first use. Files stay between calls; shell state such as cd or exported variables does not. Sandboxes started in this session are removed when it ends or after they go unused for a while, so save what matters outside them.

An example of a first tools/call in the protocol without handshake:

{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"sandbox_exec","arguments":{"command":"echo hello"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28"}}}
{
"id": 7,
"jsonrpc": "2.0",
"result": {
"_meta": {"io.modelcontextprotocol/serverInfo": {"name": "boxfork", "title": "boxfork sandboxes", "version": "0.1.0"}},
"content": [
{"type": "text", "text": "Sandbox sbx_k3v7q2mzj5xw4n6a was started for this session and is used whenever sandbox_id is left out.\n\nexit code: 0\nstdout:\nhello"}
],
"isError": false,
"resultType": "complete"
}
}
  • The server does each tools/call in a goroutine of its own. A long command does not stop the other calls.
  • The answers can come in a sequence that is different from the sequence of the requests.
  • Two calls that run at the same time must have different ids. A tools/call with the id of a call that still runs gets error -32600.
  • notifications/cancelled with a requestId stops that call. The daemon stops the command of the call. The server sends no answer to a cancelled call.
  • A cancelled call can create sandboxes. If the connection to the daemon closes before the answer, the daemon kills them.
  • If the answer came first, the session has the sandboxes in its list. It kills them at the end of the session.
Code Message Cause
-32700 the message is not valid JSON The line is not valid JSON.
-32600 a message must be a JSON object The line is JSON, but not an object and not an array. Also an item of a batch that is not an object.
-32600 method must be a string The value of method is not a string. The answer has the id of the message.
-32600 an empty batch asks for nothing The line is [].
-32600 a message was longer than the 9 MiB this server accepts and was not read The line is longer than 9 MiB.
-32600 a request with this id is still running A call with the same id runs.
-32601 Method not found: <method> The server does not know the method.
-32602 tools/call needs params with a tool name params is absent, is not an object, or has no name.
-32602 Unknown tool: <name> No tool has that name.
-32022 Unsupported protocol version The request gives a version that the server does not know.

An error in the arguments of a tool is not an error of the protocol. The answer is then a result with isError: true. Thus the model can read the reason and correct the call.

boxfork mcp and Toolkit apply the same rules. The Go code is in internal/mcp/session.go. The Python code is in sdk/python/src/boxfork/toolkit.py. This section uses the names of the MCP server. python-sdk.md gives the names of the tool kit.

  • The session creates no sandbox when it starts. initialize, tools/list, server/discover, sandbox_list and gpu_list create nothing.
  • Five tools accept a call without sandbox_id: sandbox_exec, sandbox_read_file, sandbox_write_file, sandbox_snapshot and sandbox_fork.
  • For these five tools, the session uses the session sandbox when sandbox_id is absent, null or "".
  • If there is no session sandbox yet, the session creates it first with sandbox_create.
  • Calls that start at the same time get the same session sandbox. The session creates only one.
  • A sandbox_id of a different JSON type, for example a number, stays in the call. The daemon refuses the call with invalid_request. The session creates nothing for it.

The session sandbox gets these arguments:

Argument Value
timeout_seconds The idle time.
image The value of --image. Absent when you do not give --image.
gpu The value of --gpu. Absent when --gpu is 0 or less.

When the session creates the session sandbox, the result text starts with this note and an empty line:

Sandbox sbx_k3v7q2mzj5xw4n6a was started for this session and is used whenever sandbox_id is left out.

If the daemon refuses the sandbox, the result is an error. Its text starts with A sandbox for this session could not be started. and then gives the reason. If the daemon does not answer, the result is an error with the text of the connection error.

The timeout of the session sandbox can end, or a person can kill it. If the daemon then answers sandbox_not_found, the session does these steps:

  1. It removes the old sandbox from its list.
  2. It creates a new session sandbox.
  3. It does the same call again in the new sandbox.
  4. It puts this note before the result text: The session's sandbox <old> no longer existed (it expired or was removed), so a new, empty one, <new>, was started. Files from before are gone.

The session does this only for the session sandbox. A sandbox that the agent gives in sandbox_id gets no replacement. The result is the error sandbox_not_found.

If the agent kills the session sandbox with sandbox_kill, the next call without sandbox_id creates a new session sandbox.

The session controls the timeout of these sandboxes, the managed sandboxes:

  • the session sandbox
  • each sandbox that the agent creates with sandbox_create without timeout_seconds
  • each fork that the agent makes with sandbox_fork without timeout_seconds

For sandbox_create and sandbox_fork without timeout_seconds, the session adds timeout_seconds with the idle time. A sandbox that the agent creates with timeout_seconds keeps that timeout. The session does not change it. That sandbox is still a sandbox of the session. It counts for the limit, and the session kills it at the end.

The session changes the timeout of a managed sandbox with POST /v1/sandboxes/{id}/timeout:

  • After each tool call that names the sandbox in sandbox_id, the new timeout is the idle time from now.
  • Before a sandbox_exec call in the sandbox, the new timeout is the idle time plus 1800 seconds. 1800 seconds is the longest time of a sandbox_exec call.
  • While a sandbox_exec call runs in the sandbox, each new timeout includes the 1800 seconds.
  • When no sandbox_exec call runs in the sandbox, the next timeout is the idle time again.

Thus a managed sandbox does not expire while a sandbox_exec call runs in it. The session does not change the timeout of a sandbox that it did not create. If the daemon refuses a new timeout, the session ignores the error. The session finds a sandbox that is gone at its next use.

A command with background: true returns at once. After the call, the background process does not count as use. If no tool call names a managed sandbox for the idle time, the daemon kills the sandbox and the background process.

The first call of a session, sandbox_exec without sandbox_id, makes these requests:

sequenceDiagram
participant A as Agent
participant M as boxfork mcp
participant D as Daemon
A->>M: tools/call sandbox_exec without sandbox_id
M->>D: POST /v1/tools/sandbox_create with timeout_seconds = idle time
D-->>M: result with created = [id]
M->>D: POST /v1/sandboxes/{id}/timeout with idle time + 1800 s
M->>D: POST /v1/tools/sandbox_exec with sandbox_id = id
D-->>M: result
M->>D: POST /v1/sandboxes/{id}/timeout with idle time
M-->>A: result text after the note about the new sandbox

The session counts two numbers: the sandboxes of the session that exist, and the sandboxes that calls under way can create. Before a call can create sandboxes, the session adds them to the count.

Call Count
A call that needs a new session sandbox 1
sandbox_create 1
sandbox_fork The value of count when it is an integer larger than 1. Else 1.

If the count goes above --max-sandboxes, the session sends nothing to the daemon. The result is an error with the code limit_reached and this text:

This session may have at most 16 sandboxes at once and has 16. Remove one with sandbox_kill first; sandbox_list shows them.

If calls under way can create sandboxes, the text also gives their number. If a call fails, the session gives back the count that it added for the call. A sandbox_kill of a sandbox of the session makes the count smaller. The limit applies only to this session. The daemon has its own limits for all sandboxes. See configuration.md.

The session ends in one of these cases:

  • The standard input of boxfork mcp ends. For example, the agent stops.
  • boxfork mcp gets the signal SIGINT, SIGTERM or SIGHUP.
  • A write to the standard output fails, because the agent does not read any more.

Then boxfork mcp does these steps:

  1. It reads no more messages.
  2. If the input ended, it gives the calls under way a maximum of 5 seconds. A call that finishes in this time sends its answer.
  3. It cancels the calls that still run. The daemon stops their commands.
  4. It kills all sandboxes of the session at the same time. The time limit for all kills is 30 seconds.
  5. For each sandbox that it cannot kill, it writes a warning to its log. That sandbox stays until its timeout ends.
  6. It stops.

In the two other cases, step 2 has no wait. With --keep, step 4 kills no sandbox. The command ignores the signal SIGPIPE. Thus a closed standard output does not stop the process before step 4.

The session does not kill these:

  • the snapshots that the agent made with sandbox_snapshot
  • the sandboxes that the session did not create
Tool Title read_only destructive session_sandbox longest_seconds
sandbox_create Create a sandbox no no no absent
sandbox_exec Run a command no yes yes 1800
sandbox_read_file Read a file yes no yes absent
sandbox_write_file Write a file no yes yes absent
sandbox_snapshot Snapshot a sandbox no no yes absent
sandbox_fork Fork a sandbox no no yes absent
sandbox_list List sandboxes yes no no absent
sandbox_kill Remove a sandbox no yes no absent
gpu_list List GPUs yes no no absent

The list always has this sequence. GET /v1/tools gives each tool with the fields name, title, description and input_schema, and the four fields of this table. tools/list gives each tool in the form of the protocol:

Field of tools/list Value
name name
title title
description description
inputSchema input_schema
annotations.title title
annotations.readOnlyHint read_only
annotations.destructiveHint destructive
annotations.openWorldHint true for sandbox_exec. false for the other tools.

Each input schema is a JSON Schema object with "type": "object", properties and "additionalProperties": false. A tool with required fields also has required. Each property has a type and a description for the model.

  • The arguments are a JSON object. Absent arguments and null are the same as {}.
  • In a session, arguments of a different JSON type give the error result Invalid arguments: they must be a JSON object. The session creates nothing for such a call.
  • Without a session, the daemon refuses such arguments with the code invalid_request.
  • A field that the tool does not know gives an error result, for example Invalid arguments: unknown field "comand".
  • The names of the fields are exact. Count is not the same as count.
  • A value of the wrong JSON type gives an error result. Its text starts with Invalid arguments:. For example, an integer field refuses 2.5.
  • A duration is a JSON number of seconds. A fraction is permitted.
  • The tool changes a positive duration smaller than 1 millisecond to 1 millisecond. It changes a duration larger than 100 years to 100 years.

The daemon gives a result with six fields: text, data, is_error, code, created and removed. http-api.md describes these fields.

  • text is for the model. It tells the result, or the reason of a failure and what to do.
  • data has the same result as values for a program. The section of each tool gives its fields.
  • is_error is true when the tool did not do the work.
  • A command that ends with an exit code other than 0 is not an error. The model reads the exit code in the text.
  • The session puts its notes before text, with an empty line between them.

The MCP server sends only two of these fields to the agent: text in content, and is_error as isError. The tool kit gives text, data, is_error and code to your program.

Code Cause
invalid_request An argument is wrong. The text gives the argument.
sandbox_not_found No sandbox has that identifier. Possibly its timeout ended, or a client killed it.
snapshot_not_found No snapshot has that identifier.
sandbox_paused The sandbox is paused. A client must resume it first.
limit_reached The daemon is at a limit, or the session is at --max-sandboxes.
gpu_unavailable The host cannot give the GPUs that the call asks for.
in_use The daemon cannot do the operation while a different object uses the object.
unsupported This host cannot do the operation.
not_found, permission_denied, is_directory, not_directory, invalid_argument, io_error A file operation failed in the sandbox.
timed_out The time limit of sandbox_exec killed the command.
failed A different failure. For example, the sandbox cannot start the command.
unreachable Session only: the daemon does not answer.
a code of the HTTP API Session only: the daemon refused the HTTP request, for example with unauthorized or too_large. The text starts with The boxfork daemon refused the call:.

The tool kit adds the codes unknown_tool and closed. It also gives invalid_request for arguments that are not valid JSON. See python-sdk.md.

sandbox_create, sandbox_fork and sandbox_list describe a sandbox in one line of text. The parts of the line have two spaces between them:

  1. The identifier of the sandbox.
  2. image and the image.
  3. The state: running, paused or suspended.
  4. If the sandbox has GPUs: the number, GPU and the name of the first GPU in parentheses.
  5. If the state is suspended: one space and the text while idle (its files are kept; the next command brings it back, without the processes it had).
  6. If the sandbox has a timeout: expires and the time in RFC 3339 format, in UTC.
sbx_k3v7q2mzj5xw4n6a image python:3.12 running expires 2026-12-05T10:48:00Z
Start a new isolated Linux machine to run code in. It has its own filesystem and processes, and is removed when its timeout runs out. Returns its sandbox_id. Use this when you need a specific image, a GPU, more memory, or a second sandbox; for ordinary work in a session, sandbox_exec starts one for you.
Field Type Required Default Rules
image string no The default image of the daemon The image to start from. Do not give it with snapshot.
snapshot string no none A snapshot_id from sandbox_snapshot. The new sandbox gets the files of the snapshot.
gpu integer no 0 The number of full GPUs. A negative value is an error. If not enough GPUs are free, the result is gpu_unavailable.
cpus number no The default of the daemon CPU cores. A fraction is permitted.
memory_mb integer no The default of the daemon Memory in MiB.
timeout_seconds number no In a session: the idle time. Without a session: the default timeout of the daemon. The life of the sandbox. 0 means no timeout, if the daemon permits it. A negative value, or a value above --max-timeout of the daemon, is an error.
network boolean no true false creates the sandbox without networking.

The result:

  • text: Created sandbox and the line of the sandbox.
  • data: the sandbox object. See http-api.md.
  • created: the identifier of the new sandbox.

Example arguments and result text:

{"image": "python:3.12", "memory_mb": 2048}
Created sandbox sbx_t2x7c4mq6va5k3zn image python:3.12 running expires 2026-12-05T10:48:00Z
Run a shell command in a sandbox and return its exit code, stdout and stderr. The command runs with sh -c, so pipes and && work. Each call is a new shell: a cd or an export does not carry over, so use cwd, or put the steps in one command. Very long output is cut in the middle and saved whole to a file in the sandbox, whose path is returned. For anything that runs longer than a couple of minutes (a server, a training run), set background to true and read its log later.
Field Type Required Default Rules
sandbox_id string Yes without a session. No in a session. The session sandbox The sandbox in which the command runs.
command string yes none The command line. The sandbox runs it with sh -c. It must not be empty or contain only white space.
cwd string no The default directory of the sandbox The directory must exist. If not, the result is failed.
timeout_seconds number no 120 Kill the command after this time. More than 0 and a maximum of 1800. The tool ignores it when background is true.
background boolean no false true starts the command and returns at once.

The tool has no field for environment variables and no field for the standard input of the command.

The result of a command without background:

  • The first line of text is exit code: and the exit code.
  • If the time limit killed the command, the first line is The command was killed after <time> without finishing. For long work, run it again with background set to true. The time has the Go format, for example 2m0s.
  • If a signal ended the command, the first line is The command was ended by signal and the name of the signal.
  • Then stdout: and the standard output, if it is not empty. Then stderr: and the standard error output, if it is not empty.
  • If both are empty, the text has (no output).
  • If the output was too long, the text gives the path of a file with all of the output. See Limits of output and sizes.
Field of data Meaning
sandbox_id The sandbox.
exit_code The exit code.
stdout The standard output, after the cut.
stderr The standard error output, after the cut.
timed_out true. Present only when the time limit killed the command.
signal The signal that ended the command. Present only in that case.
output_file The path of the file with all of the output. Present only when the tool cut the output.

When the command ran, is_error is true only if the time limit killed it. The code is then timed_out. If the sandbox cannot start the command, the result is failed with the text The command could not be started: and the reason.

Example arguments and result text:

{"command": "ls /etc | wc -l"}
exit code: 0
stdout:
94

With background: true, the tool starts the command with nohup and returns at once. The output goes to a log file /tmp/boxfork-bg-<12 hexadecimal characters>.log in the sandbox. The standard input of the command is /dev/null. The start has a time limit of 30 seconds.

Field of data Meaning
sandbox_id The sandbox.
pid The process identifier, as a string.
log_file The path of the log file.

Example arguments and result text:

{"command": "python3 -m http.server 8000", "background": true}
Started in the background with process id 57. Its output goes to /tmp/boxfork-bg-3f9a1c0d7e2b.log in the sandbox: read it with sandbox_exec, for example "tail -n 50 /tmp/boxfork-bg-3f9a1c0d7e2b.log". Check whether it still runs with "kill -0 57".

If the command cannot start, the result is failed with the text The command could not be started in the background: and the reason.

Read a file from a sandbox. Text is returned as it is; a file that is not text is returned base64-encoded. Only the first part of a large file is returned, with a note saying how much was left out.
Field Type Required Default Rules
sandbox_id string Yes without a session. No in a session. The session sandbox The sandbox.
path string yes none The absolute path of the file.
max_bytes integer no 262144 (256 KiB) The maximum number of bytes to read. From 1 to 4194304 (4 MiB). 0 gives the default.

The result:

  • If the bytes are valid UTF-8, text is the content of the file.
  • If not, text is <path> is not text. Its content, base64-encoded:, a newline and the content in base64.
  • If the file is larger than max_bytes, a note follows: [only the first <n> of <size> bytes are shown; read the rest with sandbox_exec, for example with tail -c or sed].
  • If the limit cuts a UTF-8 character, the tool does not return the incomplete character. Thus a text file stays text.
Field of data Meaning
sandbox_id The sandbox.
path The path.
size The size of the full file in bytes.
content The content: text, or base64.
encoding "base64". Present only for a file that is not text.
truncated true. Present only when the tool did not read the full file.

Example arguments and result text:

{"path": "/work/hello.py"}
print('hello')
Create or replace a file in a sandbox with the given text. Directories on the way are created. Prefer this to echo or a heredoc in sandbox_exec: nothing needs escaping.
Field Type Required Default Rules
sandbox_id string Yes without a session. No in a session. The session sandbox The sandbox.
path string yes none The absolute path of the file.
content string yes none The full content of the file. "" gives an empty file.
executable boolean no false true gives the file the mode 0755. Else the mode is 0644.

The tool replaces a file that exists. It creates the directories of the path that do not exist. The JSON text of all arguments has a maximum size of 8 MiB, the limit of POST /v1/tools/{name}.

The result:

  • text: Wrote <n> bytes to <path>.
  • data: sandbox_id, path and size, the number of bytes written.

Example arguments and result text:

{"path": "/work/hello.py", "content": "print('hello')\n"}
Wrote 15 bytes to /work/hello.py
Save a sandbox's files as they are now and return a snapshot_id. New sandboxes can be started from it with sandbox_create. Running processes are not saved, only files. Use it before a risky step, or to keep a prepared environment.
Field Type Required Default Rules
sandbox_id string Yes without a session. No in a session. The session sandbox The sandbox to save.

The result:

  • text: Saved the files of <sandbox> as snapshot <snapshot>. Start a sandbox from it with sandbox_create and snapshot set to that id. Running processes were not saved.
  • data: snapshot_id and sandbox_id.

A snapshot keeps files only. See decision 7 in decisions.md. No tool deletes a snapshot, and the session does not delete snapshots.

Example arguments and result text, in a session:

{}
Saved the files of sbx_k3v7q2mzj5xw4n6a as snapshot snap_p4c6w2yzr7mq3b5d. Start a sandbox from it with sandbox_create and snapshot set to that id. Running processes were not saved.
Make copies of a sandbox, each a new sandbox with the same files, to try several approaches side by side from one prepared state. The copies have the files but none of the running processes, and changes in one do not reach the others. Returns their sandbox_ids. A copy of a GPU sandbox needs a free GPU of its own unless gpu is set to 0.
Field Type Required Default Rules
sandbox_id string Yes without a session. No in a session. The session sandbox The sandbox to copy.
count integer no 1 The number of copies, from 1 to 64. 0 gives 1.
gpu integer no The number of GPUs of the original The GPUs of each copy. 0 gives copies without a GPU. A negative value is an error.
timeout_seconds number no In a session: the idle time. Without a session: the default timeout of the daemon. The life of each copy.

The result:

  • text: Made <n> copies of <sandbox>, each with its files and none of its processes: and the line of each copy.
  • data: sandbox_ids, the identifiers, and sandboxes, the sandbox objects.
  • created: the identifiers of the copies.

If the daemon cannot create all copies, it creates none. See http-api.md.

Example arguments and result text:

{"count": 2}
Made 2 copies of sbx_k3v7q2mzj5xw4n6a, each with its files and none of its processes:
sbx_a6r3n5wq2zk7m4xc image python:3.12 running expires 2026-12-05T10:50:00Z
sbx_w5z3k7nq2xm6c4ra image python:3.12 running expires 2026-12-05T10:50:00Z
List the sandboxes that exist on this host, with their image, state, GPUs and when they expire.

The tool has no fields. It lists all sandboxes of the daemon, the oldest first. The list also has the sandboxes that the session did not create. It does not show the waiting sandboxes of a pool.

The result:

  • text: the line of each sandbox, one on each line. With no sandbox, the text is There are no sandboxes.
  • data: sandboxes, an array of sandbox objects.

Example arguments and result text:

{}
sbx_k3v7q2mzj5xw4n6a image python:3.12 running expires 2026-12-05T10:48:00Z
sbx_a6r3n5wq2zk7m4xc image ubuntu:24.04 paused
Stop a sandbox and delete everything in it. Its GPUs are freed. This cannot be undone; take a snapshot first if the files matter.
Field Type Required Default Rules
sandbox_id string yes none The sandbox to kill. A session does not supply it.

The tool can kill each sandbox of the daemon, not only the sandboxes of the session. The daemon completes the kill also when the caller disconnects. The time limit of the kill is 1 minute.

The result:

  • text: Removed sandbox <id>.
  • data: sandbox_id.
  • removed: the identifier.

Example arguments and result text:

{"sandbox_id": "sbx_a6r3n5wq2zk7m4xc"}
Removed sandbox sbx_a6r3n5wq2zk7m4xc
List this host's GPUs: model, memory, and which are free or in use by which sandbox.

The tool has no fields.

The result:

  • text: one line for each GPU, GPU <index> <model> <memory> MiB <state>. On a host without GPUs, the text is This host has no GPUs.
  • data: gpus, an array of GPU objects. See http-api.md.
Text of the state Meaning
free No sandbox holds the GPU.
in use by <sandbox> That sandbox holds the GPU.
in use by another program A program that is not boxfork uses the GPU.
held by <sandbox>, but it has stopped answering That sandbox holds the GPU, and the driver does not list the GPU.
not answering; it cannot be used No sandbox holds the GPU, and the driver does not list it.
free, but the last sandbox given it could not use it; it is handed out only when no other GPU will do The last sandbox that got the GPU failed the GPU check.

Example arguments and result text:

{}
GPU 0 NVIDIA A100-SXM4-40GB 40960 MiB in use by sbx_k3v7q2mzj5xw4n6a
GPU 1 NVIDIA A100-SXM4-40GB 40960 MiB free
Limit Value Source
Bytes of one output stream of sandbox_exec in the result 12000 modelChars in tools.go
Bytes of one output stream that the daemon keeps for a tool call 2 MiB captureBytes in tools.go
Default time limit of sandbox_exec 120 seconds defaultExec
Maximum time limit of sandbox_exec 1800 seconds maxExec
Time limit to start a background command 30 seconds Kit.background
Default size of sandbox_read_file 256 KiB readBytes
Maximum size of sandbox_read_file 4 MiB maxReadBytes
Copies in one sandbox_fork 64 sandbox.MaxFork
One MCP message 9 MiB maxLine in server.go
Arguments of one call through the daemon 8 MiB maxJSONBody in internal/api/server.go
Wait for calls under way after the input ends 5 seconds grace in server.go
Time to kill the sandboxes at the end 30 seconds runMCP in cli.go

The tool examines the standard output and the standard error output separately.

  1. If a stream has more than 12000 bytes, the tool keeps a maximum of 6000 bytes of its start.
  2. It also keeps a maximum of 6000 bytes of its end.
  3. Between the two parts, it puts the line [... <n> characters left out here ...]. The number <n> counts bytes.
  4. The tool does not cut a UTF-8 character.
  5. The tool writes all of the output that the daemon kept to the file /tmp/boxfork-output-<12 hexadecimal characters>.txt in the sandbox.
  6. The file has the line ==== stdout ====, the standard output, the line ==== stderr ==== and the standard error output.
  7. The text tells the model the path. The model can read parts of the file with sandbox_exec, for example with grep, head or tail.

If the tool cannot write the file, the text has this sentence: The output was too long to show whole, and the rest could not be saved.. If a stream is larger than 2 MiB, the daemon does not keep the rest. The text then has this sentence: Output beyond 2 MiB per stream was not kept at all..

The tool does not stream the output. The result comes when the command ends. For a long command, use background: true and read the log file.

Two routes of the daemon give the tools without a session. http-api.md describes them.

  • GET /v1/tools lists the tools as plain JSON Schema, with the fields in List of the tools.
  • POST /v1/tools/{name} does one call. The request body is the arguments. The answer is the result.
  • A call that fails also gets status 200, with is_error set. An unknown tool gets status 404 and the code unknown_tool.

These routes do not apply the session rules:

  • A tool that works in a sandbox needs sandbox_id in the arguments. Without it, the result is invalid_request.
  • A new sandbox gets the default timeout of the daemon, unless the call gives timeout_seconds.
  • The daemon does not change timeouts after a call and does not kill sandboxes at an end.

Use these routes when you write your own loop and your own session rules.

A Toolkit is one session with the rules of this page. python-sdk.md gives the full reference.

Parameter of Toolkit Flag of boxfork mcp Default
url --url BOXFORK_URL, then http://127.0.0.1:7070
api_key --key BOXFORK_API_KEY, then the key file of a local daemon
image --image The default image of the daemon
gpu --gpu 0
idle_timeout --idle-timeout 1800, in seconds
max_sandboxes --max-sandboxes 16
keep --keep False

The methods:

  • kit.tools(format) gives the definitions in the form that a model API expects. The formats are "openai" (the default), "openai-responses", "anthropic", "gemini" and "raw".
  • kit.run_tool_call(call) does a tool call in the form that a model API returns. It accepts an object or a dictionary.
  • kit.run_tool(name, arguments) does a tool call by name. arguments is a dictionary or JSON text.
  • Both methods return a ToolResult with text, data, is_error, code and call_id.
  • result.as_openai_message() and result.as_anthropic_block() give the message that goes back to the model.
  • kit.close() kills the sandboxes of the tool kit. The end of a with block calls it.

How the tool kit reports errors:

  • run_tool and run_tool_call do not raise an exception for a call that fails. The result has is_error set and a code. Send text to the model.
  • This is also true when the daemon refuses the call or does not answer.
  • tools() raises BoxforkError for an unknown format. It also raises an exception of the SDK when it cannot get the definitions from the daemon.
  • close() raises BoxforkError when it cannot kill a sandbox.
  • After close(), each call returns a result with the code closed.

Differences between the two sessions:

Item boxfork mcp Toolkit
Source of the tool definitions Its own program GET /v1/tools of the daemon
What the caller gets text and isError text, data, is_error, code and call_id
An unknown tool Error -32602 of the protocol A result with the code unknown_tool. The tool kit sends nothing to the daemon.
End of the session The input ends, a signal, or a failed write close(), or the end of a with block

This example does one tool call in the form of the Messages API. It does not call a model. python-sdk.md has a loop with a client of the Chat Completions API.

from boxfork import Toolkit
with Toolkit(image="python:3.12", idle_timeout=600) as kit:
definitions = kit.tools("anthropic") # give these to the model API
# A tool call in the form in which the Messages API returns it.
call = {"type": "tool_use", "id": "toolu_01", "name": "sandbox_exec",
"input": {"command": "python3 -c 'print(6 * 7)'"}}
result = kit.run_tool_call(call)
block = result.as_anthropic_block() # send this back to the model
print(result.text)
# A wrong argument does not raise. The model reads the reason.
bad = kit.run_tool("sandbox_exec", {"comand": "ls"})
print(bad.is_error, bad.code) # True invalid_request
print(bad.text) # Invalid arguments: unknown field "comand"

The first print writes this text:

Sandbox sbx_k3v7q2mzj5xw4n6a was started for this session and is used whenever sandbox_id is left out.
exit code: 0
stdout:
42
  • The session does not keep the agent in its own sandboxes. sandbox_list shows all sandboxes of the daemon.
  • The agent can run a command in each sandbox whose identifier it knows, and sandbox_kill can kill each sandbox. The daemon has one API key. See decision 9 in decisions.md.
  • The tools cannot create or mount a volume, pause or resume a sandbox, create or change a pool, or delete a snapshot.
  • The snapshots that an agent makes stay after the session. A person must delete them, for example with boxfork rmsnapshot.
  • The MCP server sends only text to the agent. It does not send data or code.
  • The MCP server gives the tools of its own program, and the daemon does the calls. Use the same version of boxfork for both.
  • If boxfork mcp gets SIGKILL, or the machine stops, the session cannot kill its sandboxes. They stay until their timeouts end.
  • A sandbox that the agent created with timeout_seconds: 0 has no timeout. If the session cannot kill it, it stays until a person kills it.
  • If --max-timeout of the daemon is smaller than the idle time, the daemon refuses the session sandbox. Then each call without sandbox_id fails.
  • In that case, the daemon also refuses each sandbox_create and sandbox_fork of the session without timeout_seconds.
  • If --max-timeout is smaller than the idle time plus 1800 seconds, the daemon refuses the longer timeout during a sandbox_exec call. The session ignores the refusal.
  • In that case, a command that runs longer than the idle time can lose its sandbox.
  • Nobody ran the tools with a live model yet. The tests send tool calls that a person wrote. See issue #7.
  • No test in the repository starts a real agent program. The tests of the MCP server use a stand-in agent, written in Go.
  • The tests of the MCP server and of the tool kit use the test engine. Their commands run as processes of the test machine. No proof script runs boxfork mcp or the tool kit against a real engine.
  • The GPU fields of the tools ran only against stand-ins, not against a real GPU.
  • The examples on this page show the correct field names and texts. A person wrote the values in them by hand.