Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@
This file records user-visible changes to the BoxCompute CLI. GitHub Releases
use the same notes and bind them to the exact source commit.

## [0.12.0] - 2026-10-22

Run BoxCompute chats on your own machine with `bxc runner`.

### CLI users

- `bxc runner` connects this machine to BoxCompute over an outbound WebSocket
and runs the agent's shell and file commands for chats that use the runner,
in one Docker container per chat (`node:22-bookworm` unless `--image` says
otherwise). Each chat's `/workspace` is a Docker volume that stays until
BoxCompute deletes the chat's sandbox.
- Containers stop after 30 minutes without commands (`--idle-stop`, `0` to
keep them running); the next command starts them again with their files.
- `--dispatch PROGRAM` hands each ensure, exec and delete to your own program
instead of Docker. The README documents the contract and has a complete
Docker example.
- The runner reconnects by itself after network failures and server restarts,
and exits when BoxCompute rejects its token. Ctrl-C stops running commands
but keeps containers and files.
- Requires Node.js 22 or newer, Docker unless `--dispatch` is used, and a
BoxCompute server with self-hosted runners (Settings → Runners). Every other
command still runs on Node.js 20.

### Security

- The runner token is read only from `BOXCOMPUTE_RUNNER_TOKEN`, sent in the
first WebSocket message rather than a URL or header, never printed, and
removed from the environment of Docker, containers and dispatch programs.
Plain `ws://` is refused except to loopback.
- The agent's commands run on this machine with its network access, inside
containers; BoxCompute approvals still apply. Delete the runner in Settings →
Runners to revoke its token.

## [0.11.0] - 2026-10-18

Stop a running VM with `bxc sandbox stop SANDBOX_ID`.
Expand Down
149 changes: 149 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,155 @@ exact `--revoke` command; the server-side lease still expires naturally.
Run `bxc` or `bxc --help` for the complete command reference. The previous
`bcompute` executable remains available as a compatibility alias.

## Run chats on your own machine (`bxc runner`)

`bxc runner` lets the BoxCompute agent work on a computer you control. It
opens an outbound WebSocket to BoxCompute, so the machine needs no open ports,
and runs the agent's shell and file commands for chats that use this runner in
one Docker container per chat. Each chat's `/workspace` is a Docker volume on
this machine that stays until BoxCompute deletes the chat's sandbox.

Requirements: Docker (`docker version` must work for your user) and Node.js 22
or newer. The other `bxc` commands still run on Node.js 20.

### Set up a runner

1. In BoxCompute, open Settings → Runners, create a runner and copy its token.
2. On the machine that should run the commands:

```sh
export BOXCOMPUTE_RUNNER_TOKEN=bxr_...
npx -y @boxcompute/cli@latest runner
```

To keep the token out of your shell history, type it at a prompt instead:
`read -rs BOXCOMPUTE_RUNNER_TOKEN && export BOXCOMPUTE_RUNNER_TOKEN`.

The runner prints `Connected as "<runner name>"` and then one line per
operation. Leave it running; Ctrl-C disconnects it.
3. In BoxCompute, choose the runner for a chat in the composer. While the
runner is connected, that chat's commands run in a container here.

The token is read only from `BOXCOMPUTE_RUNNER_TOKEN`, never from a command-line
option, because other users on the machine can read process arguments.

```sh
# Another image; it needs bash and python3 (default: node:22-bookworm).
bxc runner --image python:3.13
# Stop a chat's container after 2 hours without commands; 0 never stops it.
bxc runner --idle-stop 2h
# A self-hosted BoxCompute (default: your `bxc login` URL, else app.boxcompute.ai).
bxc runner --url https://boxcompute.example.com
# Also log each command's arguments.
bxc runner --verbose
```

Each container is named after the chat's sandbox (`bxs-…`), labelled
`com.boxcompute.runner` and `com.boxcompute.sandbox`, runs with `--init`, and
mounts the volume `bxs-…-workspace` at `/workspace`. List them with
`docker ps -a --filter label=com.boxcompute.runner`.

**Idle stop.** A container this runner has used stops after 30 minutes without
commands (`--idle-stop`). Its volume and files stay, and the next command
starts it again.

**Disconnects.** The runner reconnects by itself, backing off up to 30 seconds.
Commands that were running when the connection dropped are stopped; BoxCompute
reports them as failed. Ctrl-C (or SIGTERM) also stops running commands but
keeps every container and its files. The runner exits instead of reconnecting
when BoxCompute rejects the token, runners are not available on the account, or
another `bxc runner` connects with the same token.

### Custom dispatch

`--dispatch PROGRAM` hands every operation to your own program instead of the
built-in Docker dispatch, for example to use Podman, a VM or a remote host. The
runner starts `PROGRAM` without a shell for each operation, with the runner's
environment minus `BOXCOMPUTE_RUNNER_TOKEN`, plus:

| Variable | Value |
| --- | --- |
| `BOXCOMPUTE_OPERATION` | `ensure`, `exec` or `delete` |
| `BOXCOMPUTE_SANDBOX_ID` | The chat's sandbox, `bxs-` and 16 hex digits |
| `BOXCOMPUTE_RUNNER_ID` | This runner's ID |
| `BOXCOMPUTE_IMAGE` | The `--image` value (default `node:22-bookworm`) |

