Skip to main content
BoxLite provides several specialized box types, each designed for specific use cases. All box types support both async context managers (async with) and explicit lifecycle management.

SimpleBox

Context manager for basic command execution with automatic cleanup.
from boxlite import SimpleBox

Constructor

SimpleBox(
    image: str,
    memory_mib: int = None,
    cpus: int = None,
    runtime: Boxlite = None,
    name: str = None,
    auto_remove: bool = True,
    **kwargs
)
ParameterTypeDefaultDescription
imagestrRequiredContainer image to use
memory_mibintSystem defaultMemory limit in MiB
cpusintSystem defaultNumber of CPU cores
runtimeBoxliteGlobal defaultRuntime instance
namestrNoneOptional unique name
auto_removeboolTrueRemove box when stopped
**kwargsAdditional options: env, volumes, ports, working_dir

Properties

PropertyTypeDescription
idstrBox ID (raises if not started)

Methods

MethodSignatureDescription
start()() -> SelfExplicitly start the box (async)
exec()(cmd, *args, env=None) -> ExecResultExecute command and wait (async)
info()() -> BoxInfoGet box metadata
shutdown()() -> NoneShutdown and release resources

Example

async with SimpleBox(image="python:slim") as box:
    result = await box.exec("python", "-c", "print('Hello!')")
    print(result.stdout)   # "Hello!\n"
    print(result.exit_code)  # 0

CodeBox

Specialized box for Python code execution with package management.
from boxlite import CodeBox

Constructor

CodeBox(
    image: str = "python:slim",
    memory_mib: int = None,
    cpus: int = None,
    runtime: Boxlite = None,
    **kwargs
)

Methods

MethodSignatureDescription
run()(code: str, timeout: int = None) -> strExecute Python code (async)
run_script()(script_path: str) -> strExecute Python script file (async)
install_package()(package: str) -> strInstall package with pip (async)
install_packages()(*packages: str) -> strInstall multiple packages (async)

Example

async with CodeBox() as cb:
    # Install packages
    await cb.install_package("requests")

    # Run code
    result = await cb.run("""
import requests
print(requests.get('https://api.github.com/zen').text)
""")
    print(result)

BrowserBox

Box configured for browser automation with Chrome DevTools Protocol.
from boxlite import BrowserBox, BrowserBoxOptions

BrowserBoxOptions

FieldTypeDefaultDescription
browserstr"chromium"Browser type: "chromium", "firefox", "webkit"
memoryint2048Memory in MiB
cpuint2Number of CPU cores

Browser CDP Ports

BrowserPort
chromium9222
firefox9223
webkit9224

Methods

MethodSignatureDescription
endpoint()() -> strGet CDP endpoint URL

Example

from boxlite import BrowserBox, BrowserBoxOptions

opts = BrowserBoxOptions(browser="chromium", memory=4096)
async with BrowserBox(opts) as browser:
    endpoint = browser.endpoint()  # "http://localhost:9222"

    # Connect with Puppeteer or Playwright
    # puppeteer.connect({ browserURL: endpoint })

ComputerBox

Box with full desktop environment and GUI automation capabilities.
from boxlite import ComputerBox

Constructor

ComputerBox(
    cpu: int = 2,
    memory: int = 2048,
    gui_http_port: int = 3000,
    gui_https_port: int = 3001,
    runtime: Boxlite = None,
    **kwargs
)

Mouse Methods

MethodSignatureDescription
mouse_move()(x: int, y: int) -> NoneMove cursor to coordinates (async)
left_click()() -> NoneLeft click at current position (async)
right_click()() -> NoneRight click at current position (async)
middle_click()() -> NoneMiddle click at current position (async)
double_click()() -> NoneDouble left click (async)
triple_click()() -> NoneTriple left click (async)
left_click_drag()(start_x, start_y, end_x, end_y) -> NoneDrag from start to end (async)
cursor_position()() -> Tuple[int, int]Get current cursor (x, y) (async)

Keyboard Methods

MethodSignatureDescription
type()(text: str) -> NoneType text characters (async)
key()(text: str) -> NonePress key or key combination (async)

Key Syntax Reference

