CLI quickstart
Drive CrowNest sandboxes from your terminal with the crownest CLI — create a sandbox, run commands, move files, export artifacts, and stream logs.
This quickstart walks you through the full sandbox lifecycle from your terminal: log in, create a sandbox, run a command, move files in and out, export an artifact, expose a preview, stream logs, and clean up.
Prerequisites
You need two things before you start.
- Node.js 18 or later, to install the
@crownest/clipackage. - A CrowNest API key, created in the dashboard at https://crownest.dev. See API keys for scopes and presets.
[!WARNING] The raw API key is shown once, at creation time. Copy it immediately and store it somewhere safe — you can't view it again later.
Install and log in
Install the CLI globally, then save your credentials.
-
Install the package. It provides the
crownestbinary.Terminal pnpm add -g @crownest/cli -
Log in with your API key. This saves credentials to
~/.crownest/config.json(or under$XDG_CONFIG_HOMEwhen set; override the location withCROWNEST_CONFIG_PATH).Terminal crownest login --api-key cn_live_...Running
crownest loginwithout--api-keyprints guidance instead. You can also skip the config file entirely and setCROWNEST_API_KEYin the environment.CROWNEST_API_URLoverrides the API endpoint (defaulthttps://api.crownest.dev).
Walk through the lifecycle
Each step uses the sandbox ID printed in step 1; substitute your own.
-
Create a sandbox. The command prints the new sandbox ID.
Terminal crownest sandboxes create --template pythonOutput sbx_a1b2c3d4Use
--project <prj_id>to create the sandbox in a specific project.crownest sandboxes listreturns your live sandboxes as JSON. -
Run a command with
exec. Everything after--runs inside the sandbox, and the CLI prints the finished command record as JSON.Terminal crownest exec sbx_a1b2c3d4 -- python -c 'print(40 + 2)'The JSON output includes the command's
id,status,exitCode,stdout, andstderr.crownest execis an alias ofcrownest commands run.[!IMPORTANT] The CLI's own exit code reports whether execution succeeded:
0for success,1for errors, and2for usage errors. A command that runs to completion with a non-zero exit code still exits0— inspectexitCodein the JSON output to check whether your command failed. -
Upload and read files. All paths are inside
/workspace, the sandbox's working filesystem area.Terminal crownest files upload sbx_a1b2c3d4 ./data.csv --to data.csv crownest files write sbx_a1b2c3d4 notes.txt "hello from crownest" crownest files read sbx_a1b2c3d4 notes.txtOutput hello from crownestfiles readwrites the raw file content to stdout, so you can pipe it. Related commands:files list,files stat,files mkdir,files move, andfiles delete— see the CLI reference. -
Export an artifact. The workspace disappears with the sandbox, so copy anything you want to keep to durable storage. The command prints the artifact ID.
Terminal crownest artifacts create sbx_a1b2c3d4 notes.txt --name notesOutput art_e5f6g7h8Download it later — even after the sandbox is gone — with
crownest artifacts download art_e5f6g7h8 --output ./notes.txt. -
Expose a preview. Start an HTTP server in the background with
commands start, then create a preview for its port. The command prints the authenticated preview URL.Terminal crownest commands start sbx_a1b2c3d4 -- python -m http.server 8000 crownest previews create sbx_a1b2c3d4 --port 8000Output https://p-a1b2c3.preview.crownest.devPreviews require authentication in v1; see Previews. Revoke one with
crownest previews revoke <preview-id>. -
Stream logs.
crownest logsfollows a command's output live until it reaches a terminal state — useful with long-running commands launched bycommands start. The JSON printed byexecandcommands startincludes the command ID.Terminal crownest logs cmd_i9j0k1l2You can also scope by sandbox:
crownest logs sbx_a1b2c3d4 --command cmd_i9j0k1l2. Cancel a running command withcrownest commands cancel cmd_i9j0k1l2(add--forceto skip graceful shutdown). -
Kill the sandbox. This stops billing and releases the environment. The command prints the sandbox ID and its new status.
Terminal crownest sandboxes kill sbx_a1b2c3d4Output sbx_a1b2c3d4 destroyedSandboxes also expire automatically at their TTL — see Sandboxes.
Next steps
- Browse every command and flag in the CLI reference.
- Learn how lifetimes, templates, and statuses work in Sandboxes.
- Understand log streaming and collection in Commands.
- Build programmatically with the TypeScript SDK quickstart or the Python SDK quickstart.