- **ensure** creates the sandbox if it is missing, with an empty `/workspace`,
or starts it if it is stopped, and exits 0 once commands can run. It must be
safe to repeat.
- **exec** receives the command's argv as its arguments. The runner writes the
command's stdin (often empty) and closes it, streams stdout and stderr, and
reports the program's exit code as the command's.
- **delete** removes the sandbox and its storage. An already missing sandbox is
a success.

When ensure or delete exits non-zero, the last non-empty line of its stderr is
shown in BoxCompute as the error. A cancelled exec gets SIGKILL for the
program's whole process group; work it started elsewhere, such as through
`docker exec`, can keep running. There is no idle stop in this mode.

This `dispatch.sh` does what the built-in Docker dispatch does, without idle
stop:

```sh
#!/bin/sh
# bxc runner --dispatch ./dispatch.sh
set -eu
id="$BOXCOMPUTE_SANDBOX_ID"
fail() { echo "$1" >&2; exit 1; }

case "$BOXCOMPUTE_OPERATION" in
ensure)
state=$(docker inspect --type container --format '{{.State.Running}}' "$id" 2>/dev/null || true)
case "$state" in
true) ;;
false) docker start "$id" >/dev/null || fail "Could not start $id" ;;
*)
docker run -d --name "$id" --init -w /workspace \
--label "com.boxcompute.runner=$BOXCOMPUTE_RUNNER_ID" \
--label "com.boxcompute.sandbox=$id" \
-v "$id-workspace:/workspace" \
"$BOXCOMPUTE_IMAGE" sleep infinity >/dev/null \
|| fail "Could not create $id from $BOXCOMPUTE_IMAGE"
docker exec "$id" sh -c 'command -v bash && command -v python3' >/dev/null \
|| fail "The image $BOXCOMPUTE_IMAGE needs bash and python3"
;;
esac
;;
exec)
exec docker exec -i "$id" "$@"
;;
delete)
if docker inspect --type container "$id" >/dev/null 2>&1; then
docker rm -f "$id" >/dev/null || fail "Could not remove $id"
fi
docker volume rm -f "$id-workspace" >/dev/null || fail "Could not remove $id-workspace"
;;
*)
fail "Unsupported operation: $BOXCOMPUTE_OPERATION"
;;
esac
```

Make it executable with `chmod +x dispatch.sh`. `--idle-stop` cannot be combined
with `--dispatch`.

### Security

- The agent's commands run on this machine, inside containers that have this
machine's network access, including your local network. Docker separates
their files from yours, but treat it as running the agent here. BoxCompute
approvals still apply.
- Anyone with the runner token can connect as this runner and receive its
chats' commands and files. Keep it secret. `bxc runner` never prints it,
sends it only in the first WebSocket message (not in a URL or header), and
does not pass it to Docker, containers or a dispatch program.
- The connection uses TLS (`wss://`). Plain `ws://` is refused except to a
loopback development server.
- Delete the runner in Settings → Runners to revoke its token. Stopping
`bxc runner` does not remove containers or volumes; remove them with
`docker rm -f` and `docker volume rm` when you no longer need their files.

## Upgrade rollout

Deploy the server release with both Sandbox API v1 and v2 before publishing CLI
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boxcompute/cli",
"version": "0.11.0",
"version": "0.12.0",
"description": "Connect local AI agents to BoxCompute sandboxes",
"keywords": [
"boxcompute",
Expand Down
108 changes: 108 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
clearConnection,
loadConnection,
loadSavedUrl,
normalizeBaseUrl,
saveConnection,
type Connection,
} from "./config.js";
Expand All @@ -49,6 +50,15 @@ import { runSsh } from "./ssh.js";
import { cooperativeConnectionApi } from "./cooperative-connection.js";
import { resumeSandbox } from "./resume.js";
import { stopSandbox } from "./stop.js";
import {
DEFAULT_IDLE_STOP_MS,
DEFAULT_RUNNER_IMAGE,
RUNNER_IMAGE_PATTERN,
RUNNER_TOKEN_ENV,
RUNNER_TOKEN_PATTERN,
parseDuration,
runRunner,
} from "./runner.js";

const DEFAULT_URL = "https://app.boxcompute.ai";
const CLI_VERSION = (JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { version: string }).version;
Expand Down Expand Up @@ -89,6 +99,7 @@ Commands:
deleted Read deleted sandboxes, their logs, and their costs
costs Compute cost per API key and per sandbox
audit Page the account's API audit log
runner Run BoxCompute chats in Docker on this machine
skill [alias: skills] Manage coding-harness skills
detect Detect compatible coding harnesses
list [alias: ls] List detected or installed harnesses
Expand Down Expand Up @@ -125,6 +136,7 @@ Examples:
$ bxc costs --from 2026-10-01T00:00:00Z
$ bxc audit --outcome error
$ BOXCOMPUTE_ENABLE_SSH=1 bxc sandbox ssh SANDBOX_ID
$ BOXCOMPUTE_RUNNER_TOKEN=bxr_... bxc runner

