Cua client
The Cua handle: embedded or daemon client, its configuration, and the SDK version.
The Cua handle: embedded or daemon client, its configuration, and the SDK version.
Every program starts from one Cua handle, embedded in the process or connected to a running cua daemon, with the same API either way. Its accessors return the other objects. The config_* functions read and write the user defaults in $CUA_HOME/config.toml (cua config).
| Topology | Create | Behavior |
|---|---|---|
| Embedded | Cua.embedded(config) (Python cua.embedded(), TypeScript embedded()) | The runtime lives in your process |
| Daemon client | Cua.connect(address, token) (Python cua.connect(), TypeScript connect()) | Calls a running cua daemon, which shares sandboxes, spacesd connections, tunnels and credentials across processes |
connect() without an address reads ~/.cua/daemon.json, then the socket ~/.cua/cua.sock. The connection is lazy: the first call fails with Transport when no daemon runs (cua daemon start). An embedded client reads Fleet credentials from FLEETS_TOKEN, or CUA_CLIENT_ID and CUA_CLIENT_SECRET (with CUA_FLEET_BASE_URL and CUA_TOKEN_URL), unless fleet_from_env is off.
Cua#The entry point of the SDK: create one with Cua::embedded or
Cua::connect, then reach sandboxes, Fleet, Spaces and the rest
through its accessors.
| Method | Description |
|---|---|
auto | The default topology: the cua daemon this machine runs when one accepts connections (so the CLI, MCP clients and apps share sandboxes and Spaces), else the runtime in this process with config. |
connect | Connects to a running cua daemon. |
embedded | Runs the SDK runtime in this process. |
fleet | Fleet pools, templates, claims and images. |
info | SDK (and daemon) identity. |
shutdown_daemon | Asks a connected daemon to stop (daemon mode only). |
spacesd | Connects to cua-spacesd at url (host:port, http(s)://…, a Fleet service URL or a relay URL) without a sandbox. |
| Accessor | Returns | Description |
|---|---|---|
agent_setup() | AgentSetup | Agent onboarding: detect AI coding agents, install the cua skills and configure the cua MCP server for the current user. |
auth() | Auth | Sign-in and the shared session (CUA_OIDC_ISSUER, CUA_CREDENTIAL_STORE, CUA_HOME apply). |
local() | Local | Local runtimes (doctor and setup) and local images. |
mode() | CuaMode | Topology. |
sandboxes() | Sandboxes | Sandboxes (Fleet, local, direct). |
spaces() | Spaces | Spaces: the registry and every Space primitive. |
Cua.auto#The default topology: the cua daemon this machine runs when one
accepts connections (so the CLI, MCP clients and apps share
sandboxes and Spaces), else the runtime in this process with
config. A discovery file (~/.cua/daemon.json) or socket left by a
daemon that exited is not a running daemon: the files are removed
when their pid is provably dead, and this falls back to embedded.
A daemon that is starting (~/.cua/daemon.starting) is waited for,
up to 30 s. Probes with a local connect only (no RPC), except in a
process inside
an app bundle that ships its own cua: it uses only that build's
daemon, and fails with CuaError.DaemonNotRunning naming the
running one (another app's, or its own before a rebuild or update)
rather than silently use it; <bundle>/Contents/MacOS/cua daemon start replaces it.
@classmethod
def auto(cls, config: CuaConfig) -> Cua| Parameter | Type | Default |
|---|---|---|
config | CuaConfig | required |
Returns Cua · Raises CuaError (DaemonNotRunning)
Cua.connect#Connects to a running cua daemon. address is a socket path
(unix: prefix optional) or a loopback URL (then token is
required unless the discovery file has it); None uses
~/.cua/daemon.json, then ~/.cua/cua.sock. Connects lazily: the
first call fails with DaemonNotRunning when no daemon runs; use
Cua.info to check, or Cua.auto to fall back to the runtime
in this process.
@classmethod
def connect(cls, address: Optional[str], token: Optional[str]) -> Cua| Parameter | Type | Default |
|---|---|---|
address | Option<String> | required |
token | Option<String> | required |
Returns Cua · Raises CuaError (DaemonNotRunning)
Cua.embedded#Runs the SDK runtime in this process. Performs no I/O beyond
reading the credential store when fleet_from_session is set.
@classmethod
def embedded(cls, config: CuaConfig) -> Cua| Parameter | Type | Default |
|---|---|---|
config | CuaConfig | required |
Example
import cua
c = cua.embedded() # the SDK runs in this process; cua.connect() uses a running `cua daemon`
print(c.mode())Cua.fleet#Fleet pools, templates, claims and images. Always talks to Fleet from this process with this SDK's credentials (in daemon mode, from the environment).
def fleet(self) -> FleetReturns Fleet · Raises CuaError
Cua.info#SDK (and daemon) identity. In daemon mode this is the connectivity check.
async def info(self) -> CuaInfoReturns CuaInfo · Async · Raises CuaError
Cua.shutdown_daemon#Asks a connected daemon to stop (daemon mode only).
async def shutdown_daemon(self) -> NoneAsync · Raises CuaError
Cua.spacesd#Connects to cua-spacesd at url (host:port, http(s)://…, a
Fleet service URL or a relay URL) without a sandbox.
async def spacesd(self, url: str, token: Optional[str]) -> SpacesdClient| Parameter | Type | Default |
|---|---|---|
url | String | required |
token | Option<String> | required |
Returns SpacesdClient · Async · Raises CuaError
CuaConfig record#Configuration of an embedded SDK runtime.
| Field | Type | Default | Description |
|---|---|---|---|
state_dir / stateDir | Option<String> | None | State directory for sandbox state files (default ~/.cua/sandboxes). |
fleet | Option<FleetSettings> | None | Fleet settings (merged over the environment). |
fleet_from_env / fleetFromEnv | bool | true | Read Fleet settings from the environment. |
env_probe_timeout_ms / envProbeTimeoutMs | Option<u32> | None | spacesd probe timeout (default 15 s). |
spaces_home / spacesHome | Option<String> | None | Spaces registry directory (default $CUA_HOME or ~/.cua). |
teleport_home / teleportHome | Option<String> | None | Teleport reads app sessions under this home directory with no host side effects (tests, CI). Default: the real host. |
fleet_from_session / fleetFromSession | bool | false | When the settings and environment carry no Fleet credentials, use the signed-in session (Cua.auth(), cua auth login) from the shared credential store, refreshed as needed. |
fleet_pool_home / fleetPoolHome | Option<String> | None | Where managed Fleet pools keep their name cache and machine-wide GC lock (default: $CUA_HOME or ~/.cua, or next to state_dir). |
FleetSettings record#Fleet credentials and endpoints. Unset fields fall back to the
environment (CUA_FLEET_BASE_URL, CUA_TOKEN_URL, CUA_CLIENT_ID,
CUA_CLIENT_SECRET, FLEETS_TOKEN) when CuaConfig.fleet_from_env.
| Field | Type | Default | Description |
|---|---|---|---|
base_url / baseUrl | Option<String> | None | Fleet API base URL. |
token_url / tokenUrl | Option<String> | None | OAuth token URL. |
client_id / clientId | Option<String> | None | OAuth client id. |
client_secret / clientSecret | Option<String> | None | OAuth client secret. |
token | Option<String> | None | Static Fleet token (wins over client credentials). |
CuaInfo record#Identity of the SDK (and daemon, when connected).
Returned by Cua.info.
| Field | Type | Default | Description |
|---|---|---|---|
sdk_version / sdkVersion | String | SDK library version. | |
mode | CuaMode | Topology. | |
daemon_version / daemonVersion | Option<String> | Daemon version (daemon mode). | |
daemon_pid / daemonPid | Option<u32> | Daemon pid (daemon mode). | |
socket_path / socketPath | Option<String> | Daemon socket (daemon mode). | |
loopback_url / loopbackUrl | Option<String> | Daemon loopback URL (daemon mode). | |
features | Vec<String> | Compiled-in modules. |
CuaMode enum#Where the SDK runtime lives.
CuaMode.EMBEDDED
CuaMode.DAEMON| Variant | Description |
|---|---|
Embedded | In this process. |
Daemon | In a cua daemon. |
cua_sdk_version#Version of the SDK library.
def cua_sdk_version() -> strReturns String
config_list#Every setting with its effective value and source.
def config_list() -> List[ConfigEntry]Returns Vec<ConfigEntry> · Raises CuaError
config_get#One setting's effective value and source.
def config_get(key: str) -> ConfigEntry| Parameter | Type | Default |
|---|---|---|
key | String | required |
Returns ConfigEntry · Raises CuaError
config_set#Writes a setting to the config file (checked and normalised: default.on
takes local, cloud or a provider). Returns its effective value, which
an environment variable may still override.
def config_set(key: str, value: str) -> ConfigEntry| Parameter | Type | Default |
|---|---|---|
key | String | required |
value | String | required |
Returns ConfigEntry · Raises CuaError
config_unset#Removes a setting from the config file. Returns its effective value afterwards (the environment variable or the built-in default).
def config_unset(key: str) -> ConfigEntry| Parameter | Type | Default |
|---|---|---|
key | String | required |
Returns ConfigEntry · Raises CuaError
config_path#The config file's path ($CUA_HOME/config.toml).
def config_path() -> strReturns String
ConfigEntry record#One setting's effective value.
Returned by config_get, config_list, config_set, config_unset.
| Field | Type | Default | Description |
|---|---|---|---|
key | String | default.on, default.kind, default.runtime, cloud.warm, cloud.max_pool_size or cloud.claim_ttl. | |
value | String | The effective value. | |
source | String | env, config or default. | |
from | String | Where exactly: env CUA_DEFAULT_ON, config /home/me/.cua/config.toml or default. | |
env | String | The environment variable that overrides it. | |
default_value / defaultValue | String | The built-in default. | |
description | String | One line about it. |
locations#Every location with the kinds and runtimes it offers (for pickers and help text).
def locations() -> List[LocationInfo]Returns Vec<LocationInfo>
LocationInfo record#The locations on accepts: local, cloud, then registered providers.
Returned by locations.
| Field | Type | Default | Description |
|---|---|---|---|
name | String | The location's name. | |
description | String | One line about it. | |
kinds | Vec<String> | The kinds it runs (container, vm). | |
runtimes | HashMap<String, Vec<String>> | Its runtimes, in auto preference order, per kind (container: gvisor, runc). |
check_placement#Checks a location, kind and runtime against each other without creating
anything: InvalidPlacement (listing the valid values) when the
combination does not exist. Empty strings are auto; an empty on is
the user default.
def check_placement(on: str, kind: str, runtime: str) -> None| Parameter | Type | Default |
|---|---|---|
on | String | required |
kind | String | required |
runtime | String | required |
Raises CuaError (InvalidPlacement)
error_doc_url#A link to the errors-reference entry of a CuaError variant, by name
(InvalidArgument, case-insensitive). An unknown name links to the
page itself. The bindings' doc_url / docUrl on CuaError use it.
def error_doc_url(variant: str) -> str| Parameter | Type | Default |
|---|---|---|
variant | String | required |
Returns String