---
name: socai-connect
description: Connect the user's existing Agent to their Socai cloud computer, without asking them to operate a terminal.
---

# Connect Socai

Carry out the connection, not a summary of these instructions. Use the commercial Socai CLI linked below, not a similarly named package from npm or GitHub. Preserve the user's existing local Chrome and public CLI. The commercial CLI includes the same-origin relay used by Aliyun AgentSandbox; installing it is not a Desktop application update.

## First choose the connection method

- **Without a connection fragment:** after installation, run the printed private command with `init --server <Socai origin>`. The CLI opens that Socai site's authorization page and waits. Let the user sign in or register there and approve this connection. Existing signed-in users only confirm their account. Let the original command finish; do not start another login or initialization while it is waiting. When automatic browser opening is unavailable, privately provide the authorization link printed by that command. Do not invent a credential. Do not use `--connection-stdin` with an empty value.
- **With `#connection=` in the supplied link:** use the stdin exchange below. A valid personalized grant already authorizes this account, so do not ask for a second Web login. Never print the fragment.
- An expired or consumed fragment is not a plain link: ask for a fresh copied connection prompt instead of silently logging in as another account.

## What to deliver

1. Detect the Agent host's OS and available terminal/HTTP tools. On macOS arm64 and Linux x64 with Node.js 22+, install the private CLI below if a compatible private installation is not available. Otherwise use the direct API section.
2. Connect by the selected method and reuse the account's existing live computer. Never echo or log a personalized link.
3. Actually execute `cloud status` and `capabilities` using the command path printed by the installer, normally `~/.socai/cloud-cli/bin/socai`. Respect a verified custom install directory. For the API route, actually read `GET /v1/cli/browsers`. Reading this guide or installing alone is not a successful connection test.
4. Open the returned safe computer URL for the user. Reply briefly with the real connection result and that URL. If research was requested, continue with the real site tools.

Examples after connecting, using the default private install path:

```text
~/.socai/cloud-cli/bin/socai xhs search-suggestions "租房收纳" --limit 5
~/.socai/cloud-cli/bin/socai xhs search "租房收纳" --num-notes 3 --preview
~/.socai/cloud-cli/bin/socai xhs search "咖啡机" --num-notes 1 --num-comments 5
```

Read an unfamiliar command's `--help` before choosing flags. A QR/login screen, empty result or transport handshake is not successful collection. Ask the user to complete platform sign-in or verification in the returned Socai computer, not an unrelated local tab. Never ask for their password or verification code. The connection uses this CLI and its bundled Skill, not an automatically configured MCP server.

Keep credentials out of stdout, screenshots, logs, commits, chat replies, command arguments and HTTP URLs. Extract a personalized link's `#connection=` value privately before fetching the README, then fetch only the URL without its fragment. HTTP cannot retrieve the fragment. Use the HTTPS origin of that same supplied link.

The fragment is base64url-encoded JSON containing `server`, `poll_token`, `code_verifier` and `expires_at`. It is a five-minute, single-use capability, not a reusable API key. Verify that `server` exactly matches the supplied HTTPS origin; never send it elsewhere. If expired or consumed, ask for a fresh copied prompt from Socai's Local Agent connections page, not a token pasted into chat.

## Install and connect

This guide applies to Codex, WorkBuddy, 豆包工作 (Doubao Work), Claude Code, Grok Build, Grok Bot, DeepSeek Harness, Cursor, Muse Agent and Dots. Selecting a host changes the instructions, not the account or computer; it does not make an unavailable terminal or CDP tool available.