Compatibility:

Expand Down Expand Up @@ -330,6 +342,41 @@ Usage: bxc usage [--days DAYS]
Use bxc credits for remaining credit and bxc costs for compute spending.
`;

const runnerHelp = `Run BoxCompute chats on this machine

Usage: bxc runner [options]

Connects to BoxCompute over an outbound WebSocket and runs the agent's
shell and file commands for chats that use this runner, in one Docker
container per chat. Each chat's files stay in a Docker volume until
BoxCompute deletes its sandbox.

Options:

--image IMAGE Container image; needs bash and python3
(default: ${DEFAULT_RUNNER_IMAGE})
--idle-stop DURATION Stop a chat's container after this long
without commands, such as 30m or 2h; 0 never
stops (default: 30m). Files stay; the next
command starts it again
--dispatch PROGRAM Hand each operation to PROGRAM instead of
Docker (see the README for the contract)
--url URL BoxCompute web URL (default: the saved login
URL, else https://app.boxcompute.ai)
--verbose Also log each command's arguments

Environment:

${RUNNER_TOKEN_ENV} Required. Create a runner in BoxCompute
(Settings → Runners) and export its token.
It is never accepted on the command line and
never passed to containers or PROGRAM.

Requires Node.js 22 or newer and, without --dispatch, a running Docker.
Ctrl-C disconnects and stops running commands; containers and files stay.
The agent's commands run here with this machine's network access.
`;

const skillHelp = `Manage coding-harness skills

Usage: bxc skill <command> [options]
Expand Down Expand Up @@ -386,6 +433,9 @@ export type CliDependencies = {
openServices?: typeof openServices;
proxy?: typeof runProxy;
ssh?: typeof runSsh;
runner?: typeof runRunner;
/** null simulates a runtime without a global WebSocket (Node.js 20). */
webSocket?: typeof WebSocket | null;
};

class UsageError extends Error {
Expand Down Expand Up @@ -1100,6 +1150,63 @@ export async function runCli(argv: string[], supplied: CliDependencies = {}): Pr
return 0;
}

if (command === "runner") {
if (json) throw new UsageError("runner is a foreground stream and does not support --json");
const image = option(args, "image");
const dispatch = option(args, "dispatch");
const idleStop = option(args, "idle-stop");
const urlOption = option(args, "url");
const verbose = flag(args, "verbose");
if (args.length) throw new UsageError(`Unknown runner option: ${args[0]}`);
if (image !== undefined && !RUNNER_IMAGE_PATTERN.test(image)) {
throw new UsageError("--image must be an image reference such as node:22-bookworm");
}
if (dispatch !== undefined && idleStop !== undefined) {
throw new UsageError("--idle-stop applies only to the built-in Docker dispatch");
}
let idleStopMs = DEFAULT_IDLE_STOP_MS;
if (idleStop !== undefined) {
try {
idleStopMs = parseDuration(idleStop);
} catch (error) {
throw new UsageError((error as Error).message);
}
}
const WebSocketImpl = supplied.webSocket === undefined ? globalThis.WebSocket : supplied.webSocket;
if (typeof WebSocketImpl !== "function") throw new Error("bxc runner needs Node.js 22 or newer.");
// The token comes only from the environment: argv is visible to every
// local user through ps.
const token = env[RUNNER_TOKEN_ENV]?.trim();
if (!token) {
throw new Error(
`${RUNNER_TOKEN_ENV} is not set. Create a runner in BoxCompute (Settings → Runners), ` +
`then run \`export ${RUNNER_TOKEN_ENV}=<token>\` and start bxc runner again.`,
);
}
if (!RUNNER_TOKEN_PATTERN.test(token)) {
throw new Error(`${RUNNER_TOKEN_ENV} is not a runner token (runner tokens start with bxr_). Copy it from Settings → Runners.`);
}
const url = normalizeBaseUrl(urlOption ?? await savedUrl(env) ?? DEFAULT_URL);
const abort = new AbortController();
const stop = () => abort.abort();
const signals = ["SIGINT", "SIGTERM", "SIGHUP"] as const;
for (const signal of signals) process.on(signal, stop);
try {
return await (supplied.runner ?? runRunner)({
url,
token,
image: image ?? DEFAULT_RUNNER_IMAGE,
imageChosen: image !== undefined,
dispatch: dispatch ?? null,
idleStopMs,
verbose,
version: CLI_VERSION,
}, { env, stdout: io.stdout, stderr: io.stderr, signal: abort.signal, WebSocket: WebSocketImpl });
} finally {
for (const signal of signals) process.off(signal, stop);
}
}

if (command === "sandbox" && !args.length) {
write(io.stdout, sandboxHelp);
return 0;
Expand Down Expand Up @@ -1400,6 +1507,7 @@ function helpFor(command?: string): string {
if (command === "deleted") return deletedHelp;
if (command === "costs") return costsHelp;
if (command === "audit") return auditHelp;
if (command === "runner") return runnerHelp;
return rootHelp;
}

Expand Down
Loading