# CLI

The CLI is the quickest way to see what Flashbox does: every line you type runs as one command in a sandbox, the way an agent's tool calls would, and after each one you see how long it took and what it cost.

```sh
npx flashbox demo     # watch a scripted agent session
npx flashbox          # a session of your own
```

It needs Node 18 or newer. To keep it around: `npm install -g flashbox`, then run `flashbox`.

## Signing in

The first run opens your browser on the dashboard with a code to approve (sign in with GitHub if you have not). Check the code matches your terminal and approve it; the CLI gets an API key of its own, named "CLI" in the dashboard, and keeps it in `~/.config/flashbox/config.json`. `flashbox logout` forgets it there; revoke it in the dashboard to switch it off.

`FLASHBOX_API_KEY` overrides the saved key, for scripts and CI.

## A session

```text
⚡ Sandbox sbx_aa3k... ready: 26 ms on the host, 140 ms round trip from here.
flashbox:/workspace$ curl -s https://example.com | grep -o '<title>.*</title>'
<title>Example Domain</title>
  ✓ 210 ms · host 180 ms · CPU 30 ms · $0.000050  │  session: 1 command · 210 ms · $0.000050
```

The line after each command reads:

- **The first time**: the whole round trip from your terminal, network included.
- **host**: the time on the machine running your sandbox, from receiving the command to its checkpoint being written.
- **CPU**: the guest CPU the command used. Each command includes 1,000 ms; only time beyond that is billed extra.
- **The price**: what this command costs at list price, $0.05 per 1,000 commands (nothing is charged during the beta).
- **session**: commands so far, time spent waiting on them, and their total cost.

`cd` changes where the next commands run; otherwise each command starts fresh, as an agent's would.

## Session commands

| Command | What it does |
| --- | --- |
| `/rollback [N]` | Undo the last N commands (default 1), files and running processes included. `/rollback ck_...` goes to any checkpoint. |
| `/checkpoints [N]` | The last N checkpoints with their commands. |
| `/fork [N]` | Copy this exact state into N new sandboxes. `/switch sbx_...` moves the session to one. |
| `/ls [path]`, `/cat <path>` | List a directory, print a file. |
| `/bg <command>`, `/ps`, `/logs <id>`, `/kill <id>` | Start and manage background processes, such as a server. |
| `/hibernate` | Stop the sandbox now. The next command resumes it from its newest checkpoint. |
| `/cost` | What the session cost, next to what a per-second sandbox would have cost for the same time. |
| `/new`, `/info`, `/destroy`, `/exit` | A new sandbox, details of this one, destroy it, leave. |

When you leave, the sandbox is kept: idle sandboxes cost nothing. `flashbox --sandbox sbx_...` goes back to it.

## Other commands

| Command | What it does |
| --- | --- |
| `flashbox run "<command>"` | One command in a new sandbox, then destroy it (`--keep` keeps it). The exit code is the command's. |
| `flashbox whoami` | The signed-in account. |
| `flashbox usage` | This month's commands, CPU and would-be bill. |
