Repository navigation
feat(cli): run BoxCompute chats on your own machine with bxc runner (0.12.0) - #27
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Outcome
bxc runnerlets 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, volumebxs-…-workspaceat/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
hellowithin 10 s of open, carrying the token,welcome, andensure/exec/delete/cancel/ping.outputchunks of at most 256 KiB, in order, before theresult. Output stops being forwarded past 64 MiB per exec, but the exit code is still reported.unsupported operation.welcomesays so; the rest queue.ensureinspects, then runs (and checksbash+python3) or starts the container.execisdocker exec -i.deleteremoves the container and its volume; a missing sandbox counts as success.--idle-stop,0disables) and keep their volume.bxc runnerneeds 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:
BOXCOMPUTE_EXEC_IDenv marker. Killing the localdocker execclient alone leaves the command running.User action
npx -y @boxcompute/cli@latest runner.bxc runner)" covers setup, idle stop, the dispatch contract with a completedispatch.sh, and security notes.Security impact
BOXCOMPUTE_RUNNER_TOKEN, never from argv, and sent only in the first frame (no URL or header).ws://is refused except to loopback.--imageis validated so it cannot become a Docker flag.Verification
Run on the approved worker with the pinned images:
oven/bun1.4.2 (CI pins 1.3.14):bun test: 96 pass, 2 fail (98 tests, 14 files). The 2 failures are the untouchedtest/vm-files.test.ts"VM creation" tests. They fail the same way on a cleanorigin/mainsnapshot under Bun 1.4.2 (9 pass, 2 fail), so they come from the Bun version, not this change.dockerCLI.node dist/cli.js runneragainst 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.sleepinside 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".bun run test:native(Go helpers untouched, no Go 1.27.1 on the worker) andnpm pack --dry-runwith prepack scripts.npm pack --dry-run --ignore-scriptslistsdist/runner*.js.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.