Services, tunnels and MCP
Named services, signed and public URLs, tunnels and MCP endpoints of a cua-sandbox sandbox.
Named services, signed and public URLs, tunnels and MCP endpoints of a cua-sandbox sandbox.
Reach ports inside a sandbox: named services, tunnels, shareable URLs and MCP servers.
class ServiceHandleOne named service of a sandbox (sb.service("mcp")).
The same calls work local and in the cloud: requests carry your headers
(the cloud gateway's credentials are added for you), url() is usable
from this machine and public_url() can be shared.
| Attribute | Type | Description |
|---|---|---|
name | str |
async def request(
method: str,
path: str = '/',
*,
headers: Headers = None,
body: bytes | str | None = None,
json: Any = None,
timeout: float = 30.0,
) -> AnyOne HTTP request to path on the service; returns an
httpx.Response. authorization is refused in the cloud, where
the gateway credentials own it.
async def url() -> strA URL for the service usable from this machine with no credentials (no trailing slash): the published loopback port locally, a signed URL (1 h, renewed on later calls) in the cloud.
async def public_url(ttl: float = 3600, *, label: Optional[str] = None) -> 'PublicUrl'A shareable URL that stops working after ttl seconds (60 s to
24 h). See cua_sandbox.Sandbox.public_url.
class ServicesRequest a named service exposed by the active sandbox connection.
async def request(
name: str,
*,
method: str,
path: str,
json: Any = None,
headers: dict[str, str] | None = None,
) -> AnySend a request to a named service on this sandbox.
Prefer sb.service(name).request(...), which works the same local
and in the cloud.
async def create_signed_url(
name: str,
*,
expires_in_seconds: int,
label: str | None = None,
) -> SignedServiceURLCreate a revocable public URL for a named cloud service.
Prefer sb.public_url(name, ttl=...), which also works locally.
async def list_signed_urls() -> list[SignedServiceURL]List signed service URLs created for this cloud sandbox.
async def revoke_signed_url(signed_url: SignedServiceURL) -> NoneRevoke a previously created signed service URL.
class SignedServiceURLA revocable public URL for one sandbox service.
Provider internals (the cloud namespace and claim) live in details.
| Attribute | Type | Description |
|---|---|---|
id | str | |
sandbox | str | |
service | str | |
label | str | None | |
url | str | |
created_at | str | |
expires_at | str | |
revoked_at | str | None | |
details | dict | |
namespace | str | None | Deprecated: details["namespace"]. |
claim | str | None | Deprecated: details["claim"]. |
@classmethod
def from_resource(resource: Any) -> 'SignedServiceURL'class TunnelPort-forwarding interface: exposes sandbox ports on the host.
def forward(*ports: int | str) -> _TunnelContextForward one or more sandbox ports (or abstract sockets) to the host.
ports may be:
int: TCP port inside the sandbox (e.g. 8080)str: Android abstract socket name (e.g. "chrome_devtools_remote")Returns a context manager (or awaitable) that yields:
TunnelInfo when one target is givendict[sandbox_port, TunnelInfo] when multiple targets are givenExample: Chrome DevTools over ADB:
async with sb.tunnel.forward("chrome_devtools_remote") as t:
# http://localhost:<random>/json lists CDP targets
print(t.url)class TunnelInfoA single forwarded port.
| Attribute | Type | Description |
|---|---|---|
host | str | |
port | int | |
sandbox_port | int | |
url | str |
async def close() -> NoneClose this tunnel (no-op if already closed or inside a context manager).
async def mcp_config(
service: Callable[[], Awaitable[Any]],
path: str = '/mcp',
) -> Dict[str, Any]{"url": ..., "headers": {...}} of the MCP endpoint at path.
async def connect(config: Dict[str, Any]) -> AsyncIterator[Any]An initialized official-SDK client for config (url, headers).
With mcp 2.x this is an mcp.Client (protocol negotiated with
server/discover, falling back to initialize); with 1.x an
initialized mcp.ClientSession.
async def open_mcp(
service: Callable[[], Awaitable[Any]],
path: str = '/mcp',
) -> AsyncIterator[Any]connect(await mcp_config(service, path)).