Skip to content

feat(sandbox-sidecar): add boxd as a sandbox runner - #2774

Open
MichielMAnalytics wants to merge 1 commit into
diggerhq:developfrom
MichielMAnalytics:feat/boxd-sandbox-runner
Open

MichielMAnalytics wants to merge 1 commit into
diggerhq:developfrom
MichielMAnalytics:feat/boxd-sandbox-runner

Conversation

@MichielMAnalytics

Copy link
Copy Markdown

boxd × Digger

I work on boxd. This adds boxd as a second sandbox runner for OpenTaco Remote Runs, next to E2B. With SANDBOX_RUNNER=boxd the sidecar runs each plan or apply in a fresh boxd machine (a full Ubuntu VM) and deletes it when the job ends.

Summary

  • sandbox-sidecar/src/runners/boxdRunner.ts: a SandboxRunner that mirrors e2bRunner.ts. Same job flow: install the requested Terraform/OpenTofu version, write the config archive and state, run init and plan or apply/destroy, stream the output to the job log, return the plan JSON or the new state.
  • SANDBOX_RUNNER accepts e2b (still the default) or boxd. An unknown value or a missing BOXD_API_KEY fails at startup with a clear message.
  • The plan summary moved from e2bRunner.ts to runners/planSummary.ts, unchanged, so both runners count changes the same way.
  • Statesman is not touched. It keeps OPENTACO_SANDBOX_PROVIDER=e2b and OPENTACO_E2B_SIDECAR_URL, since it only talks HTTP to the sidecar.
  • Docs: sidecar README, self-hosting configuration, the env var reference, and a "boxd Setup" page next to "E2B Setup".
  • docker-compose: SANDBOX_RUNNER moved from the compose environment: block into sidecar.env (the example sets e2b), so it can be switched there. An env file without it still gets e2b, the sidecar's default.

Turn it on:

SANDBOX_RUNNER=boxd BOXD_API_KEY=... npm start

Options: BOXD_ORG, BOXD_REGION, BOXD_SNAPSHOT (start from a snapshot with Terraform or OpenTofu installed, like the E2B templates), BOXD_VCPU/BOXD_MEMORY, BOXD_LABELS, BOXD_NAME_PREFIX, BOXD_JOB_TIMEOUT_SECONDS (default 1500, below statesman's 30 minute poll timeout).

How it maps onto the runner

Step E2B runner boxd runner
sandbox Sandbox.create(template) machines.create({ isolated: true, config: { autoSuspendTimeout: 0 } }) + waitUntilReady
Terraform/OpenTofu version prebuilt template or runtime install runtime install for the machine's CPU, skipped when the binary on the machine (or in BOXD_SNAPSHOT) already has that version
config and state files.write files.upload, byte count checked
init, plan, apply commands.run with output callbacks streamExec, stopped when the job runs out of time
plan JSON, state read stdout / files.read files.download
cleanup sandbox.kill() in finally machines.delete(id) in finally, retried once, plus a delete-after timer set at create

Differences from the E2B runner

  1. Machines are created isolated, since they run user Terraform. They have outbound internet (providers, registries) but can't reach other machines.
  2. The version string is checked against x.y.z[-suffix] before it goes into the install script, and a working_directory that leaves the workspace is refused before a machine is created. A leading / is relative to the workspace, as with E2B.
  3. Each job has one deadline, BOXD_JOB_TIMEOUT_SECONDS, defaulting to 25 minutes so a job ends before statesman stops polling (OPENTACO_E2B_POLL_TIMEOUT, 30 minutes). Keep a few minutes between them.
  4. If the sidecar dies mid-job, the machine's delete-after timer (the job limit plus 10 minutes) removes it. Machines carry the labels managed-by=opentaco-sidecar and opentaco-job=<job id>.
  5. A snapshot (BOXD_SNAPSHOT) holds one terraform and one tofu on PATH. Other versions are installed at runtime. The docs say to build it on a fresh isolated machine, since every job runs user Terraform on a copy of it.

Test plan

  • npm test: 39 new unit tests (the sidecar had none) against a fake boxd client. They cover config parsing, runner selection, the plan summary, create options, streaming, plan/apply/destroy, state round trip, install skip, the job deadline, and that the machine is deleted on every failure path. Passes on Node 24 and on node:20-alpine (the sidecar image's base).
  • npm run build: clean. docker build -f Dockerfile_sidecar: builds.
  • Live against boxd with BOXD_E2E=1 npm run smoke:boxd: Terraform 1.5.7 plan, apply, re-plan with state (no changes), destroy plan, destroy; OpenTofu 1.10.0 plan; a broken config that fails init. 7 jobs, 7 machines created and deleted, each job about 3 s end to end.
  • The sidecar Docker image with SANDBOX_RUNNER=boxd, driven by statesman's own Go client (taco/internal/sandbox): plan and apply with Terraform 1.8.5 in a /infra working directory, and a failing OpenTofu plan.
  • From a snapshot with Terraform 1.5.7 installed: 1.5.7 used it as is, 1.8.5 was installed on top.
  • A 150 s apply (time_sleep) streamed to the end. With BOXD_JOB_TIMEOUT_SECONDS=25 a 90 s apply was stopped and the machine deleted. A live machine had its delete-after timer, labels and idle settings as set.
  • mint broken-links in docs/: the same 19 broken links as on develop, none new.

🧠 Ai UsageDetails (if applicable):

This PR was written primarily by Claude Code (code, tests and docs). I reviewed it and ran the tests above, including the live runs against boxd.

SANDBOX_RUNNER=boxd runs each Remote Runs job in a fresh, isolated boxd
machine. The runner installs the requested Terraform or OpenTofu version
unless the machine already has it (BOXD_SNAPSHOT), streams init, plan and
apply output, returns the plan JSON or the new state, and deletes the
machine when the job ends.

Each job has one deadline (BOXD_JOB_TIMEOUT_SECONDS, default 25 minutes,
below statesman's poll timeout). Each machine also gets a delete-after
timer of that limit plus 10 minutes, so it goes away even if the sidecar
stops mid-job.

The plan summary moves to runners/planSummary.ts so both runners share it.
Adds unit tests (npm test) and a live smoke test (npm run smoke:boxd).
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​boxd-sh/​sdk@​0.3.710010010096100

View full report

This branch has not been deployed

No deployments
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