Skip to content

feat(sandbox): per-sandbox cpu and memory limits - #213

Merged
quickbeard merged 1 commit into
mainfrom
feat/sandbox-resource-limits
Aug 13, 2026
Merged

quickbeard merged 1 commit into
mainfrom
feat/sandbox-resource-limits

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Phase 4c, item 3 — the last of the 4c work that can be built and verified from here.

What

  • SandboxConfig gains optional cpus / memoryMiB, plus sandboxResourcesValid and the shared SANDBOX_CPUS_RANGE (1–32) / SANDBOX_MEMORY_MIB_RANGE (1–64 GiB). Ceilings keep an unbootable VM (0 CPUs, 64 MiB) or an oversubscribed host out of the persisted config.
  • vz provider: per-sandbox values win over the provider-wide defaults (config.cpus ?? options.cpus ?? 4).
  • Add sandbox dialog: optional CPUs and Memory (GB) fields, shown only on macOS. WSL's limits are VM-global (.wslconfig) and bubblewrap has no cgroup plumbing here, so offering the fields on those platforms would promise something the backend can't deliver. Memory is entered in GB (a MiB box invites 4-digit typing) and stored as MiB, which is what the VM config wants.
  • Validation at every boundary: dialog gates the Create button, the main process re-validates on the IPC edge (sandbox-add now takes a third resources argument), and a hand-edited store entry that fails validation falls back to provider defaults rather than dropping the sandbox from the list.

The app-side validator is a small mirror in app/src/sandbox/resources.ts — the app package must not import the node-flavored @codev/sandbox, the same rule that gives sandbox/types.ts its own copy of the wire types.

Tests

  • sandboxResourcesValid matrix (empty, valid, both ceilings, zero, over-max, fractional, under-min memory, NaN)
  • vz: default vm.json still 4 CPUs / 4096 MiB; a new test asserts per-sandbox 8 / 16384 overrides provider defaults of 2 / 2048
  • Suites: sandbox 91 pass / 2 skip, desktop 76 pass, app 657 pass; all three typecheck clean

CHANGELOG entry added; the renderer-slice DIVERGENCES row notes the new i18n keys.

4c status after this

  • ✅ named egress rules (feat(sandbox): named egress rules for the broker #212), ✅ resource limits (here)
  • ⏸ unprivileged guest user — needs the host-uid remap design + an image respin (virtio-fs checks guest perms against host file uids)
  • ⏸ WSL egress firewall — needs a session on the Windows box; implementing blind risks breaking fleet egress

🤖 Generated with Claude Code

SandboxConfig gains optional cpus/memoryMiB with shared range validation;
the vz provider prefers them over its provider-wide defaults, and the
add dialog offers the fields on macOS only — WSL limits are VM-global
(.wslconfig) and bubblewrap has no cgroup plumbing here, so offering
them elsewhere would be a lie. Memory is entered in GB and stored as
MiB. The main process re-validates on the IPC boundary, and a
hand-edited store value that fails validation falls back to the
provider defaults rather than dropping the sandbox.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@quickbeard
quickbeard merged commit f39a808 into main Aug 13, 2026
0 of 5 checks passed
@quickbeard
quickbeard deleted the feat/sandbox-resource-limits branch August 13, 2026 04:29
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