Skip to content

An open-source, faster Devin alternative

TypeScript

add cli docs

Brian Reardon87628d99a87f
diff --git a/docs/cli/checkpoints.mdx b/docs/cli/checkpoints.mdx
new file mode 100644
index 00000000..41f863f6
--- /dev/null
+++ b/docs/cli/checkpoints.mdx
@@ -0,0 +1,130 @@
+---
+title: "Checkpoints"
+description: "Snapshot, fork, and restore sandboxes"
+---
+
+Checkpoints capture the full state of a sandbox — memory, disk, and running processes — so you can restore it later or spin up multiple clones from the same point in time.
+
+## Create a Checkpoint
+
+```bash
+oc checkpoint create sb-abc123 --name my-checkpoint
+```
+
+### `oc checkpoint create <sandbox-id>`
+
+Snapshots the current state of a running sandbox and uploads it to S3.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--name` | string | — | Checkpoint name (required) |
+
+Output:
+
+```
+Checkpoint created: cp-7f3a1b2c (status: ready)
+Name: my-checkpoint
+```
+
+## List Checkpoints
+
+```bash
+oc checkpoint list sb-abc123
+```
+
+### `oc checkpoint list <sandbox-id>`
+
+Lists all checkpoints associated with a sandbox.
+
+Output:
+
+```
+ID NAME STATUS SIZE CREATED
+cp-7f3a1b2c my-checkpoint ready 843.2 MB 2024-01-15T10:30:00Z
+cp-2d9e4a1f before-deploy ready 801.5 MB 2024-01-14T09:00:00Z
+```
+
+## Restore a Sandbox
+
+```bash
+oc checkpoint restore sb-abc123 cp-7f3a1b2c
+```
+
+### `oc checkpoint restore <sandbox-id> <checkpoint-id>`
+
+Reverts an existing sandbox in-place to the state captured in the checkpoint. All changes made after the checkpoint was created are discarded.
+
+## Spawn a New Sandbox from a Checkpoint
+
+```bash
+oc checkpoint spawn cp-7f3a1b2c
+```
+
+Or with a custom timeout:
+
+```bash
+oc checkpoint spawn cp-7f3a1b2c --timeout 600
+```
+
+### `oc checkpoint spawn <checkpoint-id>`
+
+Creates a brand-new sandbox from an existing checkpoint, leaving the original sandbox untouched. Useful for forking — run the same starting state in parallel.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--timeout` | int | `300` | TTL for the new sandbox in seconds |
+
+## Delete a Checkpoint
+
+```bash
+oc checkpoint delete sb-abc123 cp-7f3a1b2c
+```
+
+### `oc checkpoint delete <sandbox-id> <checkpoint-id>`
+
+Permanently removes a checkpoint and its stored data from S3.
+
+## Alias
+
+`oc checkpoint` can also be invoked as `oc cp`:
+
+```bash
+oc cp create sb-abc123 --name quick-save
+oc cp list sb-abc123
+```
+
+## Examples
+
+### Save State Before a Risky Operation
+
+```bash
+oc checkpoint create sb-abc123 --name before-migration
+oc exec sb-abc123 -- ./run-migration.sh
+
+# Something went wrong — roll back
+oc checkpoint restore sb-abc123 cp-7f3a1b2c
+```
+
+### Fork a Sandbox for Parallel Testing
+
+```bash
+# Create a checkpoint with a known-good state
+oc checkpoint create sb-abc123 --name test-base
+
+# Spawn two independent sandboxes from it
+ID1=$(oc checkpoint spawn cp-7f3a1b2c --json | jq -r '.id')
+ID2=$(oc checkpoint spawn cp-7f3a1b2c --json | jq -r '.id')
+
+# Run different experiments in each
+oc exec $ID1 -- ./experiment-a.sh
+oc exec $ID2 -- ./experiment-b.sh
+```
+
+### Checkpoint vs Hibernate
+
+| | Checkpoint | Hibernate |
+| --- | --- | --- |
+| Original sandbox | Keeps running | Stopped |
+| Can fork / clone | Yes | No |
+| Restore target | Any sandbox | Same sandbox only |
+| Use case | Branching, testing | Pause and resume |
diff --git a/docs/cli/commands.mdx b/docs/cli/commands.mdx
new file mode 100644
index 00000000..20da30b7
--- /dev/null
+++ b/docs/cli/commands.mdx
@@ -0,0 +1,92 @@
+---
+title: "Commands"
+description: "Execute shell commands inside a sandbox"
+---
+
+The `exec` command runs a shell command inside a sandbox and captures its output. The CLI exits with the same exit code as the remote command.
+
+## Running a Command
+
+```bash
+oc exec sb-abc123 -- echo "Hello, World!"
+```
+
+Output:
+
+```
+Hello, World!
+```
+
+### `oc exec <id> -- <command...>`
+
+Executes a shell command and waits for it to complete. Everything after `--` is joined into the command string.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--cwd` | string | — | Working directory for the command |
+| `--timeout` | int | `60` | Maximum execution time in seconds |
+| `--env` | string | — | Environment variable (`KEY=VALUE`, repeatable) |
+
+**Default output:** Prints stdout and stderr directly to your terminal, then exits with the remote exit code.
+
+**JSON output (`--json`):** Returns the full `ProcessResult` object.
+
+## ProcessResult
+
+When using `--json`, the output includes:
+
+| Field | Type | Description |
+| --- | --- | --- |
+| `exitCode` | number | Exit code of the process (0 = success) |
+| `stdout` | string | Standard output |
+| `stderr` | string | Standard error |
+
+## Examples
+
+### Run with a Working Directory
+
+```bash
+oc exec sb-abc123 --cwd /app -- ls -la
+```
+
+### Run with Environment Variables
+
+```bash
+oc exec sb-abc123 --env MY_VAR=hello -- echo $MY_VAR
+```
+
+### Run with a Timeout
+
+```bash
+oc exec sb-abc123 --timeout 5 -- sleep 30
+# Killed after 5 seconds, non-zero exit code
+```
+
+### Check for Errors
+
+```bash
+oc exec sb-abc123 -- python3 script.py
+if [ $? -ne 0 ]; then
+ echo "Command failed"
+fi
+```
+
+### Chain Commands
+
+```bash
+oc exec sb-abc123 -- bash -c 'cd /app && npm install && npm run build'
+```
+
+### Capture Output as JSON
+
+```bash
+RESULT=$(oc exec sb-abc123 --json -- node -e 'console.log("hello")')
+echo $RESULT | jq '.stdout'
+```
+
+### Install Packages
+
+```bash
+oc exec sb-abc123 -- apt update
+oc exec sb-abc123 -- apt install -y python3 nodejs
+```
diff --git a/docs/cli/overview.mdx b/docs/cli/overview.mdx
new file mode 100644
index 00000000..2671150f
--- /dev/null
+++ b/docs/cli/overview.mdx
@@ -0,0 +1,102 @@
+---
+title: "CLI Reference"
+description: "Full reference for the oc command-line interface"
+---
+
+The `oc` CLI lets you manage OpenComputer sandboxes directly from your terminal — create sandboxes, run commands, open interactive shells, manage checkpoints, and more.
+
+## Installation
+
+```bash
+# Build from source
+make build-oc
+
+# Install to /usr/local/bin
+make install-oc
+```
+
+Or with `go install`:
+
+```bash
+go install github.com/opensandbox/opensandbox/cmd/oc@latest
+```
+
+## Configuration
+
+Set your API key (stored in `~/.oc/config.json`):
+
+```bash
+oc config set api-key YOUR_API_KEY
+```
+
+Optionally set a custom API URL:
+
+```bash
+oc config set api-url https://app.opencomputer.dev
+```
+
+View current configuration:
+
+```bash
+oc config show
+```
+
+### Resolution Order
+
+Configuration values are resolved in this order (highest priority first):
+
+| Priority | Source | Example |
+| --- | --- | --- |
+| 1 (highest) | CLI flags | `--api-key=xxx` |
+| 2 | Environment variables | `OPENCOMPUTER_API_KEY` |
+| 3 | Config file | `~/.oc/config.json` |
+| 4 (lowest) | Defaults | `https://app.opencomputer.dev` |
+
+## Global Flags
+
+Every command supports these flags:
+
+| Flag | Environment Variable | Description |
+| --- | --- | --- |
+| `--api-key` | `OPENCOMPUTER_API_KEY` | API key for authentication |
+| `--api-url` | `OPENCOMPUTER_API_URL` | Control plane URL |
+| `--json` | — | Output as JSON instead of tables |
+
+## Quick Example
+
+```bash
+# Create a sandbox
+oc create
+
+# Run a command
+oc exec sb-abc123 -- echo "Hello from the cloud"
+
+# Open an interactive shell
+oc shell sb-abc123
+
+# Clean up
+oc sandbox kill sb-abc123
+```
+
+## Modules
+
+| Module | Description |
+| --- | --- |
+| [Sandbox](/cli/sandbox) | Create, list, and manage sandbox lifecycles |
+| [Commands](/cli/commands) | Execute shell commands in a sandbox |
+| [Shell](/cli/shell) | Interactive PTY terminal sessions |
+| [Checkpoints](/cli/checkpoints) | Snapshot, fork, and restore sandboxes |
+| [Patches](/cli/patches) | Apply scripted modifications to checkpoints |
+| [Preview URLs](/cli/previews) | Expose sandbox ports to the internet |
+
+## JSON Output
+
+Every command supports `--json` for machine-readable output, making it easy to script with `jq`:
+
+```bash
+# Get a sandbox ID programmatically
+ID=$(oc create --json | jq -r '.sandboxID')
+
+# List all running sandbox IDs
+oc ls --json | jq -r '.[].sandboxID'
+```
diff --git a/docs/cli/patches.mdx b/docs/cli/patches.mdx
new file mode 100644
index 00000000..56da9b2b
--- /dev/null
+++ b/docs/cli/patches.mdx
@@ -0,0 +1,96 @@
+---
+title: "Patches"
+description: "Apply scripted modifications when spawning sandboxes from a checkpoint"
+---
+
+Patches are shell scripts attached to a checkpoint. When a new sandbox is spawned from that checkpoint, all patches are applied in sequence before the sandbox is handed back to you. This lets you layer additional setup on top of a base checkpoint without re-creating it.
+
+## Create a Patch
+
+From a file:
+
+```bash
+oc patch create cp-7f3a1b2c --script ./setup.sh --description "Install dependencies"
+```
+
+From stdin:
+
+```bash
+echo "apt install -y curl jq" | oc patch create cp-7f3a1b2c --script=-
+```
+
+### `oc patch create <checkpoint-id>`
+
+Attaches a patch script to a checkpoint. Patches run in the order they were created (by sequence number) whenever `oc checkpoint spawn` is called for that checkpoint.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--script` | string | — | Path to a shell script file, or `-` to read from stdin (required) |
+| `--description` | string | — | Human-readable description of what the patch does |
+
+Output:
+
+```
+Patch created: patch-3c8d2e1a (sequence: 1)
+```
+
+## List Patches
+
+```bash
+oc patch list cp-7f3a1b2c
+```
+
+### `oc patch list <checkpoint-id>`
+
+Shows all patches attached to a checkpoint, in the order they will be applied.
+
+Output:
+
+```
+ID SEQ DESCRIPTION STRATEGY CREATED
+patch-3c8d2e1a 1 Install dependencies 2024-01-15T10:35:00Z
+patch-9a1f4b7c 2 Configure environment 2024-01-15T10:40:00Z
+```
+
+## Delete a Patch
+
+```bash
+oc patch delete cp-7f3a1b2c patch-3c8d2e1a
+```
+
+### `oc patch delete <checkpoint-id> <patch-id>`
+
+Removes a patch from the checkpoint. Future spawns will no longer apply it. Existing sandboxes already spawned are unaffected.
+
+## Examples
+
+### Layer Setup Steps onto a Base Checkpoint
+
+```bash
+# Start with a minimal checkpoint
+oc checkpoint create sb-abc123 --name base
+
+# Add patches for each layer of setup
+oc patch create cp-7f3a1b2c --script ./install-node.sh --description "Node.js 20"
+oc patch create cp-7f3a1b2c --script ./install-postgres.sh --description "PostgreSQL client"
+oc patch create cp-7f3a1b2c --script ./app-config.sh --description "App config"
+
+# Each spawned sandbox gets all three patches applied in order
+oc checkpoint spawn cp-7f3a1b2c
+```
+
+### Use stdin for Quick One-Liners
+
+```bash
+echo "npm install -g typescript" | oc patch create cp-7f3a1b2c --script=- --description "Global TypeScript"
+```
+
+### Inspect Before Spawning
+
+```bash
+# Review the patches that will run
+oc patch list cp-7f3a1b2c
+
+# Spawn knowing exactly what will be applied
+oc checkpoint spawn cp-7f3a1b2c
+```
diff --git a/docs/cli/previews.mdx b/docs/cli/previews.mdx
new file mode 100644
index 00000000..acb68a33
--- /dev/null
+++ b/docs/cli/previews.mdx
@@ -0,0 +1,104 @@
+---
+title: "Preview URLs"
+description: "Expose sandbox ports to the internet"
+---
+
+Preview URLs give a sandbox port a publicly accessible HTTPS hostname. This lets you share a running web server, API, or any TCP service without any networking configuration.
+
+## Create a Preview URL
+
+```bash
+oc preview create sb-abc123 --port 3000
+```
+
+With a custom domain:
+
+```bash
+oc preview create sb-abc123 --port 8080 --domain preview.example.com
+```
+
+### `oc preview create <sandbox-id>`
+
+Provisions a public HTTPS URL that proxies traffic to the specified port inside the sandbox.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--port` | int | — | Sandbox port to expose (required) |
+| `--domain` | string | — | Custom hostname to use instead of the generated one |
+
+Output:
+
+```
+Preview URL created:
+ Hostname: sb-abc123-3000.preview.opencomputer.dev
+ Port: 3000
+ SSL: active
+```
+
+## List Preview URLs
+
+```bash
+oc preview list sb-abc123
+```
+
+### `oc preview list <sandbox-id>`
+
+Shows all active preview URLs for a sandbox.
+
+Output:
+
+```
+PORT HOSTNAME SSL CREATED
+3000 sb-abc123-3000.preview.opencomputer.dev active 2024-01-15T10:30:00Z
+8080 preview.example.com active 2024-01-15T10:31:00Z
+```
+
+## Delete a Preview URL
+
+```bash
+oc preview delete sb-abc123 3000
+```
+
+### `oc preview delete <sandbox-id> <port>`
+
+Removes the preview URL for the given port. The sandbox keeps running; only the public URL is torn down.
+
+## Examples
+
+### Share a Dev Server
+
+```bash
+# Start a web server inside the sandbox
+oc exec sb-abc123 -- bash -c 'cd /app && npm run dev &'
+
+# Expose port 3000
+oc preview create sb-abc123 --port 3000
+
+# Share the URL with a teammate
+oc preview list sb-abc123 --json | jq -r '.[0].hostname'
+```
+
+### Expose Multiple Ports
+
+```bash
+# Frontend on 3000, API on 4000
+oc preview create sb-abc123 --port 3000
+oc preview create sb-abc123 --port 4000
+
+oc preview list sb-abc123
+```
+
+### Use a Custom Domain
+
+```bash
+oc preview create sb-abc123 --port 8080 --domain staging.myapp.com
+```
+
+> Custom domains require DNS to point to the OpenComputer ingress and may take a few minutes for SSL to become active.
+
+### Scripted: Create and Print URL
+
+```bash
+URL=$(oc preview create sb-abc123 --port 3000 --json | jq -r '.hostname')
+echo "Open: https://$URL"
+```
diff --git a/docs/cli/sandbox.mdx b/docs/cli/sandbox.mdx
new file mode 100644
index 00000000..0774d341
--- /dev/null
+++ b/docs/cli/sandbox.mdx
@@ -0,0 +1,137 @@
+---
+title: "Sandbox"
+description: "Create, list, and manage sandbox lifecycles"
+---
+
+The `sandbox` command group manages the full lifecycle of OpenComputer sandboxes. The most common operations — `create` and `ls` — are also available as top-level shortcuts.
+
+## Create a Sandbox
+
+```bash
+oc create
+```
+
+Or with options:
+
+```bash
+oc create --timeout 600 --cpu 2 --memory 2048 --env NODE_ENV=production
+```
+
+### `oc create`
+
+Alias for `oc sandbox create`. Creates a new sandbox and prints its ID.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--template` | string | `default` | Template to use |
+| `--timeout` | int | `300` | Sandbox TTL in seconds |
+| `--cpu` | int | `1` | Number of vCPUs |
+| `--memory` | int | `1024` | Memory in MB |
+| `--env` | string | — | Environment variable (`KEY=VALUE`, repeatable) |
+| `--metadata` | string | — | Metadata (`KEY=VALUE`, repeatable) |
+
+## List Sandboxes
+
+```bash
+oc ls
+```
+
+Output:
+
+```
+ID TEMPLATE STATUS CPU MEM AGE
+sb-e148d1b0 running 1 1024MB 2m30s
+sb-a3f91c27 running 2 2048MB 15m0s
+```
+
+### `oc ls`
+
+Alias for `oc sandbox list`. Lists all sandboxes for your organization.
+
+## Get Sandbox Details
+
+```bash
+oc sandbox get sb-abc123
+```
+
+### `oc sandbox get <id>`
+
+Displays detailed information about a sandbox including status, resources, and timestamps.
+
+## Kill a Sandbox
+
+```bash
+oc sandbox kill sb-abc123
+```
+
+### `oc sandbox kill <id>`
+
+Immediately terminates a sandbox. All data is lost unless a [checkpoint](/cli/checkpoints) was created.
+
+## Hibernate
+
+```bash
+oc sandbox hibernate sb-abc123
+```
+
+### `oc sandbox hibernate <id>`
+
+Saves the sandbox's full state (memory + disk) to S3 and stops the VM. The sandbox can be resumed later with `wake`.
+
+## Wake
+
+```bash
+oc sandbox wake sb-abc123
+```
+
+Or with a new timeout:
+
+```bash
+oc sandbox wake sb-abc123 --timeout 600
+```
+
+### `oc sandbox wake <id>`
+
+Resumes a hibernated sandbox. All processes and state are restored exactly as they were.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--timeout` | int | `300` | New TTL in seconds after waking |
+
+## Set Timeout
+
+```bash
+oc sandbox set-timeout sb-abc123 600
+```
+
+### `oc sandbox set-timeout <id> <seconds>`
+
+Updates the sandbox's idle timeout and resets the TTL countdown.
+
+## Examples
+
+### Create and Immediately Shell In
+
+```bash
+ID=$(oc create --json | jq -r '.sandboxID')
+oc shell $ID
+```
+
+### Hibernate and Resume Later
+
+```bash
+# Save state and stop
+oc sandbox hibernate sb-abc123
+
+# ... hours later ...
+
+# Resume exactly where you left off
+oc sandbox wake sb-abc123
+oc shell sb-abc123
+```
+
+### List Running Sandboxes as JSON
+
+```bash
+oc ls --json | jq '.[] | select(.status == "running") | .sandboxID'
+```
diff --git a/docs/cli/shell.mdx b/docs/cli/shell.mdx
new file mode 100644
index 00000000..68330137
--- /dev/null
+++ b/docs/cli/shell.mdx
@@ -0,0 +1,71 @@
+---
+title: "Shell"
+description: "Open an interactive terminal session in a sandbox"
+---
+
+The `shell` command opens a full interactive terminal inside a running sandbox. It connects via WebSocket and supports everything you'd expect from a local terminal — colors, tab completion, `vim`, `top`, and terminal resizing.
+
+## Opening a Shell
+
+```bash
+oc shell sb-abc123
+```
+
+You'll be dropped into a bash shell inside the sandbox. Press `Ctrl+D` or type `exit` to disconnect.
+
+### `oc shell <id>`
+
+Creates a PTY session and opens a bidirectional WebSocket connection to the sandbox.
+
+| Flag | Type | Default | Description |
+| --- | --- | --- | --- |
+| `--shell` | string | `/bin/bash` | Shell binary to use |
+
+## Using a Different Shell
+
+```bash
+oc shell sb-abc123 --shell /bin/zsh
+oc shell sb-abc123 --shell /bin/sh
+```
+
+## How It Works
+
+1. **Get sandbox info** — Fetches the sandbox's direct worker URL and auth token from the control plane
+2. **Create PTY** — Sends your terminal dimensions to the worker to create a PTY session
+3. **WebSocket connect** — Opens a persistent WebSocket to the worker for bidirectional I/O
+4. **Raw terminal mode** — Puts your local terminal into raw mode so keystrokes are forwarded directly
+5. **Resize handling** — Listens for `SIGWINCH` and sends resize events when you resize your terminal window
+6. **Cleanup** — On exit, restores your terminal, closes the WebSocket, and destroys the remote PTY session
+
+## Tips
+
+### Create and Shell In One Line
+
+```bash
+oc shell $(oc create --json | jq -r '.sandboxID')
+```
+
+### Interactive Tools Work
+
+Full-screen terminal applications work as expected:
+
+```bash
+# Inside the shell:
+top # Process monitor
+vim file.txt # Text editor
+htop # Interactive process viewer
+```
+
+### Terminal Resizing
+
+Resize your terminal window at any time — the remote PTY automatically adjusts to match your new dimensions.
+
+### When to Use Shell vs Exec
+
+| Use Case | Command |
+| --- | --- |
+| Run a single command and capture output | `oc exec` |
+| Script or automation | `oc exec` |
+| Interactive development | `oc shell` |
+| Debugging | `oc shell` |
+| Long-running interactive sessions | `oc shell` |