async with) and explicit lifecycle management.
SimpleBox
Context manager for basic command execution with automatic cleanup.Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
image | str | Required | Container image to use |
memory_mib | int | System default | Memory limit in MiB |
cpus | int | System default | Number of CPU cores |
runtime | Boxlite | Global default | Runtime instance |
name | str | None | Optional unique name |
auto_remove | bool | True | Remove box when stopped |
**kwargs | Additional options: env, volumes, ports, working_dir |
Properties
| Property | Type | Description |
|---|---|---|
id | str | Box ID (raises if not started) |
Methods
| Method | Signature | Description |
|---|---|---|
start() | () -> Self | Explicitly start the box (async) |
exec() | (cmd, *args, env=None) -> ExecResult | Execute command and wait (async) |
info() | () -> BoxInfo | Get box metadata |
shutdown() | () -> None | Shutdown and release resources |
Example
CodeBox
Specialized box for Python code execution with package management.Constructor
Methods
| Method | Signature | Description |
|---|---|---|
run() | (code: str, timeout: int = None) -> str | Execute Python code (async) |
run_script() | (script_path: str) -> str | Execute Python script file (async) |
install_package() | (package: str) -> str | Install package with pip (async) |
install_packages() | (*packages: str) -> str | Install multiple packages (async) |
Example
BrowserBox
Box configured for browser automation with Chrome DevTools Protocol.BrowserBoxOptions
| Field | Type | Default | Description |
|---|---|---|---|
browser | str | "chromium" | Browser type: "chromium", "firefox", "webkit" |
memory | int | 2048 | Memory in MiB |
cpu | int | 2 | Number of CPU cores |
Browser CDP Ports
| Browser | Port |
|---|---|
| chromium | 9222 |
| firefox | 9223 |
| webkit | 9224 |
Methods
| Method | Signature | Description |
|---|---|---|
endpoint() | () -> str | Get CDP endpoint URL |
Example
ComputerBox
Box with full desktop environment and GUI automation capabilities.Constructor
Mouse Methods
| Method | Signature | Description |
|---|---|---|
mouse_move() | (x: int, y: int) -> None | Move cursor to coordinates (async) |
left_click() | () -> None | Left click at current position (async) |
right_click() | () -> None | Right click at current position (async) |
middle_click() | () -> None | Middle click at current position (async) |
double_click() | () -> None | Double left click (async) |
triple_click() | () -> None | Triple left click (async) |
left_click_drag() | (start_x, start_y, end_x, end_y) -> None | Drag from start to end (async) |
cursor_position() | () -> Tuple[int, int] | Get current cursor (x, y) (async) |
Keyboard Methods
| Method | Signature | Description |
|---|---|---|
type() | (text: str) -> None | Type text characters (async) |
key() | (text: str) -> None | Press key or key combination (async) |
Key Syntax Reference
Thekey() method uses xdotool key syntax:
| Key | Syntax |
|---|---|
| Enter | Return |
| Tab | Tab |
| Escape | Escape |
| Backspace | BackSpace |
| Delete | Delete |
| Arrow keys | Up, Down, Left, Right |
| Function keys | F1, F2, … F12 |
| Modifiers | ctrl, alt, shift, super |
| Combinations | ctrl+c, ctrl+shift+s, alt+Tab |
Display Methods
| Method | Signature | Description |
|---|---|---|
wait_until_ready() | (timeout: int = 60) -> None | Wait for desktop ready (async) |
screenshot() | () -> dict | Capture screen (async) |
scroll() | (x, y, direction, amount=3) -> None | Scroll at position (async) |
get_screen_size() | () -> Tuple[int, int] | Get screen dimensions (async) |
Screenshot Return Format
Scroll Directions
| Direction | Description |
|---|---|
"up" | Scroll up |
"down" | Scroll down |
"left" | Scroll left |
"right" | Scroll right |
Example
InteractiveBox
Box for interactive terminal sessions with PTY support.Constructor
| Parameter | Type | Default | Description |
|---|---|---|---|
image | str | Required | Container image |
shell | str | "/bin/sh" | Shell to run |
tty | bool | None | None | TTY mode (see below) |
memory_mib | int | System default | Memory limit in MiB |
cpus | int | System default | Number of CPU cores |
runtime | Boxlite | Global default | Runtime instance |
name | str | None | Optional unique name |
auto_remove | bool | True | Remove box when stopped |
**kwargs | Additional options: env, volumes, ports, working_dir |
TTY Mode
| Value | Behavior |
|---|---|
None | Auto-detect from sys.stdin.isatty() |
True | Force TTY mode with I/O forwarding |
False | No I/O forwarding (programmatic control) |
Methods
| Method | Signature | Description |
|---|---|---|
wait() | () -> None | Wait for shell to exit (async) |
Example
BoxOptions
Configuration options shared across all box types. See BoxOptions reference for the full specification.| Field | Type | Default | Description |
|---|---|---|---|
image | str | Required | OCI image URI (e.g., "python:slim", "alpine:latest") |
cpus | int | 1 | Number of CPU cores (1 to host CPU count) |
memory_mib | int | 512 | Memory limit in MiB (128-65536) |
disk_size_gb | int | None | None | Persistent disk size in GB (None = ephemeral) |
working_dir | str | "/root" | Working directory inside container |
env | List[Tuple[str, str]] | [] | Environment variables as (key, value) pairs |
volumes | List[Tuple[str, str, str]] | [] | Volume mounts as (host_path, guest_path, mode) |
ports | List[Tuple[int, int, str]] | [] | Port forwarding as (host_port, guest_port, protocol) |
auto_remove | bool | True | Auto cleanup when stopped |
detach | bool | False | Survive parent process exit |
BoxInfo
Metadata about a box, returned bybox.info() and runtime.list().
| Field | Type | Description |
|---|---|---|
id | str | Unique box identifier (ULID) |
name | str | None | Optional user-assigned name |
status | str | Current status: "running", "stopped", "created" |
created_at | datetime | Creation timestamp |
pid | int | None | Process ID (if running) |
image | str | OCI image used |
cpus | int | Allocated CPU cores |
memory_mib | int | Allocated memory in MiB |
BoxStateInfo
Detailed state information for a box.| Value | Description |
|---|---|
Created | Box created but not yet started |
Starting | Box is initializing |
Running | Box is running and ready |
Stopping | Box is shutting down |
Stopped | Box is stopped |
Failed | Box encountered an error |
See Also
- Python SDK Overview - Runtime management, installation, sync API
- Execution - Command execution, streaming I/O
- Errors & Metrics - Exception hierarchy, metrics classes