Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

Add dual command structure: flat and grouped styles

f-trycua839506828632
diff --git a/docs/content/docs/libraries/cua-cli/commands.mdx b/docs/content/docs/libraries/cua-cli/commands.mdx
index 5768fc39ad..77e79e13ce 100644
--- a/docs/content/docs/libraries/cua-cli/commands.mdx
+++ b/docs/content/docs/libraries/cua-cli/commands.mdx
@@ -8,7 +8,29 @@ import { Callout } from 'fumadocs-ui/components/callout';
## Overview
-The CUA CLI provides commands for authentication and sandbox management:
+The CUA CLI provides commands for authentication and sandbox management.
+
+### Command Styles
+
+The CLI supports **two command styles** for flexibility:
+
+**Flat style** (quick & concise):
+```bash
+cua list
+cua create --os linux --configuration small --region north-america
+cua start my-sandbox
+```
+
+**Grouped style** (explicit & organized):
+```bash
+cua sandbox list # or: cua sb list
+cua sandbox create # or: cua sb create
+cua sandbox start # or: cua sb start
+```
+
+Both styles work identically - use whichever you prefer!
+
+### Available Commands
- **Authentication** - `cua login`, `cua env`, `cua logout`
- **Sandbox Management** - `cua list`, `cua create`, `cua start`, `cua stop`, `cua restart`, `cua delete`, `cua open`
diff --git a/libs/typescript/cua-cli/README.md b/libs/typescript/cua-cli/README.md
index b8dd5b819a..c79b52a073 100644
--- a/libs/typescript/cua-cli/README.md
+++ b/libs/typescript/cua-cli/README.md
@@ -17,22 +17,40 @@ bun run ./index.ts -- --help
## Commands
- **Auth**
- - `cua auth login` – opens browser to authorize; stores API key locally
- - `cua auth login --api-key sk-...` – stores provided key directly
- - `cua auth pull` – writes/updates `.env` with `CUA_API_KEY`
- - `cua auth logout` – clears stored API key
+ - `cua login` – opens browser to authorize; stores API key locally
+ - `cua login --api-key sk-...` – stores provided key directly
+ - `cua env` – writes/updates `.env` with `CUA_API_KEY`
+ - `cua logout` – clears stored API key
- **Sandboxes**
- - `cua sandbox list` (aliases: `ls`, `ps`)
- - `cua sandbox create --os OS --configuration SIZE --region REGION` – creates a new sandbox
- - OS: `linux`, `windows`, `macos`
- - SIZE: `small`, `medium`, `large`
- - REGION: `north-america`, `europe`, `asia-pacific`, `south-america`
- - `cua sandbox delete NAME` – deletes a sandbox
- - `cua sandbox start NAME`
- - `cua sandbox stop NAME`
- - `cua sandbox restart NAME`
- - `cua sandbox open NAME` – opens NoVNC URL in your browser
+
+ The CLI supports both **flat** and **grouped** command styles:
+
+ ```bash
+ # Flat style (quick & concise)
+ cua list
+ cua create --os linux --configuration small --region north-america
+ cua start <name>
+ cua stop <name>
+
+ # Grouped style (explicit & organized)
+ cua sandbox list # or: cua sb list
+ cua sandbox create # or: cua sb create
+ cua sandbox start # or: cua sb start
+ cua sandbox stop # or: cua sb stop
+ ```
+
+ **Available Commands:**
+ - `list` (aliases: `ls`, `ps`) – list all sandboxes
+ - `create` – create a new sandbox
+ - `--os`: `linux`, `windows`, `macos`
+ - `--configuration`: `small`, `medium`, `large`
+ - `--region`: `north-america`, `europe`, `asia-pacific`, `south-america`
+ - `delete <name>` – delete a sandbox
+ - `start <name>` – start a stopped sandbox
+ - `stop <name>` – stop a running sandbox
+ - `restart <name>` – restart a sandbox
+ - `open <name>` – open NoVNC URL in your browser
## Auth Flow (Dynamic Callback Port)
diff --git a/libs/typescript/cua-cli/src/commands/sandbox.ts b/libs/typescript/cua-cli/src/commands/sandbox.ts
index fa1f23ba9a..550c83f39a 100644
--- a/libs/typescript/cua-cli/src/commands/sandbox.ts
+++ b/libs/typescript/cua-cli/src/commands/sandbox.ts
@@ -6,33 +6,235 @@ import { clearApiKey } from '../storage';
import type { SandboxItem } from '../util';
import { openInBrowser, printSandboxList } from '../util';
+// Command handlers
+const listHandler = async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const res = await http('/v1/vms', { token });
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+ if (!res.ok) {
+ console.error(`Request failed: ${res.status}`);
+ process.exit(1);
+ }
+ const data = (await res.json()) as SandboxItem[];
+ printSandboxList(data, Boolean(argv['show-passwords']));
+};
+
+const createHandler = async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const { os, configuration, region } = argv as {
+ os: string;
+ configuration: string;
+ region: string;
+ };
+
+ const res = await http('/v1/vms', {
+ token,
+ method: 'POST',
+ body: { os, configuration, region },
+ });
+
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+
+ if (res.status === 400) {
+ console.error('Invalid request or unsupported configuration');
+ process.exit(1);
+ }
+
+ if (res.status === 500) {
+ console.error('Internal server error');
+ process.exit(1);
+ }
+
+ if (res.status === 200) {
+ const data = (await res.json()) as {
+ status: string;
+ name: string;
+ password: string;
+ host: string;
+ };
+ console.log(`Sandbox created and ready: ${data.name}`);
+ console.log(`Password: ${data.password}`);
+ console.log(`Host: ${data.host}`);
+ return;
+ }
+
+ if (res.status === 202) {
+ const data = (await res.json()) as {
+ status: string;
+ name: string;
+ job_id: string;
+ };
+ console.log(`Sandbox provisioning started: ${data.name}`);
+ console.log(`Job ID: ${data.job_id}`);
+ console.log("Use 'cua list' to monitor provisioning progress");
+ return;
+ }
+
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+};
+
+const deleteHandler = async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}`, {
+ token,
+ method: 'DELETE',
+ });
+
+ if (res.status === 202) {
+ const body = (await res.json().catch(() => ({}))) as {
+ status?: string;
+ };
+ console.log(
+ `Sandbox deletion initiated: ${body.status ?? 'deleting'}`
+ );
+ return;
+ }
+
+ if (res.status === 404) {
+ console.error('Sandbox not found or not owned by you');
+ process.exit(1);
+ }
+
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+};
+
+const startHandler = async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}/start`, {
+ token,
+ method: 'POST',
+ });
+ if (res.status === 204) {
+ console.log('Start accepted');
+ return;
+ }
+ if (res.status === 404) {
+ console.error('Sandbox not found');
+ process.exit(1);
+ }
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+};
+
+const stopHandler = async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}/stop`, {
+ token,
+ method: 'POST',
+ });
+ if (res.status === 202) {
+ const body = (await res.json().catch(() => ({}))) as {
+ status?: string;
+ };
+ console.log(body.status ?? 'stopping');
+ return;
+ }
+ if (res.status === 404) {
+ console.error('Sandbox not found');
+ process.exit(1);
+ }
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+};
+
+const restartHandler = async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const res = await http(`/v1/vms/${encodeURIComponent(name)}/restart`, {
+ token,
+ method: 'POST',
+ });
+ if (res.status === 202) {
+ const body = (await res.json().catch(() => ({}))) as {
+ status?: string;
+ };
+ console.log(body.status ?? 'restarting');
+ return;
+ }
+ if (res.status === 404) {
+ console.error('Sandbox not found');
+ process.exit(1);
+ }
+ if (res.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+ console.error(`Unexpected status: ${res.status}`);
+ process.exit(1);
+};
+
+const openHandler = async (argv: Record<string, unknown>) => {
+ const token = await ensureApiKeyInteractive();
+ const name = String((argv as any).name);
+ const listRes = await http('/v1/vms', { token });
+ if (listRes.status === 401) {
+ clearApiKey();
+ console.error("Unauthorized. Try 'cua login' again.");
+ process.exit(1);
+ }
+ if (!listRes.ok) {
+ console.error(`Request failed: ${listRes.status}`);
+ process.exit(1);
+ }
+ const sandboxes = (await listRes.json()) as SandboxItem[];
+ const sandbox = sandboxes.find((s) => s.name === name);
+ if (!sandbox) {
+ console.error('Sandbox not found');
+ process.exit(1);
+ }
+ const host =
+ sandbox.host && sandbox.host.length
+ ? sandbox.host
+ : `${sandbox.name}.containers.cloud.trycua.com`;
+ const url = `https://${host}/vnc.html?autoconnect=true&password=${encodeURIComponent(sandbox.password)}`;
+ console.log(`Opening NoVNC: ${url}`);
+ await openInBrowser(url);
+};
+
+// Register commands in both flat and grouped structures
export function registerSandboxCommands(y: Argv) {
- return y
- .command(
- ['list', 'ls', 'ps'],
- 'List sandboxes',
- (y) =>
- y.option('show-passwords', {
- type: 'boolean',
- default: false,
- describe: 'Show sandbox passwords in output',
- }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const res = await http('/v1/vms', { token });
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- if (!res.ok) {
- console.error(`Request failed: ${res.status}`);
- process.exit(1);
- }
- const data = (await res.json()) as SandboxItem[];
- printSandboxList(data, Boolean(argv['show-passwords']));
- }
- )
+ // Flat structure (backwards compatible)
+ y.command(
+ ['list', 'ls', 'ps'],
+ 'List sandboxes',
+ (y) =>
+ y.option('show-passwords', {
+ type: 'boolean',
+ default: false,
+ describe: 'Show sandbox passwords in output',
+ }),
+ listHandler
+ )
.command(
'create',
'Create a new sandbox',
@@ -61,257 +263,120 @@ export function registerSandboxCommands(y: Argv) {
demandOption: true,
describe: 'Sandbox region',
}),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const { os, configuration, region } = argv as {
- os: string;
- configuration: string;
- region: string;
- };
-
- const res = await http('/v1/vms', {
- token,
- method: 'POST',
- body: { os, configuration, region },
- });
-
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
-
- if (res.status === 400) {
- console.error('Invalid request or unsupported configuration');
- process.exit(1);
- }
-
- if (res.status === 500) {
- console.error('Internal server error');
- process.exit(1);
- }
-
- if (res.status === 200) {
- // Sandbox ready immediately
- const data = (await res.json()) as {
- status: string;
- name: string;
- password: string;
- host: string;
- };
- console.log(`Sandbox created and ready: ${data.name}`);
- console.log(`Password: ${data.password}`);
- console.log(`Host: ${data.host}`);
- return;
- }
-
- if (res.status === 202) {
- // Sandbox provisioning started
- const data = (await res.json()) as {
- status: string;
- name: string;
- job_id: string;
- };
- console.log(`Sandbox provisioning started: ${data.name}`);
- console.log(`Job ID: ${data.job_id}`);
- console.log("Use 'cua list' to monitor provisioning progress");
- return;
- }
-
- console.error(`Unexpected status: ${res.status}`);
- process.exit(1);
- }
+ createHandler
)
.command(
'delete <name>',
'Delete a sandbox',
(y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(`/v1/vms/${encodeURIComponent(name)}`, {
- token,
- method: 'DELETE',
- });
-
- if (res.status === 202) {
- const body = (await res.json().catch(() => ({}))) as {
- status?: string;
- };
- console.log(
- `Sandbox deletion initiated: ${body.status ?? 'deleting'}`
- );
- return;
- }
-
- if (res.status === 404) {
- console.error('Sandbox not found or not owned by you');
- process.exit(1);
- }
-
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
-
- console.error(`Unexpected status: ${res.status}`);
- process.exit(1);
- }
+ deleteHandler
)
.command(
'start <name>',
'Start a sandbox',
(y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(`/v1/vms/${encodeURIComponent(name)}/start`, {
- token,
- method: 'POST',
- });
- if (res.status === 204) {
- console.log('Start accepted');
- return;
- }
- if (res.status === 404) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- console.error(`Unexpected status: ${res.status}`);
- process.exit(1);
- }
+ startHandler
)
.command(
'stop <name>',
'Stop a sandbox',
(y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(`/v1/vms/${encodeURIComponent(name)}/stop`, {
- token,
- method: 'POST',
- });
- if (res.status === 202) {
- const body = (await res.json().catch(() => ({}))) as {
- status?: string;
- };
- console.log(body.status ?? 'stopping');
- return;
- }
- if (res.status === 404) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- console.error(`Unexpected status: ${res.status}`);
- process.exit(1);
- }
+ stopHandler
)
.command(
'restart <name>',
'Restart a sandbox',
(y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const res = await http(`/v1/vms/${encodeURIComponent(name)}/restart`, {
- token,
- method: 'POST',
- });
- if (res.status === 202) {
- const body = (await res.json().catch(() => ({}))) as {
- status?: string;
- };
- console.log(body.status ?? 'restarting');
- return;
- }
- if (res.status === 404) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- if (res.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- console.error(`Unexpected status: ${res.status}`);
- process.exit(1);
- }
+ restartHandler
)
.command(
'open <name>',
'Open NoVNC for a sandbox in your browser',
(y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- async (argv: Record<string, unknown>) => {
- const token = await ensureApiKeyInteractive();
- const name = String((argv as any).name);
- const listRes = await http('/v1/vms', { token });
- if (listRes.status === 401) {
- clearApiKey();
- console.error("Unauthorized. Try 'cua login' again.");
- process.exit(1);
- }
- if (!listRes.ok) {
- console.error(`Request failed: ${listRes.status}`);
- process.exit(1);
- }
- const sandboxes = (await listRes.json()) as SandboxItem[];
- const sandbox = sandboxes.find((s) => s.name === name);
- if (!sandbox) {
- console.error('Sandbox not found');
- process.exit(1);
- }
- const host =
- sandbox.host && sandbox.host.length
- ? sandbox.host
- : `${sandbox.name}.containers.cloud.trycua.com`;
- const url = `https://${host}/vnc.html?autoconnect=true&password=${encodeURIComponent(sandbox.password)}`;
- console.log(`Opening NoVNC: ${url}`);
- await openInBrowser(url);
- }
+ openHandler
);
- // .command(
- // 'chat <name>',
- // 'Open CUA playground for a sandbox',
- // (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
- // async (argv: Record<string, unknown>) => {
- // const token = await ensureApiKeyInteractive();
- // const name = String((argv as any).name);
- // const listRes = await http('/v1/vms', { token });
- // if (listRes.status === 401) {
- // clearApiKey();
- // console.error("Unauthorized. Try 'cua login' again.");
- // process.exit(1);
- // }
- // if (!listRes.ok) {
- // console.error(`Request failed: ${listRes.status}`);
- // process.exit(1);
- // }
- // const sandboxes = (await listRes.json()) as SandboxItem[];
- // const sandbox = sandboxes.find((s) => s.name === name);
- // if (!sandbox) {
- // console.error('Sandbox not found');
- // process.exit(1);
- // }
- // const host =
- // sandbox.host && sandbox.host.length
- // ? sandbox.host
- // : `${sandbox.name}.containers.cloud.trycua.com`;
- // const base = WEBSITE_URL.replace(/\/$/, '');
- // const url = `${base}/dashboard/playground?host=${encodeURIComponent(host)}&id=${encodeURIComponent(sandbox.name)}&name=${encodeURIComponent(sandbox.name)}&vnc_password=${encodeURIComponent(sandbox.password)}&fullscreen=true`;
- // console.log(`Opening Playground: ${url}`);
- // await openInBrowser(url);
- // }
- // );
+
+ // Grouped structure: cua sandbox <command> or cua sb <command>
+ y.command(
+ ['sandbox', 'sb'],
+ 'Manage sandboxes',
+ (y) => {
+ return y
+ .command(
+ ['list', 'ls', 'ps'],
+ 'List sandboxes',
+ (y) =>
+ y.option('show-passwords', {
+ type: 'boolean',
+ default: false,
+ describe: 'Show sandbox passwords in output',
+ }),
+ listHandler
+ )
+ .command(
+ 'create',
+ 'Create a new sandbox',
+ (y) =>
+ y
+ .option('os', {
+ type: 'string',
+ choices: ['linux', 'windows', 'macos'],
+ demandOption: true,
+ describe: 'Operating system',
+ })
+ .option('configuration', {
+ type: 'string',
+ choices: ['small', 'medium', 'large'],
+ demandOption: true,
+ describe: 'Sandbox size configuration',
+ })
+ .option('region', {
+ type: 'string',
+ choices: [
+ 'north-america',
+ 'europe',
+ 'asia-pacific',
+ 'south-america',
+ ],
+ demandOption: true,
+ describe: 'Sandbox region',
+ }),
+ createHandler
+ )
+ .command(
+ 'delete <name>',
+ 'Delete a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ deleteHandler
+ )
+ .command(
+ 'start <name>',
+ 'Start a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ startHandler
+ )
+ .command(
+ 'stop <name>',
+ 'Stop a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ stopHandler
+ )
+ .command(
+ 'restart <name>',
+ 'Restart a sandbox',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ restartHandler
+ )
+ .command(
+ 'open <name>',
+ 'Open NoVNC for a sandbox in your browser',
+ (y) => y.positional('name', { type: 'string', describe: 'Sandbox name' }),
+ openHandler
+ )
+ .demandCommand(1, 'You must provide a sandbox command');
+ },
+ () => {}
+ );
+
+ return y;
}