1. Check the private installation and its release metadata. A matching name or support for `--connection-stdin` alone does not prove support for the AgentSandbox relay. Do not replace an existing public `socai`, local Chrome profile or shell configuration. Keep a verified custom private command path.
2. On macOS arm64 or Linux x64 with Node.js 22+, download `https://socai-downloads.oss-cn-hangzhou.aliyuncs.com/cli/dev/0.1.7-dev.20261124/install.mjs` into a temporary file and run it with Node. The installer selects the matching native binary and verifies its checksum. Read the bundled `SKILL.md` beside the resolved `socai.mjs`. This is an explicit dev preview, not an automatic Desktop update. On an unsupported platform or installation failure, use the API route instead of installing another platform's binary or retrying indefinitely.
3. For a plain link, run `init --server <Socai origin>` and finish the Web authorization above. Only for a supplied personalized fragment, run `init --connection-stdin --server <Socai origin>`, passing the original personalized README link or fragment value through the child process's stdin, never argv or logs. A shell-free child process with `input`/stdin is preferred. The CLI exchanges the capability once, saves a revocable browser-only key with owner-only permissions, and returns an onboarding URL. Do not run interactive login again after a successful exchange.
4. Run the status and capability commands above, then open the returned Socai computer URL. Reuse a live computer instead of initializing or creating another merely for a preview. A cloud Agent operates in its own execution environment; do not install software on the user's local computer from there.

Only report what actually succeeded. If the host has no terminal, HTTP client or compatible CDP implementation, explain the specific limitation. Do not claim a host adapter, MCP server, collection result or tool was installed merely because this guide was read.

## Direct API when installation is unavailable

Use the same supplied Socai origin under `/api/server`. This requires an HTTP client and, for browser operations, a compatible native CDP client.

1. With a personalized link, decode its fragment privately and `POST /v1/cli/auth/token` with JSON `poll_token` and `code_verifier`. Consume it once. Without a fragment, open that Socai site's `/session` page for sign-in or registration, then have the user copy the Local Agent connection prompt. Do not invent a token. An `authorized` response contains a revocable `sc-cli-` browser key; store it privately with owner-only permissions. Never use this browser-only key for `/v1/responses`, Web session authentication or model billing.
2. Send the key only as `Authorization: Bearer <key>` to the same Socai origin. `GET /v1/cli/browsers` lists this account's computers. Reuse a live `ready` entry with a future `expires_at`; do not use stale readiness or create a duplicate for a preview.
3. Only when no live computer exists, `POST /v1/cli/browsers` with a fresh UUID `request_id`, `platform: "xhs"` and `timeout_seconds: 600`. Store that request ID before sending. Do not replay a timed-out create; reconcile it using `GET /v1/cli/browsers/{id}`. On 409 inspect the existing list instead of generating another UUID.
4. Open the returned `onboarding_url` after checking that it belongs to the same Socai origin. `GET /v1/cli/browsers/{id}/connection` returns a short-lived `connect_url` for private CDP use. It is not a public preview URL; never include it in chat, screenshots or logs.
5. For AgentSandbox, the returned relay has the exact form `wss://<Socai host>/api/server/v1/cli/browsers/<lease UUID>/cdp`. Require the same host and port as the supplied HTTPS origin, the exact current lease UUID, no query, no fragment and no URL username/password. Connect with `Authorization: Bearer <key>` in the WebSocket upgrade header. Use a native CDP client that supports header authentication and does not set a browser Origin header. A browser page's JavaScript WebSocket cannot supply this header; do not move the key to a query parameter, disable TLS validation, copy login cookies or silently switch providers to work around that limitation.
6. Older servers may return supplier-owned `wss:` URLs under `*.kernel.sh` or `*.onkernel.com`. The commercial CLI retains legacy compatibility, but an AgentSandbox relay does not require a Kernel host. Never attach the Socai key to a supplier URL. Do not treat unrelated hosts, insecure URLs, another lease or a changed endpoint as authorized.
7. If the host cannot operate the authenticated CDP connection, leave the user at the usable Web computer and state the limitation. Do not claim collection succeeded. On explicit close, `POST /v1/cli/browsers/{id}/release` with `{}`. A hidden preview alone is not a reason to delete or release a computer.

On 401/410 reconcile the current authorization or browser state; do not repeat a consumed grant or blindly recreate a computer. On 402 show the Socai recharge page, or explicitly offer the existing local mode (`init --local`) with its own platform login. On 429 respect the rate limit. An event-delivery failure does not repeat the tool; preserve the real tool outcome and report trace delivery as pending. Never silently change billing or copy cloud cookies into local Chrome.

Use the server's returned billing status and actual settled usage. Missing supplier usage remains pending, not zero; do not assume Kernel-only pricing for AgentSandbox. Installing or connecting does not authorize a purchase, subscription, GitHub Star or other external account action.
