Connection
The SDK auto-connects to the BoxRun server using this priority:- Unix socket at
~/.boxrun/boxrun.sock(if it exists) BOXRUN_HOST:BOXRUN_PORTenvironment variables- Fallback to
127.0.0.1:9090
BoxRunClient
create
| Parameter | Type | Default | Description |
|---|---|---|---|
image | str | (required) | Container image (or alias like "ubuntu") |
name | str | None | None | Human-readable name |
cpu | int | 2 | CPU cores |
memory_mb | int | 1024 | Memory in MB |
disk_size_gb | int | 8 | Disk size in GB |
network | bool | False | Enable networking |
workdir | str | "/root" | Working directory |
env | dict[str, str] | None | None | Environment variables |
volumes | list[dict] | None | None | Volume mounts |
{"host_path": "/src", "guest_path": "/root/src", "readonly": False}
run
get_box
list_boxes
"running", "stopped").
gc
older_than seconds. Returns the number of boxes removed.
BoxHandle
A handle to a specific box, obtained fromclient.create().
Properties
| Property | Type | Description |
|---|---|---|
id | str | Box ID |
name | str | None | Box name |
info | BoxInfo | Full box info (call refresh() to update) |
exec
exec_stream
upload
download
stop / start / remove
refresh
self.info.
Data types
BoxInfo
ExecInfo
ExecEvent
RunResult
Error handling
All SDK errors raiseBoxRunError(code, message).
| Error code | Description |
|---|---|
BOX_NOT_FOUND | Box does not exist |
BOX_NOT_RUNNING | Box is stopped |
BOX_ALREADY_RUNNING | Box is already running |
EXEC_NOT_FOUND | Execution does not exist |
EXEC_ALREADY_FINISHED | Execution already completed |
IMAGE_PULL_FAILED | Failed to pull container image |
NAME_ALREADY_EXISTS | A box with that name already exists |
RESOURCE_EXCEEDED | CPU or memory limit exceeded |
TIMEOUT | Operation timed out |
RUNTIME_ERROR | Internal runtime error |
CANCELED | Operation was canceled |
AI agent patterns
A typical agent workflow with BoxRun:- Create a box with the right image and resources
- Install dependencies via
exec - Upload code or data
- Run the task, streaming output for real-time feedback
- Download results
- Remove the box when done
client.run():

