Services

Named services, port forwards, public URLs and MCP clients of a sandbox.

Reach ports inside a sandbox: sandbox.service(name) for a declared service, sandbox.forward(port) for any port, sandbox.public_url(...) for a shareable URL, and McpClient for an MCP server. None of them needs cua-spacesd.

Python programs usually use the high-level API instead: cua_sandbox services, tunnels and MCP.

To reach a guest portUseWorks
From your code, by namesandbox.service(name).request(...) or .url()Declared services
From local tools (a browser, a client)sandbox.forward(port)Any port; a loopback listener
From someone elsesandbox.public_url(service, ttl_seconds, label)Declared services; a bearer URL that expires
From an MCP clientsandbox.mcp_config(service, path) or sandbox.mcp(service, path)An MCP server behind a declared service

Sandbox services#

Methods of Sandbox.

Sandbox.service#

A named service (for example "server" or "env").

def service(self, name: str) -> Service
ParameterTypeDefault
nameStringrequired

Returns Service · Raises CuaError

Sandbox.services#

Declared services.

def services(self) -> dict[str, int]

Returns HashMap<String, u16>

Sandbox.forward#

Forwards a loopback port to guest port: a TCP forward locally (and over cua-spacesd's tunnel when the image has it). url() is a loopback URL.

async def forward(self, port: int) -> PortForward
ParameterTypeDefault
portu16required

Returns PortForward · Async · Raises CuaError

Sandbox.public_url#

A shareable URL for service that stops working after ttl_seconds (60 s to 24 h, default 1 h): a loopback URL with its own token, served by the cua daemon (started if needed; CUA_BIN names the CLI).

async def public_url(self, service: str, ttl_seconds: Optional[int] = None, label: Optional[str] = None) -> PublicUrl
ParameterTypeDefault
serviceStringrequired
ttl_secondsOption<u32>None
labelOption<String>None

Returns PublicUrl · Async · Raises CuaError

Sandbox.revoke_public_url#

Revokes a URL from public_url.

async def revoke_public_url(self, id: str) -> None
ParameterTypeDefault
idStringrequired

Async · Raises CuaError

Sandbox.mcp_config#

Where the MCP server behind service is (URL of its endpoint at path, default /mcp, plus the headers every request needs), for any MCP client. Embedded: the service route itself (loopback). Daemon: the daemon's streaming passthrough with its loopback bearer.

async def mcp_config(self, service: str, path: Optional[str] = None) -> McpConfig
ParameterTypeDefault
serviceStringrequired
pathOption<String>None

Returns McpConfig · Async · Raises CuaError

Sandbox.mcp#

An MCP client (the official Rust SDK) for the MCP server behind service at path (default /mcp).

async def mcp(self, service: str, path: Optional[str] = None) -> McpClient
ParameterTypeDefault
serviceStringrequired
pathOption<String>None

Returns McpClient · Async · Raises CuaError

Service#

A named service of a sandbox.

Returned by Sandbox.service.

MethodDescription
endpointWhere this service is reachable from this process: base URL plus the headers every request needs.
mcpAn MCP client (the official Rust SDK) for this service's endpoint at path (default /mcp).
mcp_configThe MCP endpoint of this service at path (default /mcp).
public_urlA shareable URL for this service that stops working after ttl_seconds (60 s to 24 h, default 1 h): the same as Sandbox.public_url(name, ...): a loopback URL with its own token, served by the cua daemon.
requestOne HTTP request to path on the service.
urlA URL for the service usable from this machine with no credentials (no trailing slash): the published loopback port locally.
AccessorReturnsDescription
name()StringService name.

Service.endpoint#

Where this service is reachable from this process: base URL plus the headers every request needs. Any HTTP client can use it (SSE, long-lived streams and every method pass through unchanged).

async def endpoint(self) -> ServiceEndpoint

Returns ServiceEndpoint · Async · Raises CuaError

Service.mcp#

An MCP client (the official Rust SDK) for this service's endpoint at path (default /mcp).

async def mcp(self, path: Optional[str] = None) -> McpClient
ParameterTypeDefault
pathOption<String>None

Returns McpClient · Async · Raises CuaError

Service.mcp_config#

The MCP endpoint of this service at path (default /mcp).

async def mcp_config(self, path: Optional[str] = None) -> McpConfig
ParameterTypeDefault
pathOption<String>None

Returns McpConfig · Async · Raises CuaError

Service.public_url#

A shareable URL for this service that stops working after ttl_seconds (60 s to 24 h, default 1 h): the same as Sandbox.public_url(name, ...): a loopback URL with its own token, served by the cua daemon.

async def public_url(self, ttl_seconds: Optional[int] = None, label: Optional[str] = None) -> PublicUrl
ParameterTypeDefault
ttl_secondsOption<u32>None
labelOption<String>None

Returns PublicUrl · Async · Raises CuaError

Service.request#

One HTTP request to path on the service. Credentials are attached by the runtime. headers are sent as given (for example content-type, or accept and mcp-session-id for MCP).

async def request(self, method: str, path: str, body: Optional[bytes], timeout_ms: Optional[int], headers: Optional[List[HttpHeader]] = None) -> HttpResponse
ParameterTypeDefault
methodStringrequired
pathStringrequired
bodyOption<Vec<u8>>required
timeout_msOption<u32>required
headersOption<Vec<HttpHeader>>None

Returns HttpResponse · Async · Raises CuaError

Service.url#

A URL for the service usable from this machine with no credentials (no trailing slash): the published loopback port locally.

async def url(self) -> str

Returns String · Async · Raises CuaError

ServiceEndpoint record#

Where a sandbox service is reachable from this process.

Returned by Service.endpoint.

FieldTypeDefaultDescription
urlStringBase URL (append the path).
headersVec<HttpHeader>Headers every request needs.

HttpHeader record#

An HTTP header.

Returned by Space.websocket_headers.

FieldTypeDefaultDescription
nameStringName.
valueStringValue.

HttpResponse record#

An HTTP response from a sandbox service.

Returned by Service.request.

FieldTypeDefaultDescription
statusu16Status.
headersVec<HttpHeader>Headers.
bodyVec<u8>Body.

PortForward#

An active port forward. Closed on close() or when dropped.

Returned by Sandbox.forward, Space.forward.

MethodDescription
closeStops the forward.
AccessorReturnsDescription
guest_port()u16Guest port.
local_addr()Option<String>Loopback host:port accepting connections (local/direct).
url()Option<String>URL to use (a loopback URL).

PortForward.close#

Stops the forward.

async def close(self) -> None

Async · Raises CuaError

PublicUrl record#

A shareable URL of a sandbox service that expires.

Returned by Sandbox.public_url, Service.public_url.

FieldTypeDefaultDescription
idStringId for Sandbox.revoke_public_url.
urlStringThe URL.
expires_at_unix / expiresAtUnixi64When it stops working (unix seconds).
serviceStringService name.
provider_details / providerDetailsHashMap<String, String>Provider internals (local: upstream).

McpClient#

An MCP client (rmcp, streamable HTTP; protocol 2026-07-28 when the server supports it, else the server's revision). Results are the server's JSON, unchanged.

Returned by Sandbox.mcp, Service.mcp, mcp_connect, mcp_connect_url.

MethodDescription
call_toolCalls name with a JSON object of arguments (None: {}); returns the tools/call result JSON verbatim (a tool error is isError).
closeCloses the connection (ends the session on servers that keep one).
get_promptRenders prompt name; the prompts/get result JSON.
list_promptsEvery prompt (all pages), JSON array.
list_resource_templatesEvery resource template (all pages), JSON array.
list_resourcesEvery resource (all pages), JSON array.
list_toolsEvery tool (all pages) as a JSON array of MCP Tool objects.
read_resourceReads uri; the resources/read result JSON.
requestAny other JSON-RPC method (extensions such as skills/list, skills/get); returns its result JSON.
AccessorReturnsDescription
server_info_json()Option<String>The server's serverInfo/negotiated version as JSON, when known.

McpClient.call_tool#

Calls name with a JSON object of arguments (None: {}); returns the tools/call result JSON verbatim (a tool error is isError).

async def call_tool(self, name: str, arguments_json: Optional[str]) -> str
ParameterTypeDefault
nameStringrequired
arguments_jsonOption<String>required

Returns String · Async · Raises CuaError

McpClient.close#

Closes the connection (ends the session on servers that keep one).

async def close(self) -> None

Async · Raises CuaError

McpClient.get_prompt#

Renders prompt name; the prompts/get result JSON.

async def get_prompt(self, name: str, arguments_json: Optional[str]) -> str
ParameterTypeDefault
nameStringrequired
arguments_jsonOption<String>required

Returns String · Async · Raises CuaError

McpClient.list_prompts#

Every prompt (all pages), JSON array.

async def list_prompts(self) -> str

Returns String · Async · Raises CuaError

McpClient.list_resource_templates#

Every resource template (all pages), JSON array.

async def list_resource_templates(self) -> str

Returns String · Async · Raises CuaError

McpClient.list_resources#

Every resource (all pages), JSON array.

async def list_resources(self) -> str

Returns String · Async · Raises CuaError

McpClient.list_tools#

Every tool (all pages) as a JSON array of MCP Tool objects.

async def list_tools(self) -> str

Returns String · Async · Raises CuaError

McpClient.read_resource#

Reads uri; the resources/read result JSON.

async def read_resource(self, uri: str) -> str
ParameterTypeDefault
uriStringrequired

Returns String · Async · Raises CuaError

McpClient.request#

Any other JSON-RPC method (extensions such as skills/list, skills/get); returns its result JSON.

async def request(self, method: str, params_json: Optional[str]) -> str
ParameterTypeDefault
methodStringrequired
params_jsonOption<String>required

Returns String · Async · Raises CuaError

McpConfig record#

Where an MCP endpoint is and what every request needs. Hand it to any MCP client (Claude Code, Cursor, the Python or TypeScript SDKs). A provider's headers may be short-lived: fetch a fresh config per connection.

Returned by Sandbox.mcp_config, Service.mcp_config.

FieldTypeDefaultDescription
urlStringStreamable-HTTP endpoint URL.
headersVec<HttpHeader>Headers to send with every request.

mcp_connect#

Connects an MCP client to config (from Sandbox.mcp_config).

async def mcp_connect(config: McpConfig) -> McpClient
ParameterTypeDefault
configMcpConfigrequired

Returns McpClient · Async · Raises CuaError

mcp_connect_url#

Connects an MCP client to an endpoint URL (http://host:8765/mcp; a bare origin means /mcp) with headers on every request.

async def mcp_connect_url(url: str, headers: Optional[List[HttpHeader]]) -> McpClient
ParameterTypeDefault
urlStringrequired
headersOption<Vec<HttpHeader>>required

Returns McpClient · Async · Raises CuaError