The key() method uses xdotool key syntax:
KeySyntax
EnterReturn
TabTab
EscapeEscape
BackspaceBackSpace
DeleteDelete
Arrow keysUp, Down, Left, Right
Function keysF1, F2, … F12
Modifiersctrl, alt, shift, super
Combinationsctrl+c, ctrl+shift+s, alt+Tab
Examples:
await computer.key("Return")        # Press Enter
await computer.key("ctrl+c")        # Copy
await computer.key("ctrl+shift+s")  # Save As
await computer.key("alt+Tab")       # Switch window
await computer.key("ctrl+a Delete") # Select all and delete

Display Methods

MethodSignatureDescription
wait_until_ready()(timeout: int = 60) -> NoneWait for desktop ready (async)
screenshot()() -> dictCapture screen (async)
scroll()(x, y, direction, amount=3) -> NoneScroll at position (async)
get_screen_size()() -> Tuple[int, int]Get screen dimensions (async)

Screenshot Return Format

{
    "data": str,    # Base64-encoded PNG
    "width": int,   # 1024 (default)
    "height": int,  # 768 (default)
    "format": str   # "png"
}

Scroll Directions

DirectionDescription
"up"Scroll up
"down"Scroll down
"left"Scroll left
"right"Scroll right

Example

async with ComputerBox() as desktop:
    await desktop.wait_until_ready()

    # Take screenshot
    screenshot = await desktop.screenshot()

    # Mouse interaction
    await desktop.mouse_move(100, 200)
    await desktop.left_click()

    # Type text
    await desktop.type("Hello, World!")
    await desktop.key("Return")

    # Get screen size
    width, height = await desktop.get_screen_size()

InteractiveBox

Box for interactive terminal sessions with PTY support.
from boxlite import InteractiveBox

Constructor

InteractiveBox(
    image: str,
    shell: str = "/bin/sh",
    tty: bool = None,
    memory_mib: int = None,
    cpus: int = None,
    runtime: Boxlite = None,
    name: str = None,
    auto_remove: bool = True,
    **kwargs
)
ParameterTypeDefaultDescription
imagestrRequiredContainer image
shellstr"/bin/sh"Shell to run
ttybool | NoneNoneTTY mode (see below)
memory_mibintSystem defaultMemory limit in MiB
cpusintSystem defaultNumber of CPU cores
runtimeBoxliteGlobal defaultRuntime instance
namestrNoneOptional unique name
auto_removeboolTrueRemove box when stopped
**kwargsAdditional options: env, volumes, ports, working_dir

TTY Mode

ValueBehavior
NoneAuto-detect from sys.stdin.isatty()
TrueForce TTY mode with I/O forwarding
FalseNo I/O forwarding (programmatic control)

Methods

MethodSignatureDescription
wait()() -> NoneWait for shell to exit (async)

Example

# Interactive shell session
async with InteractiveBox(image="alpine:latest") as box:
    # You're now in an interactive shell
    # Type commands, see output in real-time
    # Type "exit" to close
    await box.wait()

BoxOptions

Configuration options shared across all box types. See BoxOptions reference for the full specification.
FieldTypeDefaultDescription
imagestrRequiredOCI image URI (e.g., "python:slim", "alpine:latest")
cpusint1Number of CPU cores (1 to host CPU count)
memory_mibint512Memory limit in MiB (128-65536)
disk_size_gbint | NoneNonePersistent disk size in GB (None = ephemeral)
working_dirstr"/root"Working directory inside container
envList[Tuple[str, str]][]Environment variables as (key, value) pairs
volumesList[Tuple[str, str, str]][]Volume mounts as (host_path, guest_path, mode)
portsList[Tuple[int, int, str]][]Port forwarding as (host_port, guest_port, protocol)
auto_removeboolTrueAuto cleanup when stopped
detachboolFalseSurvive parent process exit

BoxInfo

Metadata about a box, returned by box.info() and runtime.list().
FieldTypeDescription
idstrUnique box identifier (ULID)
namestr | NoneOptional user-assigned name
statusstrCurrent status: "running", "stopped", "created"
created_atdatetimeCreation timestamp
pidint | NoneProcess ID (if running)
imagestrOCI image used
cpusintAllocated CPU cores
memory_mibintAllocated memory in MiB

BoxStateInfo

Detailed state information for a box.
ValueDescription
CreatedBox created but not yet started
StartingBox is initializing
RunningBox is running and ready
StoppingBox is shutting down
StoppedBox is stopped
FailedBox encountered an error

See Also