Python high-level API
cua_sandbox and the cua package helpers: packages, configuration, and the page for each class.
cua_sandbox and the cua package helpers: packages, configuration, and the page for each class.
The high-level Python API: cua_sandbox (Sandbox, Image, the computer interfaces, Pool) and the helpers the cua package adds. It is a thin layer over the Cua SDK objects: the cloud, the local runtimes and cua-spacesd all go through cua, whose generated binding (cua._native) those pages document.
| Package | Install | Import |
|---|---|---|
cua-sandbox 0.8.0 (Python 3.11 to 3.13) | pip install cua-sandbox | from cua_sandbox import Sandbox, Image |
cua 0.2.0 with the extra | pip install "cua[sandbox]" | from cua import Sandbox, Image (the same classes) |
| MCP client support | pip install "cua-sandbox[mcp]" | sb.mcp() |
| Typed Cua Driver access | pip install "cua-sandbox[driver]" | sb.driver |
configure() sets process-wide options; environment variables override it:
| Variable | Purpose | Default |
|---|---|---|
FLEETS_TOKEN | Cloud bearer token; wins over client credentials | None |
CUA_CLIENT_ID, CUA_CLIENT_SECRET | Cloud OAuth client credentials | None; then the cua auth login session |
CUA_FLEET_BASE_URL, CUA_TOKEN_URL | Cloud API and token endpoints | https://run.cua.ai, the cua.ai token endpoint |
CUA_FLEET_MAX_POOL_SIZE, CUA_FLEET_CLAIM_TTL, CUA_FLEET_WARM, CUA_FLEET_POOL_IDLE_GC | Cloud capacity defaults (CUA_FLEET_POOL_IDLE_GC=off disables idle cleanup) | 10, 15 min, warm for canonical images, 30 min |
CUA_IMAGE_LINUX, CUA_IMAGE_WINDOWS, CUA_IMAGE_MACOS | Override Image.linux(), Image.windows(), Image.macos() | The canonical images |
| Page | Covers |
|---|---|
| Sandbox | Sandbox, SandboxInfo, the sandbox() helper and the creation options of cua-sandbox. |
| Image | The Image builder, sidecar containers and registry credentials of cua-sandbox. |
| Pool | Pools, templates, sandbox specs and pool errors of cua-sandbox. |
| Interfaces | Shell, mouse, keyboard, screen, clipboard, window, terminal, files, apps, mobile and driver interfaces. |
| Services, tunnels and MCP | Named services, signed and public URLs, tunnels and MCP endpoints of a cua-sandbox sandbox. |
| Runtimes | Local runtimes (Docker, QEMU, Lume, Hyper-V, Tart, Android emulator) and local support checks. |
| Configuration and errors | configure, login, whoami, transports and the errors cua-sandbox raises. |
The hand-written layer of cua: two module-level constructors, a canonical-image helper and lazy re-exports of the extras.
def embedded(
*,
state_dir: Optional[str] = None,
fleet: Optional[FleetSettings] = None,
fleet_from_env: bool = True,
fleet_from_session: bool = False,
env_probe_timeout_ms: Optional[int] = None,
spaces_home: Optional[str] = None,
teleport_home: Optional[str] = None,
fleet_pool_home: Optional[str] = None,
) -> CuaAn SDK runtime in this process (no I/O until the first call).
Fleet uses CUA_CLIENT_ID/CUA_CLIENT_SECRET (or FLEETS_TOKEN);
fleet_from_session=True falls back to the cua auth login session
(cua-sandbox's Sandbox does this by default).
spaces_home is the Spaces registry directory (default ~/.cua);
teleport_home makes teleport read app sessions under that directory
with no host side effects (tests); fleet_pool_home is where managed Fleet pools keep their name
cache and GC lock (default ~/.cua).
def connect(address: Optional[str] = None, token: Optional[str] = None) -> CuaA client of a running cua daemon (socket path or loopback URL).
Without cua[sandbox], cua.Image is this helper. With it installed, cua.Image is the richer cua_sandbox Image.
class ImageCanonical image references (plain strings for sandboxes().create).
Example
from cua_sandbox import Image
img = Image.linux().apt_install("curl").pip_install("requests").env(DEBUG="1").expose(8080)
print(img.to_dict())
# {'os_type': 'linux', 'distro': 'ubuntu', 'version': '24.04', 'kind': None,
# 'layers': [{'type': 'apt_install', 'packages': ['curl']},
# {'type': 'pip_install', 'packages': ['requests']}],
# 'env': {'DEBUG': '1'}, 'ports': [8080]}@staticmethod
def linux(version: Optional[str] = None, tier: Optional[str] = None) -> strslim or full (the default).
@staticmethod
def windows(version: Optional[str] = None, tier: Optional[str] = None) -> str@staticmethod
def macos(version: Optional[str] = None, tier: Optional[str] = None) -> strslim, full (the default), xcode or xcode-<X.Y>.
@staticmethod
def omarchy(channel: Optional[str] = None) -> strOmarchy (Arch Linux, Hyprland) with cua-spacesd: an amd64 VM
(ghcr.io/trycua/omarchy:edge; emulated on arm64 hosts).
@staticmethod
def from_registry(reference: str) -> str@staticmethod
def resolve(
reference: str,
backend: str = 'local',
arch: Optional[str] = None,
) -> ResolvedImagecua resolves these names lazily from the optional extras. Install the extra to use them.
| Name | Resolves to | Extra |
|---|---|---|
cua.AgentResponse | cua_agent.AgentResponse | cua[agent] |
cua.AndroidEmulatorRuntime | cua_sandbox.runtime.AndroidEmulatorRuntime | cua[sandbox] |
cua.check_local_support | cua_sandbox.check_local_support | cua[sandbox] |
cua.Clipboard | cua_sandbox.interfaces.clipboard.Clipboard | cua[sandbox] |
cua.CloudTransport | cua_sandbox.CloudTransport | cua[sandbox] |
cua.CommandResult | cua_sandbox.interfaces.shell.CommandResult | cua[sandbox] |
cua.ComputerAgent | cua_agent.ComputerAgent | cua[agent] |
cua.configure | cua_sandbox.configure | cua[sandbox] |
cua.DockerRuntime | cua_sandbox.runtime.DockerRuntime | cua[sandbox] |
cua.EnvTransport | cua_sandbox.EnvTransport | cua[sandbox] |
cua.HyperVRuntime | cua_sandbox.runtime.HyperVRuntime | cua[sandbox] |
cua.Image | cua_sandbox.Image | cua[sandbox] |
cua.Keyboard | cua_sandbox.interfaces.keyboard.Keyboard | cua[sandbox] |
cua.login | cua_sandbox.login | cua[sandbox] |
cua.LumeRuntime | cua_sandbox.runtime.LumeRuntime | cua[sandbox] |
cua.Messages | cua_agent.Messages | cua[agent] |
cua.Mobile | cua_sandbox.interfaces.mobile.Mobile | cua[sandbox] |
cua.Mouse | cua_sandbox.interfaces.mouse.Mouse | cua[sandbox] |
cua.Pool | cua_sandbox.Pool | cua[sandbox] |
cua.PoolAccessDeniedError | cua_sandbox.PoolAccessDeniedError | cua[sandbox] |
cua.QEMURuntime | cua_sandbox.runtime.QEMURuntime | cua[sandbox] |
cua.register_agent | cua_agent.register_agent | cua[agent] |
cua.RuntimeInfo | cua_sandbox.runtime.RuntimeInfo | cua[sandbox] |
cua.RuntimeSupport | cua_sandbox.RuntimeSupport | cua[sandbox] |
cua.sandbox | cua_sandbox.sandbox | cua[sandbox] |
cua.Sandbox | cua_sandbox.Sandbox | cua[sandbox] |
cua.SandboxInfo | cua_sandbox.SandboxInfo | cua[sandbox] |
cua.Screen | cua_sandbox.interfaces.screen.Screen | cua[sandbox] |
cua.Shell | cua_sandbox.interfaces.shell.Shell | cua[sandbox] |
cua.skip_if_unsupported | cua_sandbox.skip_if_unsupported | cua[sandbox] |
cua.SpacesdNotAvailable | cua_sandbox.SpacesdNotAvailable | cua[sandbox] |
cua.TartRuntime | cua_sandbox.runtime.TartRuntime | cua[sandbox] |
cua.Template | cua_sandbox.Template | cua[sandbox] |
cua.Terminal | cua_sandbox.interfaces.terminal.Terminal | cua[sandbox] |
cua.Tunnel | cua_sandbox.interfaces.tunnel.Tunnel | cua[sandbox] |
cua.TunnelInfo | cua_sandbox.interfaces.tunnel.TunnelInfo | cua[sandbox] |
cua.whoami | cua_sandbox.whoami | cua[sandbox] |
cua.Window | cua_sandbox.interfaces.window.Window | cua[sandbox] |
cua.runtime: sandbox runtime backends.
Exports: Runtime, RuntimeInfo, DockerRuntime, QEMURuntime, QEMUDockerRuntime, QEMUBaremetalRuntime, QEMUWSL2Runtime, LumeRuntime, HyperVRuntime, AndroidEmulatorRuntime, TartRuntime.
cua.tools: agent tool classes and registry.
Exports: BaseTool, BaseComputerTool, register_tool, get_registered_tools, get_tool, TOOL_REGISTRY, BrowserTool, ToolError, IllegalArgumentError.
cua.callbacks: agent lifecycle callback handlers.
Exports: AsyncCallbackHandler, ImageRetentionCallback, LoggingCallback, TrajectorySaverCallback, BudgetManagerCallback, TelemetryCallback, OtelCallback, OtelErrorCallback, OperatorNormalizerCallback, PromptInstructionsCallback.