Configuration and errors
configure, login, whoami, transports and the errors cua-sandbox raises.
configure, login, whoami, transports and the errors cua-sandbox raises.
Process-wide settings, sign-in helpers, transports and the typed errors of cua-sandbox.
def configure(
*,
api_key: Optional[str] = None,
base_url: Optional[str] = None,
fleet_base_url: Optional[str] = None,
token_url: Optional[str] = None,
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
fleet_token: Optional[str] = None,
) -> NoneSet global configuration for cloud sandboxes.
API-key cloud operations use base_url. Fleet uses fleet_base_url and
OAuth client credentials.
def fleet_auth_source(*, read_session: bool = True) -> Optional[str]Where Fleet credentials come from, in the order the SDK uses them.
"FLEETS_TOKEN" (a workload token), "client credentials"
(CUA_CLIENT_ID/CUA_CLIENT_SECRET), "cua auth login session"
(the stored session, refreshed by the SDK while it is used) or None
when nothing is configured. A stored session is only looked up when
neither of the first two is set. read_session=False decides that from
the non-secret session marker alone, without reading the OS credential
vault (for dashboards and other implicit checks).
def login(*, base_url: Optional[str] = None) -> NoneOpen the CUA login page in a browser and store credentials.
This initiates a Clerk-based browser authentication flow. The user completes login in their browser, and the resulting API key is stored in ~/.cua/credentials.
def whoami(*, api_key: Optional[str] = None) -> Dict[str, Any]Return info about the authenticated user.
Returns: Dict with user info (id, email, etc.) from the CUA API.
class SpacesdNotAvailable(RuntimeError)The sandbox has no reachable cua-spacesd.
Sandboxes are daemon-agnostic: creating, listing and deleting them never
needs a guest agent. The computer interfaces (screen, mouse,
shell, files ...) need cua-spacesd, or one of the agentless
transports (QMP, VNC, SSH, ADB) the runtime exposes.
class InvalidArgument(ValueError)Contradictory or invalid options (the native SDK's
CuaError.InvalidArgument), for example local=True together with
cloud=CloudOptions(...).
class InvalidPlacement(InvalidArgument)A location, kind and runtime that do not go together (the native
SDK's CuaError.InvalidPlacement), for example kind="container"
with runtime="qemu", or runtime="kubevirt" locally. The message
lists the valid values.
class Unsupported(NotImplementedError)The operation is not supported for this sandbox, image or provider
(the native SDK's CuaError.Unsupported). A NotImplementedError,
so older except NotImplementedError handlers still catch it.
class CloudTransport(Transport)Compatibility shim for the removed API-key cloud transport.
Constructing it still works (and keeps the requested image), so code that
builds one fails at connect() with a message pointing to Fleet.
| Attribute | Type | Description |
|---|---|---|
name | Optional[str] |
async def connect() -> Noneasync def disconnect() -> Noneasync def delete_vm() -> NoneDelete an existing API-key VM through the platform API.
async def create_snapshot(name: str | None = None, stateful: bool = False) -> dictasync def send(action: str, **params: Any) -> Anyasync def screenshot(format: str = 'png', quality: int = 95) -> bytesasync def get_screen_size() -> Dict[str, int]async def get_environment() -> strclass EnvTransport(Transport)Drives a sandbox through cua-spacesd.
| Parameter | Type | Default | Description |
|---|---|---|---|
url | Optional[str] | None | spacesd URL (http://host:3211, a relay or Fleet service URL). Ignored when env_factory is given. |
token | Optional[str] | None | spacesd token, if the driver requires one. |
env_factory | Optional[EnvFactory] | None | coroutine returning a cua.SpacesdClient (used by Fleet and local runtimes, which know how to reach the driver). |
environment | Optional[str] | None | OS hint (linux, windows, mac) used before the driver has been reached. |
fallback | Optional[Transport] | None | an agentless transport (QMP/VNC/SSH/ADB) to use when the sandbox has no spacesd. |
ready_timeout | float | 0.0 | how long to keep retrying the spacesd probe on first use (a freshly booted VM starts its driver late). 0 probes once. |
native_sandbox | Any | None | the cua.Sandbox handle, for port forwarding and named services. |
| Attribute | Type | Description |
|---|---|---|
url | Optional[str] |
async def connect() -> Noneasync def disconnect() -> Noneasync def spacesd() -> AnyThe raw cua.SpacesdClient (typed client escape hatch).
async def send(action: str, **params: Any) -> Anyasync def screenshot(format: str = 'png', quality: int = 95) -> bytesasync def get_screen_size() -> Dict[str, int]async def get_environment() -> strasync def get_display_url(*, share: bool = False) -> strA browser URL for the sandbox's display.
With cua-spacesd (an env or viewer service), a link to its
HTML5 viewer carrying a scoped, expiring viewer ticket; the same
link serves share=True. For images without cua-spacesd, the page
of the first declared legacy web display service (novnc,
display, web; a raw RFB port 59xx is skipped, and
share=True returns its expiring public link), then the agentless
fallback's VNC address.
async def request_service(
name: str,
*,
method: str,
path: str,
json_body: Any = None,
headers: Any = None,
) -> Anyasync def native_handle() -> AnyThe cua.Sandbox handle behind this transport (services,
forwards, public URLs).
async def native_service(name: str) -> Anyasync def forward_tunnel(sandbox_port: int | str) -> 'TunnelInfo'async def close_tunnel(info: 'TunnelInfo') -> Noneasync def pty_create(
command: Optional[str] = None,
cols: int = 120,
rows: int = 40,
cwd: Optional[str] = None,
envs: Optional[Dict[str, str]] = None,
) -> Dict[str, Any]async def pty_send(pid: int, data: str) -> Noneasync def pty_kill(pid: int) -> boolasync def pty_info(pid: int) -> Optional[Dict[str, Any]]