barebox 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,9 +4,54 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
 
7
+ ## [0.3.0] - 2026-10-28
8
+
9
+ Breaking changes (pre-1.0): the control socket, `createProxy`'s `certDir` and `allowUpstream`, `run()`'s low-level options, the hold queue's `approve`/`deny`/`size` and the top-level `allowLoopback` option are removed or moved; `runtime` is now required. Each is marked **Breaking** below.
10
+
11
+ ### Added
12
+
13
+ - M2.5 integration seam: `ask`, `auto` (the default) and `trust` modes with the card/payment floor in every mode; the `onAsk` seam plus the file-checkpoint ask channel (`asks/<id>.json` → `answers/<id>.json`, control socket deleted); `run()` wrapping proxy + launch; `sbx run [--mode ask|auto|trust] [--json] [--overlay]`; a 0600 JSONL audit log (bareguard's line shape deferred to M3); `sbx pending` / `approve` / `deny` refuse when no live proxy owns the runtime.
14
+ - M4 undo layer: per-run overlay tracing paper with `sbx diff` / `commit` / `rollback`, conflict flagging (refuse by default, `--skip-conflicts`), and `node_modules` invisibility. Diff walks the merged view with node inside the mount (no shell); `commit` stages into the project and swaps by journaled rename, undoing every step on failure (a full undo reports nothing was applied; a partial one names the steps not undone and keeps the commit folder with the originals); it strips setuid/setgid bits, and committed files get fresh mtimes. `rollback` reports diff's answer, or raw upper paths when the project is gone. Needs bubblewrap ≥ 0.11.0; older bwrap gets a clear refusal.
15
+ - The agent always starts in the project dir.
16
+ - The commit applies under read-only project folders.
17
+ - Rollback always removes the overlay upper, whatever the agent left there.
18
+ - The walker has no output cap, and node is resolved wherever it is installed.
19
+ - One proxy per runtime, enforced by a kernel-held lock: `createProxy` binds an abstract unix socket named from the runtime's real path, device and inode and holds it while the proxy lives. A second live proxy throws "in use" naming the owner's pid, before touching sockets or `asks/`. The kernel frees the lock when the process dies (SIGKILL included), so there is no stale claim and no takeover. `<runtime>/owner` (0600) only names the pid.
20
+ - `sbx pending`, `approve` and `deny` need a live proxy on the runtime and refuse otherwise.
21
+ - `SBX_OVERLAY_IGNORE=a,b` extends the list of folders the overlay layer ignores (`node_modules` is always ignored).
22
+ - Locked credential paths: `launch` hides 21 credential stores from the agent (keys, password stores, keyrings, browser profiles, cloud/cluster/container credentials, `gh`/`op` CLIs, token files). Folders are masked with an empty tmpfs and files read empty; a symlinked drawer is masked at its real target inside `$HOME` or the project. `~/.claude` is deliberately left visible.
23
+ - The upstream wall lives in `src/wall.js`: every resolved IP is checked after DNS, unresolvable names fail closed, and the dial is pinned to the checked IPs. One writer (`denyRes`) produces every HTTP error response.
24
+ - The agent sandbox always runs with bwrap `--new-session`, so its stdin is never the terminal.
25
+
26
+ ### Security
27
+
28
+ - The audit log is owner-only (0600) and scrubs sensitive header values to `[redacted]` before any user `redact` hook runs.
29
+ - Ask and answer files are owner-only (0600); `sbx approve`/`deny` accept only `h<n>` ids; `sbx pending` and `sbx run` strip terminal control sequences from agent-controlled fields before printing.
30
+
31
+ ### Removed
32
+
33
+ - **Breaking:** Control socket (`createProxy`'s `controlSocket` option, `SBX_SOCK`): decisions flow through the file checkpoint (`<runtime>/asks` + `<runtime>/answers`) or `hold.onAsk`; the migration guards are deleted.
34
+ - **Breaking:** `createProxy`'s `certDir`. Certificates always live in `<runtime>/certs`, and `runtime` is now required.
35
+ - **Breaking:** `createProxy`'s `allowUpstream`. There is no escape hatch around the upstream wall.
36
+ - **Breaking:** `run()`'s `gate`, `match`, `shouldHold`, `pollMs`, `proxyPort` and `extraEnv`. Use `createProxy` + `launch` for low-level control.
37
+ - **Breaking:** The hold queue's `approve(id)`, `deny(id)` and `size()`, and `body` on `pending()` entries (the ask payload carries `bodyPreview`).
38
+ - **Breaking:** The library's `ASK OPEN <id>` write to stderr. The library never prints.
39
+
40
+ ### Changed
41
+
42
+ - **Breaking:** Test-only options moved under one key: `createProxy({ unsafeTestOnly: { allowLoopback, resolveUpstream } })`, `run({ unsafeTestOnly: { allowLoopback } })`. The CLI variable is renamed from `SBX_ALLOW_LOOPBACK` to `SBX_UNSAFE_TEST_ALLOW_LOOPBACK`.
43
+ - `onEvent(e)` on `createHolds` / `createProxy`'s `hold` / `run()`: `{ type: 'ask', ask }` when a hold parks, `{ type: 'decided', id, decision, reason }` when it settles. `run()`'s `asks` result is built from these events.
44
+ - `sbx run` prints how each ask ended: `decided <id> <allow|deny> [(reason)]`, or `{"ev":"decided","id","decision","reason"}` with `--json`, between the `ask` and `done` lines. A hold whose client went away reports `deny` / `client gone` (also in `run()`'s `asks`).
45
+ - Decisions are written as `allow` / `deny` everywhere, the audit log included. `approve` is still accepted, as an alias in answer files only.
46
+ - `sbx` results go to stdout; every error, refusal and usage-on-error goes to stderr through `err`. `--help` stays on stdout, exit 0. Exit codes don't change.
47
+
7
48
  ## [0.2.0] - 2026-10-27
8
49
 
9
- Graduation rewrite: the M0-M2 POCs become a library.
50
+ Graduation rewrite: the M0–M2 POCs become a library. The POCs (Oct 26, `poc/`, not shipped) passed all three go/no-go gates:
51
+
52
+ - walls + front door: 14/14 checks, red-team 8/8
53
+ - inspection inside HTTPS: curl, node, python requests and git over the real internet
54
+ - hold-and-ask: a 9-scenario matrix
10
55
 
11
56
  ### Added
12
57
 
@@ -15,19 +60,30 @@ Graduation rewrite: the M0-M2 POCs become a library.
15
60
  - Hold queue: requests park for approve/deny or time out; holds abandoned by a disconnecting client are dropped; `maxBody` caps queued bodies.
16
61
  - `launch`: bwrap sandbox with locked paths, a CA trust bundle exported through the usual env vars, and the runtime sockets masked from the sandbox (including a runtime reached through a symlink).
17
62
  - `sbx` CLI: `pending`, `approve`, `deny`, `--help`, defined exit codes; socket from `SBX_SOCK` or `SBX_RUNTIME`, with no cwd default.
18
- - `npm run bench`: per-sandbox and proxy RSS benchmark.
63
+ - `npm run bench`: per-sandbox and proxy RSS benchmark. Measured with 20 agents: 7.8 MB mean per sandbox (budget 10), and proxy 60.1 MB idle, 71.9 MB with 20 parked holds (budget 80).
19
64
  - TypeScript types, `primitives.json` and `barebox.context.md`.
65
+ - `package.json` `repository` field, which npm provenance needs. Published with SLSA provenance.
20
66
 
21
67
  ### Changed
22
68
 
23
69
  - `createProxy` throws unless `certDir` and the control socket live inside `runtime` (real paths compared).
70
+ - HTTP handling uses the stdlib `http` server instead of hand-rolled framing.
71
+ - The `bin` path is written as `src/cli.js`, without `./`.
24
72
 
25
73
  ### Fixed
26
74
 
27
75
  - POST/PUT bodies to real hostnames no longer hang; the client stream is paused until the upstream pipe is attached.
76
+ - HEAD requests no longer return 502 after 6 s, and slow upstreams are no longer killed at 10 s.
77
+ - Plain-HTTP requests now go through holds the same way HTTPS ones do.
78
+ - The publish workflow installs the same sandbox runner deps as CI (bubblewrap, socat, curl, openssl, userns sysctl).
79
+ - The adopter-gate quickstart uses the 0.2.0 API (`pending()`, a JSON import with `with { type: "json" }`).
28
80
 
29
81
  ### Security
30
82
 
83
+ - The proxy listens on 127.0.0.1 only, not on all interfaces.
84
+ - An agent can no longer approve its own holds. A read-only bind does not block `connect` on a unix socket, so the runtime is masked inside the sandbox and the control socket must live in the runtime.
85
+ - Loopback is no longer reachable through the proxy. A failed DNS lookup is denied, and the private LAN is blocked.
86
+ - `ca.key` can no longer leak through a `certDir` outside the runtime.
31
87
  - Audit log is created 0600 and `Authorization` headers are scrubbed from logged lines.
32
88
 
33
89
  ## [0.1.0] - 2026-10-26
@@ -35,3 +91,7 @@ Graduation rewrite: the M0-M2 POCs become a library.
35
91
  ### Added
36
92
 
37
93
  - Reserved `barebox` on npm; repo scaffold (docs, M0 throwaway POC, publish workflow).
94
+
95
+ [0.3.0]: https://github.com/hamr0/barebox/compare/v0.2.0...v0.3.0
96
+ [0.2.0]: https://github.com/hamr0/barebox/compare/1f144f4...v0.2.0
97
+ [0.1.0]: https://github.com/hamr0/barebox/commit/1f144f4
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
  <img src="https://img.shields.io/badge/status-POC-c0841a" alt="status: POC">
19
19
  </p>
20
20
 
21
- > **Status:** POC. The walls (M0), HTTPS inspection (M1), and hold-and-ask (M2) are proven and measured. The npm package is a name reservation — the API lands with the graduation rewrite next. Linux only.
21
+ > **Status:** early. The walls (M0), HTTPS inspection (M1), hold-and-ask (M2), the one-call `run()` and file ask channel (M2.5) and the undo layer (M4) are built and measured; the decision rules (M3), key custody (M5) and the rest are not. Today's hold rule is interim: payment destinations, plus every non-GET/HEAD request in `ask` and `auto` modes. Linux only.
22
22
 
23
23
  ## Why
24
24
 
@@ -41,8 +41,8 @@ Three letters, each handled differently — the same `r`/`w`/`x` as [bareguard](
41
41
 
42
42
  The agent works in your house:
43
43
 
44
- - **Tracing paper (w).** The agent sees your real files, but every change lands on an overlay laid over them. At the end you commit it or roll it back.
45
- - **Locked drawers (r).** It reads most things. `~/.ssh`, `~/secrets`, `~/.gnupg`, browser profiles stay shut.
44
+ - **Tracing paper (w).** The agent sees your real files, but every change lands on an overlay laid over them. At the end you commit it or roll it back (`sbx run --overlay -- <cmd>`, then `sbx diff`, `sbx commit`, `sbx rollback`).
45
+ - **Locked drawers (r).** It reads most things. Keys and password stores (`~/.ssh`, `~/secrets`, `~/.gnupg`, `~/.password-store`, keyrings), browser profiles, cloud and cluster credentials (`~/.aws`, `~/.azure`, `~/.config/gcloud`, `~/.kube`, `~/.docker`, `~/.config/gh`, `~/.config/op`) and token files (`~/.netrc`, `~/.npmrc`, `~/.pypirc`, `~/.git-credentials`, `~/.cargo/credentials.toml`) stay shut. The agent's own model credentials (`~/.claude`) do not; moving those out is M5.
46
46
  - **One front door with a doorman (x).** No network of its own. Lookups pass; anything that sends, pays, or publishes waits for your yes.
47
47
  - **Keys it never holds.** The agent types a placeholder; the doorman puts the real API key in the request header only after you approve that request.
48
48
 
@@ -60,7 +60,7 @@ The agent works in your house:
60
60
  +-----+--------------- bwrap sandbox (unprivileged) ---------------+
61
61
  | files: overlay lower = real project (read only) |
62
62
  | upper = per-run tracing paper |
63
- | locked paths (~/.ssh etc.) -> empty tmpfs |
63
+ | locked paths (~/.ssh etc.) -> empty tmpfs or /dev/null |
64
64
  | network: none of its own |
65
65
  | socat inside: 127.0.0.1:3128 -> per-agent unix socket |
66
66
  +-----+------------------------------------------------------------+
@@ -89,7 +89,7 @@ Measured, not estimated. Fedora, kernel 7.2, bubblewrap 0.12.0, Node 22.
89
89
  | Start + exit | **10 ms** (M0 POC; unmeasured on the rewrite — TODO re-measure) | 1.87–2.05 s |
90
90
  | 20 agents | ~228 MB (rough sum: ~72 MB proxy + 20 × 7.8 MB) | ~2 GB |
91
91
 
92
- Targets: shared proxy ≤ 80 MB, each extra sandbox ≤ 10 MB, 20 agents on a 2 GB VPS. Bypass attempts (`--noproxy`, unset proxy env, direct IP, host localhost) all fail closed, and a red-team script breaks each wall on purpose to prove the checks can fail. Setup, dead ends and why: [findings](docs/product/findings.md).
92
+ Targets: shared proxy ≤ 80 MB, each extra sandbox ≤ 10 MB, 20 agents on a 2 GB VPS. Bypass attempts (`--noproxy`, unset proxy env, direct IP, host localhost) all fail closed, and a red-team script breaks each wall on purpose to prove the checks can fail. Setup, dead ends and why: [findings](docs/logs/findings.md).
93
93
 
94
94
  ## Roadmap
95
95
 
@@ -99,7 +99,7 @@ Targets: shared proxy ≤ 80 MB, each extra sandbox ≤ 10 MB, 20 agents on a 2
99
99
  | M1 | Proxy sees inside HTTPS (curl, node, python requests, git) | **PASS** — real-internet matrix + negatives, peak 63 MB |
100
100
  | M2 | Hold one `x` request, ask, keep everything else running | **PASS** — 9-scenario hold matrix, 120 s + never timeouts |
101
101
  | M3 | Decide r/w/x deterministically (rwxmap + bareguard), audit log | |
102
- | M4 | Undo layer: `diff`, `commit`, `rollback`, conflict flagging | |
102
+ | M4 | Undo layer: `diff`, `commit`, `rollback`, conflict flagging | **PASS** — paper + review flow implemented, full bwrap+unix proof in a real shell |
103
103
  | M5 | Keys the agent never holds | |
104
104
  | M6 | Scale run: 20 agents + shared proxy | |
105
105
  | M7 | Demos: payment held for approval; prompt-injected `~/.ssh` exfil blocked | |
@@ -112,11 +112,11 @@ M0–M2 are the go/no-go. Later: macOS (`sandbox-exec` + APFS clones), Windows v
112
112
  npm install barebox
113
113
  ```
114
114
 
115
- Requires Node.js >= 22. Zero production dependencies. Published 0.1.0 is the reservation scaffold — nothing to import yet.
115
+ Requires Node.js >= 22. Zero production dependencies. Needs bubblewrap >= 0.11.0 for `--overlay` / `sbx diff|commit|rollback` (Ubuntu 24.04 ships 0.9.0: build from source or use a newer distro); plain runs work with older bwrap. CI builds bubblewrap 0.12.0 from a checksum-pinned source tarball and fails if any test is skipped. The API is in [`barebox.context.md`](barebox.context.md) and `primitives.json` (both ship in the package); the `sbx` CLI comes with it.
116
116
 
117
117
  ## Try the POCs
118
118
 
119
- Linux with `bwrap`, `socat`, `openssl`, Node >= 22 and Python 3. Needs a normal shell (namespaces + listening sockets), not a tool sandbox. The POCs are throwaway proofs, not the product.
119
+ Linux with `bwrap` (>= 0.11.0 only for the overlay), `socat`, `openssl`, Node >= 22 and Python 3. Needs a normal shell (namespaces + listening sockets), not a tool sandbox. The POCs are throwaway proofs, not the product.
120
120
 
121
121
  ```
122
122
  git clone https://github.com/hamr0/barebox && cd barebox
@@ -23,36 +23,100 @@ npx sbx --help
23
23
  ```
24
24
 
25
25
  ```js
26
- import { launch } from "barebox";
27
- // one sandboxed agent: walls up, front door on :3128, locked drawers masked.
28
- // The agent's socket must already be listening: proxy.addAgent("fx").
29
- const child = launch({ runtime: "/tmp/sbx", agent: "fx", proj: "/tmp/proj", command: ["bash", "-c", "echo hi"] });
26
+ import { createProxy, launch } from "barebox";
27
+ import { mkdtempSync } from "node:fs";
28
+ import { tmpdir } from "node:os";
29
+ import { join } from "node:path";
30
+ // one sandboxed agent: walls up, front door on, locked drawers masked.
31
+ // The agent's socket must already be listening: create the front door,
32
+ // then add the agent to it.
33
+ const runtime = mkdtempSync(join(tmpdir(), "sbx-"));
34
+ const proj = mkdtempSync(join(tmpdir(), "proj-"));
35
+ const proxy = createProxy({ runtime, port: 0, logFile: join(runtime, "mitm.log") });
36
+ await proxy.ready;
37
+ const child = launch({ runtime, agent: "fx", proj, command: ["bash", "-c", "echo hi"], socket: proxy.addAgent("fx"), caFile: proxy.caFile });
30
38
  await new Promise((r) => child.on("close", r));
39
+ await proxy.close();
31
40
  ```
32
41
 
33
42
  ```js
34
43
  import { createProxy } from "barebox";
44
+ import { mkdtempSync } from "node:fs";
45
+ import { tmpdir } from "node:os";
46
+ import { join } from "node:path";
35
47
  // the front door: terminates agent TLS, logs every request, parks holds.
36
48
  // The TCP port is opt-in for tests (bound to 127.0.0.1); agents connect
37
49
  // over their own unix socket: proxy.addAgent("fx") -> <runtime>/socks/fx.sock
38
- const proxy = createProxy({ port: 3129, certDir: "./certs", logFile: "./mitm.log" });
50
+ const runtime = mkdtempSync(join(tmpdir(), "sbx-"));
51
+ const proxy = createProxy({ runtime, port: 0, logFile: join(runtime, "mitm.log") });
39
52
  await proxy.ready;
40
53
  await proxy.close();
41
54
  ```
42
55
 
43
56
  ## Holds (human approval)
44
57
 
45
- Start the proxy with a hold rule and a control socket, then decide from a
46
- second terminal:
58
+ Start the proxy with a hold rule, then decide from a second terminal
59
+ through the file checkpoint (`<runtime>/asks` + `<runtime>/answers`):
47
60
 
48
61
  ```bash
49
- SBX_SOCK=/tmp/sbx/ctl.sock npx sbx pending
50
- SBX_SOCK=/tmp/sbx/ctl.sock npx sbx approve h1
51
- SBX_SOCK=/tmp/sbx/ctl.sock npx sbx deny h2 "reason here"
62
+ SBX_RUNTIME=/tmp/sbx npx sbx pending
63
+ SBX_RUNTIME=/tmp/sbx npx sbx approve h1
64
+ SBX_RUNTIME=/tmp/sbx npx sbx deny h2 "reason here"
52
65
  ```
53
66
 
54
67
  Held requests wait (default 120 s, `never` supported); approve forwards,
55
- deny and timeout answer 403 with the reason.
68
+ deny and timeout answer 403 with the reason. These commands need the proxy
69
+ to be alive: with no live proxy on the runtime `sbx pending`, `approve` and
70
+ `deny` exit 1 and say so, because nothing would read the answer.
71
+
72
+ ## One call: `run()` and `sbx run`
73
+
74
+ `run()` starts the proxy, sandboxes one command, answers holds and returns
75
+ the exit code with the ask and audit trail. Modes: `ask`, `auto` (default),
76
+ `trust`. Payment destinations (`/checkout`, `/payment`, `/orders`,
77
+ `/purchase`) hold in every mode; `ask` and `auto` also hold every
78
+ non-GET/HEAD request (an interim rule until the policy module lands).
79
+
80
+ ```js no-run
81
+ import { run } from "barebox";
82
+ const { exit, asks, audit, diff, runtime } = await run({
83
+ proj: "/path/to/project",
84
+ command: ["bash", "-c", "echo hi"],
85
+ mode: "auto",
86
+ overlay: true, // writes land on the undo layer; `diff` lists them
87
+ onAsk: async (ask) => ({ decision: "deny", reason: "not today" }), // omit for the file checkpoint
88
+ });
89
+ ```
90
+
91
+ ```bash
92
+ sbx run [--mode ask|auto|trust] [--json] [--overlay] -- <cmd> [...]
93
+ ```
94
+
95
+ `sbx run` uses the current directory as the project and `SBX_RUNTIME` as the
96
+ runtime (a short temp dir otherwise, printed on stderr). It prints an `ask`
97
+ line when a request parks and a `decided` line when it ends, then `done`;
98
+ with `--json` stdout carries only JSON lines. Its exit code mirrors the
99
+ agent's.
100
+
101
+ ## Undo layer
102
+
103
+ `overlay: true` (`sbx run --overlay`) mounts a per-run upper over the
104
+ project: the agent sees the real files, every write lands on the upper.
105
+ Review and press it down from the same runtime:
106
+
107
+ ```bash
108
+ SBX_RUNTIME=/tmp/sbx npx sbx diff [--agent <name>] # A/M/D, conflicts flagged
109
+ SBX_RUNTIME=/tmp/sbx npx sbx commit [--skip-conflicts] # refuses on conflicts by default
110
+ SBX_RUNTIME=/tmp/sbx npx sbx rollback # throw the paper away
111
+ ```
112
+
113
+ A path the project changed after the run started is a conflict: commit
114
+ refuses all of it unless `--skip-conflicts`. `node_modules` is invisible to
115
+ the layer (extend with `SBX_OVERLAY_IGNORE=a,b`). Commit strips setuid/setgid
116
+ and does not keep mtimes; a killed commit leaves a `.sbx-commit-*` folder in
117
+ the project that blocks the next diff/commit/run until you remove it. The
118
+ library equivalents are `diffOverlay`, `commitOverlay` and `rollbackOverlay`.
119
+ The overlay needs bubblewrap >= 0.11.0 for `--overlay` / `sbx diff|commit|rollback` (Ubuntu 24.04 ships 0.9.0: build from source or use a newer distro); plain runs work with older bwrap.
56
120
 
57
121
  ## Gotchas
58
122
 
@@ -63,14 +127,18 @@ deny and timeout answer 403 with the reason.
63
127
  `NODE_EXTRA_CA_CERTS`, `REQUESTS_CA_BUNDLE`, `CURL_CA_BUNDLE`,
64
128
  `GIT_SSL_CAINFO`. Without it every HTTPS call from inside fails
65
129
  verification. Only `ca.pem` enters the sandbox, never the key.
66
- - `createProxy` throws if `certDir` or `controlSocket` is not inside `runtime` (real paths, so symlinks don't help): the launcher masks only the runtime dir, and `ca.key` / the approve socket must stay behind it. The default `<runtime>/certs` always passes.
67
- - The upstream wall answers `403` for loopback, link-local (incl. `169.254.169.254`), the host's own addresses, private LAN ranges and unresolvable names. Every DNS answer is checked and the dial is pinned to the checked IP; `allowLoopback` is test-only.
68
- - The audit log (`logFile`) is created `0600`, but only when the file is new. `Authorization` and `Proxy-Authorization` values are logged as `[redacted]`; other headers (cookies, API-key headers) and bodies are logged as-is unless your `redact` hook shapes them (it runs after the built-in scrub).
69
- - `sbx` exits 0 ok, 1 unknown id / refused / socket failure, 2 usage.
130
+ - Certificates live in `<runtime>/certs` (`runtime` is required). There is no `certDir` option and no control socket: decisions flow through `<runtime>/asks` + `<runtime>/answers` or `hold.onAsk`.
131
+ - The upstream wall answers `403` for loopback, link-local (incl. `169.254.169.254`), the host's own addresses, private LAN ranges and unresolvable names. Every DNS answer is checked and the dial is pinned to the checked IP; test-only options live under `unsafeTestOnly` (`allowLoopback`, `resolveUpstream`) and production never sets them.
132
+ - The audit log (`logFile`) is set to `0600` every time a proxy starts. The values of `Authorization`, `Proxy-Authorization`, `Cookie`, `Set-Cookie`, `X-Api-Key`, `X-Auth-Token` and `Api-Key` are logged as `[redacted]`; other headers and bodies are logged as-is unless your `redact` hook shapes them (it runs after the built-in scrub).
133
+ - One proxy per runtime: `createProxy` throws "in use by pid N" (`run()` rejects, `sbx run` exits 1) while a live proxy owns the runtime. The claim is held by the proxy process and the kernel frees it when the process dies, so a crashed proxy never blocks the runtime. Use another `SBX_RUNTIME`, or leave it unset for a fresh one.
134
+ - `launch()` starts the agent in the project dir, in a new session (no controlling terminal). Locked drawers are 21 credential stores (see `LOCKED_PATHS` in `src/launcher.js`); the agent's own model credentials in `~/.claude` stay readable until keys move out of its reach.
135
+ - `sbx` exits 0 ok, 1 unknown id / refused / no live proxy / run failure, 2 usage; `sbx run` mirrors the agent's exit code.
70
136
  - Any listening unix socket under `$HOME` (IDE IPC, rootless-container sockets) is reachable from inside the sandbox: a read-only bind does not block `connect(2)`; the locked-paths list is the lever.
71
137
 
72
138
  ## What this package does not do
73
139
 
74
- Enforcement policy (which requests hold) arrives in a later module; this
75
- release parks by path rule. No Docker, no MCP server, no macOS/Windows —
140
+ Enforcement policy (which requests hold) arrives in a later module; until
141
+ then holds follow the interim rules above (a path rule for `createProxy`;
142
+ payment destinations plus non-GET/HEAD for `run()`). The hold decision never
143
+ sees the request body, so card numbers in a body are not caught yet. No Docker, no MCP server, no macOS/Windows —
76
144
  Linux only. POC harnesses live in `poc/` in the repo and never ship.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "barebox",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Lightweight local sandbox for AI agents: every write undoable, nothing leaves the machine without passing the doorman.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -37,7 +37,7 @@
37
37
  "redteam:m0": "bash poc/m0/redteam.sh",
38
38
  "bench": "node scripts/bench.mjs",
39
39
  "test": "env -u NODE_USE_ENV_PROXY -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY -u FTP_PROXY -u http_proxy -u https_proxy -u all_proxy -u ftp_proxy node --test --import ./test/setup-env.mjs \"test/*.test.mjs\"",
40
- "typecheck": "tsc --noEmit",
40
+ "typecheck": "tsc --noEmit && tsc -p tsconfig.scripts.json",
41
41
  "build:types": "tsc",
42
42
  "build:primitives": "node scripts/gen-primitives.mjs",
43
43
  "check:primitives": "node scripts/gen-primitives.mjs --check",
package/primitives.json CHANGED
@@ -1,23 +1,59 @@
1
1
  {
2
2
  "package": "barebox",
3
3
  "primitives": [
4
+ {
5
+ "name": "commitOverlay",
6
+ "category": "overlay",
7
+ "when": "Reach for this to press one run's tracing paper down: it stages the sandbox's changes and swaps them into the project by rename, refusing loudly on mid-run conflicts.",
8
+ "import": "import { commitOverlay } from 'barebox'",
9
+ "signature": "commitOverlay(opts: object) => {committed: string[], skipped: {path: string, reason: string}[]}",
10
+ "fails": "Throws (writing nothing) when any changed file was also changed in the project mid-run, unless onConflict is `skip`; throws on unsupported file kinds, on a project that moved mid-commit, and when bubblewrap is older than 0.11.0. A phase-2 failure undoes every journaled step: a full undo reports `nothing was applied`, a partial one throws `SBX_COMMIT_FAILED` listing exactly the steps not undone and keeping the commit folder (originals in `old/`) named in the error. Setuid/setgid bits are stripped from committed modes; mtimes are not preserved. A killed commit leaves a folder that blocks the next diff/commit/setup until removed.",
11
+ "example": "import { commitOverlay } from \"barebox\";\nconst { committed, skipped } = commitOverlay({ runtime: \"/tmp/sbx-abc\", agent: \"agent\" });\nconsole.log(`committed ${committed.length} file(s), skipped ${skipped.length}`);"
12
+ },
4
13
  {
5
14
  "name": "createProxy",
6
15
  "category": "proxy",
7
16
  "when": "Reach for this HARNESS-ONLY to run the front door: it terminates agent TLS, sees every request, and parks the ones a human must decide. It decides nothing itself; pair with the launcher for sandboxes and `sbx` for decisions.",
8
17
  "import": "import { createProxy } from 'barebox'",
9
18
  "signature": "createProxy(opts: ProxyOptions)",
10
- "fails": "Throws synchronously on a missing `logFile` (or neither `certDir` nor `runtime`). At runtime, dead upstreams, malformed input, over-cap and timed-out holds all become loud logged HTTP errors, never silence and never a crash. A second proxy on the same port rejects `ready`, never crashes the process.",
11
- "example": "import { createProxy } from \"barebox\";\nconst proxy = createProxy({ port: 0, certDir: \"./certs\", logFile: \"./mitm.log\" });\nconst { port } = await proxy.ready;\nawait proxy.close();"
19
+ "fails": "Throws synchronously on a missing `logFile` or `runtime`. Throws when another live proxy owns the runtime; the claim dies with its process; nothing is ever taken over. At runtime, dead upstreams, malformed input, over-cap and timed-out holds all become loud logged HTTP errors, never silence and never a crash. A second proxy on the same port rejects `ready`, never crashes the process.",
20
+ "example": "import { createProxy } from \"barebox\";\nconst proxy = createProxy({ port: 0, runtime: \"./sbx-runtime\", logFile: \"./mitm.log\" });\nconst { port } = await proxy.ready;\nawait proxy.close();"
21
+ },
22
+ {
23
+ "name": "diffOverlay",
24
+ "category": "overlay",
25
+ "when": "Reach for this to review one run's tracing paper: it lists every file the sandboxed run added, modified or deleted, flagging the ones the project changed meanwhile.",
26
+ "import": "import { diffOverlay } from 'barebox'",
27
+ "signature": "diffOverlay(opts: object) => OverlayChange[]",
28
+ "fails": "Throws when no overlay exists for the agent, when the project is gone, when a leftover commit folder blocks, when bubblewrap is older than 0.11.0, or when the overlay view cannot be mounted; never writes anything.",
29
+ "example": "import { diffOverlay } from \"barebox\";\nconst changes = diffOverlay({ runtime: \"/tmp/sbx-abc\", agent: \"agent\" });\nfor (const c of changes) console.log(c.status, c.path, c.conflict ? \"(CONFLICT)\" : \"\");"
12
30
  },
13
31
  {
14
32
  "name": "launch",
15
33
  "category": "launcher",
16
- "when": "Reach for this to HARNESS-ONLY start one sandboxed agent run: it creates the sandbox the agent lives in. It does not decide anything; combine with the proxy for the front door and the gate (M3) for policy.",
34
+ "when": "Reach for this to HARNESS-ONLY start one sandboxed agent run: it creates the sandbox the agent lives in. It does not decide anything; combine with the proxy for the front door and the gate (M3) for policy. Pass overlay:true for a writable tracing-paper run (M4). The agent starts in the project dir.",
17
35
  "import": "import { launch } from 'barebox'",
18
36
  "signature": "launch(opts: object) => ChildProcess",
19
- "fails": "Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, or when `runtime` IS `HOME` or the project dir (its sockets could not be hidden from the agent). The child fails at runtime (nonzero exit) when `bwrap` or `socat` is missing inside, or when nothing listens on the agent socket.",
37
+ "fails": "Throws synchronously on a missing/empty `runtime`, `agent`, `proj`, or `command`, on a bad agent name, on a non-integer `proxyPort`, on an over-long socket path, when `socket` disagrees with `<runtime>/socks/<agent>.sock`, when `runtime` IS `HOME` or the project dir (its sockets could not be hidden from the agent), or with overlay on when the runtime sits inside the project or uncommitted changes linger. The child fails at runtime (nonzero exit) when `bwrap` or `socat` is missing inside, or when nothing listens on the agent socket.",
20
38
  "example": "import { launch } from \"barebox\";\nconst child = launch({ runtime: \"/tmp/sbx\", agent: \"fx\", proj: \"/tmp/proj\", command: [\"bash\", \"-c\", \"echo hi\"] });\nawait new Promise((r) => child.on(\"close\", r)); // child.exitCode === 0"
39
+ },
40
+ {
41
+ "name": "rollbackOverlay",
42
+ "category": "overlay",
43
+ "when": "Reach for this to throw one run's tracing paper away: it drops every sandboxed change and leaves the project exactly as it was.",
44
+ "import": "import { rollbackOverlay } from 'barebox'",
45
+ "signature": "rollbackOverlay(opts: object) => {discarded: OverlayChange[], exact: boolean, why: string|null}",
46
+ "fails": "Throws when no overlay exists for the agent or its record is corrupt, or when the overlay folder cannot be removed even after a permission repair (the error names the folder). Listing the changes never throws and never invents entries: an unlistable upper reports `discarded: []` with the reasons in `why`. Removal depends on neither listing nor the first permission pass: a partial failure retries removal once after a fresh permission pass. Dropping the upper never touches the project.",
47
+ "example": "import { rollbackOverlay } from \"barebox\";\nconst { discarded } = rollbackOverlay({ runtime: \"/tmp/sbx-abc\", agent: \"agent\" });\nconsole.log(`discarded ${discarded.length} change(s)`);"
48
+ },
49
+ {
50
+ "name": "run",
51
+ "category": "run",
52
+ "when": "Reach for this to HARNESS-ONLY run one sandboxed agent start-to-finish in a single call: it starts the proxy, sandboxes the command, answers holds, and returns the exit code with the ask and audit trail (plus the overlay diff once M4 exists).",
53
+ "import": "import { run } from 'barebox'",
54
+ "signature": "run(opts: object) => Promise<{ exit: number, asks: AskRecord[], audit: string, diff: OverlayChange[], runtime: string }>",
55
+ "fails": "Rejects on a missing/unreadable `proj`, an empty `command`, a bad `mode`, a misshapen `onAsk`, a proxy that never becomes ready, a `launch` that throws (uncommitted overlay changes, a runtime inside the project — the proxy is closed first), or an overlay diff that cannot be read. The agent's own nonzero exit is returned as `exit`, never thrown.",
56
+ "example": "import { run } from \"barebox\";\nconst { exit, asks, audit } = await run({ proj: \"/tmp/proj\", command: [\"bash\", \"-c\", \"echo hi\"] });"
21
57
  }
22
58
  ]
23
59
  }
package/src/certs.js CHANGED
@@ -7,7 +7,8 @@ import { execFile } from 'node:child_process';
7
7
  import { mkdirSync, chmodSync, existsSync, writeFileSync, rmSync } from 'node:fs';
8
8
  import { join } from 'node:path';
9
9
 
10
- const HOST_RE = /^[A-Za-z0-9.-]+$/;
10
+ /** Hostname/IP spelling both the mint cache and the proxy wall accept. Single definition (see proxy.js). */
11
+ export const HOST_RE = /^[A-Za-z0-9.-]+$/;
11
12
 
12
13
  function sh(file, args) {
13
14
  return new Promise((resolve, reject) => {