Skip to content

feat(cli): run BoxCompute chats on your own machine with bxc runner (0.12.0) - #27

Merged
farhan-helmy merged 2 commits into
mainfrom
feat/runner
Oct 23, 2026
Merged

farhan-helmy merged 2 commits into
mainfrom
feat/runner

Conversation

@farhan-helmy

@farhan-helmy farhan-helmy commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Outcome

bxc runner lets the BoxCompute agent run a chat's shell and file commands on a machine the user controls, like Amp's self-hosted orbs. It opens an outbound WebSocket to /api/runners/connect (protocol v1), so the machine needs no open ports. Each chat gets one Docker container (bxs-…, --init, volume bxs-…-workspace at /workspace), or each operation goes to a --dispatch PROGRAM.

export BOXCOMPUTE_RUNNER_TOKEN=bxr_...
npx -y @boxcompute/cli@latest runner [--image IMAGE] [--idle-stop 30m] [--dispatch PROGRAM] [--url URL] [--verbose]

Draft: the server half (Settings → Runners and /api/runners/connect) ships separately in web-agent. Until it is deployed, the runner keeps retrying the connection. Deploy the server first, then merge and publish.

What it does

  • Protocol v1 exactly as specified:
    • hello within 10 s of open, carrying the token, welcome, and ensure/exec/delete/cancel/ping.
    • output chunks of at most 256 KiB, in order, before the result. Output stops being forwarded past 64 MiB per exec, but the exit code is still reported.
    • Unknown frame types are ignored; an unknown op gets unsupported operation.
    • Sandbox id, argv and base64 stdin are validated before anything runs.
    • At most 8 requests run at once, or fewer if the welcome says so; the rest queue.
  • Reconnects:
    • Backoff from 1 s to 30 s with jitter, reset after a welcome.
    • 1–3 s after close code 1012.
    • Exit 1 with the close reason on 4400/4401/4403/4409.
    • The connection is dropped after 70 s of silence.
    • In-flight commands are killed on disconnect.
  • Docker dispatch:
    • ensure inspects, then runs (and checks bash + python3) or starts the container.
    • exec is docker exec -i.
    • delete removes the container and its volume; a missing sandbox counts as success.
    • Idle containers stop after 30 minutes (--idle-stop, 0 disables) and keep their volume.
  • SIGINT/SIGTERM: closes with code 1000, kills running commands, keeps every container and volume, exits 0.
  • bxc runner needs Node.js 22+ and exits 1 with a clear message on Node 20; every other command still runs on Node 20.

Beyond the spec, all deliberate:

  • A cancelled or disconnected command is also killed inside its container, matched by a BOXCOMPUTE_EXEC_ID env marker. Killing the local docker exec client alone leaves the command running.
  • Before a command, a container is re-inspected (and started if Docker stopped it behind the runner's back) when its state is more than 10 s old.
  • Output is paused while the socket's send buffer is over 8 MiB.

User action

  • Create a runner in Settings → Runners, export the token, and run npx -y @boxcompute/cli@latest runner.
  • Choose the runner for a chat in the composer.
  • The README section "Run chats on your own machine (bxc runner)" covers setup, idle stop, the dispatch contract with a complete dispatch.sh, and security notes.

Security impact

  • The token is read only from BOXCOMPUTE_RUNNER_TOKEN, never from argv, and sent only in the first frame (no URL or header).
  • It is never printed: error and log text is scrubbed, and verbose argv is redacted.
  • It is removed from the environment of Docker, containers and dispatch programs.
  • Plain ws:// is refused except to loopback.
  • Children run without a shell, in their own process group; Docker values are single argv elements, and --image is validated so it cannot become a Docker flag.
  • The agent's commands run on the user's machine with its network access. BoxCompute approvals still apply, and the README says so.

Verification

Run on the approved worker with the pinned images:

  • Repo checks in oven/bun 1.4.2 (CI pins 1.3.14):
    • install, typecheck, lint (0 warnings) and build pass.
    • bun test: 96 pass, 2 fail (98 tests, 14 files). The 2 failures are the untouched test/vm-files.test.ts "VM creation" tests. They fail the same way on a clean origin/main snapshot under Bun 1.4.2 (9 pass, 2 fail), so they come from the Bun version, not this change.
    • The new runner suites: 23 pass, 0 fail. They cover a fake WebSocket server and a fake dispatch program, plus the Docker argv builders and a fake docker CLI.
  • Node 24.20 smoke of the built node dist/cli.js runner against a fake server: 19 pass, 0 fail. It covers the undici WebSocket, chunking, cancel, 1012 reconnect, SIGINT exiting within 5 s with close 1000, 4401, and no token anywhere.
  • Real Docker end-to-end (Docker 29) using the built CLI: 28 pass, 0 fail. It covers labels, init and the volume, stdin, exit 143 for a signal, a cancel that kills sleep inside the container, restarting a stopped container with files kept, deleting twice, refusing an image without bash/python3, an unreachable Docker, and cleanup.
  • node scripts/validate-release-change.mjs <base>: "Validated unpublished release @boxcompute/cli@0.12.0".
  • Not run: bun run test:native (Go helpers untouched, no Go 1.27.1 on the worker) and npm pack --dry-run with prepack scripts. npm pack --dry-run --ignore-scripts lists dist/runner*.js.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

farhan-helmy and others added 2 commits October 22, 2026 15:53
…0.12.0)

Self-hosted runners let a chat's shell and file commands run on a machine
the user controls, like Amp's self-hosted orbs. `bxc runner` opens an
outbound WebSocket to /api/runners/connect, so the machine needs no open
ports, and speaks protocol v1: hello/welcome, ensure/exec/delete requests,
streamed output and result frames, cancel, and ping/pong. Each chat gets one
Docker container with a named /workspace volume, or each operation goes to
a --dispatch program for people who want Podman, a VM or a remote host.

The token comes only from BOXCOMPUTE_RUNNER_TOKEN, because argv is visible
to every local user. It travels in the first frame rather than a URL or
header, is never printed, and is removed from the environment of Docker,
containers and dispatch programs. Plain ws:// is refused except to loopback.

Reconnects back off from 1 s to 30 s, come back within 1-3 s after a server
restart (1012), and stop for good on 4400/4401/4403/4409 so a revoked or
replaced runner does not loop. Commands from a dropped connection are
killed, since the server has already failed them. Killing the local
`docker exec` client does not stop the command in the container, so a
cancelled command is also killed inside its container by an exec marker.
Containers stop after 30 idle minutes and keep their volume; a container
Docker stopped behind the runner's back is started again before the next
command.

The server half ships separately; until it does, the runner keeps
retrying the connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bun 1.3.14 never settles server.stop(true) after the server itself closed a
WebSocket, so the 4401 and 1012 tests timed out in afterEach on CI although
their assertions passed. Bun 1.4.2 on the worker did not show it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@farhan-helmy
farhan-helmy marked this pull request as ready for review October 23, 2026 01:51
@farhan-helmy
farhan-helmy merged commit 0642356 into main Oct 23, 2026
4 checks passed
@farhan-helmy
farhan-helmy deleted the feat/runner branch October 23, 2026 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant