> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vers.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Branching quickstart

> Start a computer, mutate live state, checkpoint it, branch parallel copies, and sleep idle VMs in 3 minutes.

Vers computers are full Linux microVMs whose CPU, memory, running processes,
and root filesystem can be captured into a portable checkpoint and restored
into parallel branches.

> [!TIP]
>
> Want to try Vers with zero signup first? Run `ssh try.vers.sh` to open an
> ephemeral trial shell. For the full CLI and `/api/v2` branching workflow below,
> [install the CLI](https://docs.vers.sh/installation.md) and export `VERS_API_KEY`.

**1. Warm start a computer from an OCI image**

Start a detached Ubuntu computer with a workload that stays alive, then
confirm it reaches `running`:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
computer_id="$(vers run --detach --name branch-base ubuntu:24.04 -- sleep infinity)"
vers get "$computer_id"
```

**2. Mutate live filesystem and process state**

Use `vers exec` to write a file and launch a background process inside the
computer. Pass `--keep-background` so background children continue running
after `vers exec` exits:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers exec --keep-background "$computer_id" -- sh -c '
  echo "base-v1" > /tmp/state.txt
  nohup sh -c "while true; do date -u >> /tmp/heartbeat.log; sleep 5; done" >/dev/null 2>&1 &
'
```

Verify that both the file and the live process exist:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers exec "$computer_id" -- sh -c 'cat /tmp/state.txt && cat /tmp/heartbeat.log'
```

**3. Capture a full-state checkpoint and branch in parallel**

Capture CPU, memory, device, process, and disk state into a portable
checkpoint:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
checkpoint_id="$(vers checkpoint "$computer_id" --name base-v1 --json | jq -r '.checkpoint_id')"
echo "Checkpoint: $checkpoint_id"
```

### Fan out parallel branches via `POST /api/v2/branches`

The standalone CLI does not include a `vers branch` subcommand; to fan out
multiple parallel computers from one checkpoint (or directly from a running
computer) in a single call, call `POST /api/v2/branches`:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
curl -fsSL -X POST https://api.vers.sh/api/v2/branches \
  -H "Authorization: Bearer $VERS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "source": {
      "type": "checkpoint",
      "checkpoint_id": "'"$checkpoint_id"'"
    },
    "count": 3
  }'
```

`POST /api/v2/branches` returns `201 Created` with the newly started computers:

```json theme={"theme":{"light":"min-light","dark":"min-dark"}}
{
  "computers": [
    {
      "computer_id": "2c8d0f7e-...",
      "ip": "10.0.0.12",
      "name": null,
      "volume_backend": "cowfswal"
    }
  ],
  "error": null
}
```

> [!NOTE]
>
> You can also branch directly from a running computer without a separate
> checkpoint step by setting `"source": { "type": "computer", "computer_id": "<uuid>" }`.

### Restore a single branch with durable idempotency

For a single branch from the CLI, use `vers restore`:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
branch_id="$(vers restore "$checkpoint_id" --name branch-a --json | jq -r '.computer_id')"
```

Programmatic callers that want durable, retry-safe admission can call
`POST /api/v2/computers` directly with a UUID `Idempotency-Key` header. Vers
answers `202 Accepted` with a durable `Operation` you can poll via
`GET /api/v2/operations/{operation_id}` (or follow with
`vers operation wait <operation_id>`):

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
op_id="$(uuidgen | tr '[:upper:]' '[:lower:]')"

curl -fsSL -X POST https://api.vers.sh/api/v2/computers \
  -H "Authorization: Bearer $VERS_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $op_id" \
  -d '{
    "source": {
      "type": "checkpoint",
      "checkpoint_id": "'"$checkpoint_id"'"
    },
    "labels": {
      "name": "branch-b"
    }
  }'

# Poll until .status == "succeeded" (computer ID is in .result.id)
curl -fsSL "https://api.vers.sh/api/v2/operations/$op_id" \
  -H "Authorization: Bearer $VERS_API_KEY"
```

Confirm that a branched computer resumes with both `/tmp/state.txt` and the
running heartbeat process intact — completely isolated from the original and
other branches:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers exec "$branch_id" -- sh -c '
  echo "branch-a" >> /tmp/state.txt
  cat /tmp/state.txt
  tail -n 3 /tmp/heartbeat.log
'
```

**4. Sleep idle computers and wake on demand**

When a computer is idle, put it to sleep to drop compute billing to `$0`
(only storage applies) while preserving its live memory, processes, and disk:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers sleep "$computer_id"
```

Wake the exact same computer whenever you need it again:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers wake "$computer_id"
```

Commands that need a running computer (`vers exec`, `vers cat`, `vers write`,
`vers logs`, `vers workload-logs`, and `vers ssh-key`) also wake a sleeping
computer automatically unless you pass `--no-wake`.

**5. Clean up**

Delete the computers you created, then remove the checkpoint once no computers
depend on it:

```bash theme={"theme":{"light":"min-light","dark":"min-dark"}}
vers delete "$branch_id" --yes
vers delete "$computer_id" --yes
vers checkpoint delete "$checkpoint_id" --yes
```

> [!NOTE]
>
> Need to branch an entire multi-service stack (like an app plus seeded Postgres)?
> See the [Multi-VM project networks](https://docs.vers.sh/guides/project-networks.md) guide for private
> `<service>.internal` DNS and whole-stack restores.

## Next steps

> [card] [Python & TypeScript cookbook](https://docs.vers.sh/guides/python-and-typescript.md)
>
> Copy reusable `/api/v2` helpers for branching, exec, and streaming events.

> [card] [Multi-VM project networks](https://docs.vers.sh/guides/project-networks.md)
>
> Put up to 253 VMs on a private network and branch the full stack together.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.