barebox 0.4.0 → 0.6.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 +79 -0
- package/README.md +37 -23
- package/barebox.context.md +196 -13
- package/package.json +7 -2
- package/primitives.json +10 -1
- package/src/cardscan.js +96 -0
- package/src/cli.js +29 -4
- package/src/config.js +147 -0
- package/src/holds.js +76 -48
- package/src/index.js +1 -0
- package/src/labels.js +94 -0
- package/src/launcher.js +52 -7
- package/src/policy.js +141 -0
- package/src/proxy.js +599 -161
- package/src/run.js +40 -71
- package/src/runtime.js +7 -2
- package/src/secrets.js +113 -0
- package/src/wall.js +12 -6
- package/types/cardscan.d.ts +17 -0
- package/types/cli.d.ts +1 -1
- package/types/config.d.ts +59 -0
- package/types/holds.d.ts +25 -46
- package/types/index.d.ts +1 -0
- package/types/labels.d.ts +27 -0
- package/types/launcher.d.ts +10 -2
- package/types/policy.d.ts +64 -0
- package/types/proxy.d.ts +87 -33
- package/types/run.d.ts +61 -11
- package/types/runtime.d.ts +3 -1
- package/types/secrets.d.ts +63 -0
- package/types/wall.d.ts +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,85 @@ 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.6.0] - 2026-11-01
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Keys the agent never holds. Config keys `secrets` (`NAME` -> `{ fromEnv` or `value, hosts }`) and `env` (`{ pass, set }`); `run()` takes `secrets` and `env`, `createProxy()` takes `secrets` (the list `loadSecrets` in the new `src/secrets.js` builds), `launch()` takes `env: { pass, set, placeholders }`. The sandbox gets a random placeholder per secret, new each run, under the secret's name. The proxy swaps the real value into request headers (a substring, also inside a decoded `Basic <base64>`) only after the gate allowed the request and only for the secret's hosts, and only into a request that goes upstream over TLS. A placeholder headed for any other host is refused `403 denied: secret.host`, and one headed for a bound host over plain http `403 denied: secret.scheme`, in every mode. Each hit is a `secret` annotate line in `gate.jsonl` (`meta: { agent, rid, name, host, swapped }`); the value is never in the audit, an ask or an error body. `env.pass` refuses names matching `KEY|TOKEN|SECRET|PASSWORD` (any case); a `fromEnv` variable that is unset exits 2 naming the secret. Headers only; the agent's own sign-in in `~/.claude` stays readable.
|
|
12
|
+
- The sandbox sets `NODE_USE_ENV_PROXY=1` next to the proxy variables, so Node's built-in `fetch` uses the proxy.
|
|
13
|
+
- `loadLabels` is exported from `barebox`: an embedder builds the `labels` value `run()` and `createProxy()` take (`{ matcher, tools, dirs }`) without the `sbx` CLI.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- The host environment no longer reaches the sandbox. The inside gets barebox's own variables (`HOME`, `PATH`, the proxy and CA variables), `TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*`, `TZ`, `USER`, `LOGNAME`, `SHELL`, `EDITOR`, `PAGER`, the config `env.pass` names, `env.set`, one placeholder per secret, and `extraEnv`. A caller that relied on an inherited variable lists it in `env.pass` (or passes `launch({ env })` / `extraEnv`). `launch()` still looks `bwrap` up on your `PATH` but starts it with `PATH=/usr/bin:/bin`.
|
|
18
|
+
- Requires Node.js >= 22.21 (was >= 22): the sandbox sets `NODE_USE_ENV_PROXY=1`, honoured from v22.21.0 (the test suite also uses `tls.setDefaultCACertificates`, v22.19.0).
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- A held request refused for being over the body cap could answer 500 instead of 403 when a body write was still in flight.
|
|
23
|
+
|
|
24
|
+
### Security
|
|
25
|
+
|
|
26
|
+
- The host environment no longer reaches the sandbox: before, every host variable (an exported API key, `SBX_RUNTIME`) was readable inside, in `env` and in `/proc/*/environ`. `bwrap` is started with a clean environment, so `/proc/1/environ` inside is clean too.
|
|
27
|
+
- The mode no longer changes with `BAREGUARD_RWX_LETTERS` or `BAREGUARD_BUDGET_FILE` in the host environment: the gate gets its letters explicitly and no shared budget file, so a user shell or parent process that exports them cannot widen, break or budget-deny a run.
|
|
28
|
+
|
|
29
|
+
## [0.5.0] - 2026-10-30
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
- One config file, `${XDG_CONFIG_HOME:-$HOME/.config}/barebox/config.json`, read by the CLI only (`sbx run`). Keys: `mode`, `holdTimeoutSec` (a positive integer or `"never"`), `heldBodyMaxMB` (a positive integer), `localLlm` (an array of `"host:port"`). A flag beats the file, the file beats the default. An unknown key, a bad value or bad JSON makes `sbx run` exit 2, naming the file and the key.
|
|
34
|
+
- The card floor now looks inside bodies: an allowed request whose body is 64 KB or less and holds a card number (13-19 digits, optional single space or dash between digits, first digit 2-6, Luhn-valid) parks as an ask with rule `flags.cardLike` in every mode, `trust` included. Nothing is denied because of a card. Bodies over 64 KB stream through unchecked for cards (known gap). Each agent has one 64 KB working slot, so allowed body-carrying requests read their body one at a time per agent.
|
|
35
|
+
- Held bodies are spooled to `<runtime>/held/<id>` (a 0600 file in an owner-only dir), never kept in memory, and deleted whenever the hold ends. `runtimePaths` gains `heldDir` and `heldFile(id)`; `run()` gains the `heldBodyMaxBytes` option.
|
|
36
|
+
- The `sbx` CLI starts Node with `--max-semi-space-size=1` (caps the V8 young generation to hold proxy memory down; latency unchanged).
|
|
37
|
+
- `holds.js` exports `ASK_BODY_LIMIT`, `DEFAULT_HOLD_MAX_BODY` and `bodyPreview`.
|
|
38
|
+
- bareguard decides every request: one `gate.check()` per request, one gate per agent (and one for the TCP door's `tcp` agent), all sharing one tools table. `src/policy.js` exports `MODES` and `gateFor`. Modes: `ask` holds `r--` and asks for w and x; `auto` holds `rw-` and asks for x; `trust` holds `rwx`. GET/HEAD are r; POST/PUT/PATCH/DELETE are x; any other method is denied (`rwx.unlisted`).
|
|
39
|
+
- The floor is two bareguard flags, `cardLike` and `paymentPath` (`/checkout`, `/payment`, `/orders`, `/purchase`), which ask in every mode, `trust` included.
|
|
40
|
+
- `createProxy` option `gateFor(agent, { humanChannel })`: returns a bareguard `Gate` or any object with `async check(action)` resolving `{ outcome, rule?, reason? }`; `askHuman` from a plain object goes to the same hold queue. Without it nothing is checked.
|
|
41
|
+
- One audit file: `<runtime>/gate.jsonl` (`runtimePaths(runtime).audit`; `createProxy`'s `logFile` names it). Every line is in bareguard's shape. bareguard's gate lines carry the decision; a response status is a `record` line joined to its decision line by `aid`; barebox's own facts are `annotate` lines with `surface:false`, keyed by `verdict`: `deny`, `hold`, `decide`, `hold-abandoned`, `hold-queue-full`, `stale-answer`, `malformed-answer`, `body`, and `resp` in forward-all mode. A request with a body gets one `body` line with `meta: { agent, rid, bodyBytes, bodySha256 }`, joined to its gate line by `rid`.
|
|
42
|
+
- A runtime-level audit-only `sbx` gate takes lines for agents whose gate is not built, and every line when `gateFor` is omitted. `close()` waits up to 3 s for pending audit writes; later lines are dropped.
|
|
43
|
+
- `GateLike` gains optional `record`, `annotate` and `drainAnnotations`; `check` may return `aid`.
|
|
44
|
+
- Config key `localLlm` and the `allowLocal` option of `run()` and `createProxy()`: exact `host:port` pairs (such as a local model server) pass the wall's private/loopback check; link-local (cloud metadata) never does. `checkUpstream` takes a port argument.
|
|
45
|
+
- New dependency: `bareguard` 0.30.0 (exact).
|
|
46
|
+
- rwxmap labels. Two config keys: `labels` (folders the rwxmap CLI wrote) and `tenants` (vendor -> server URLs, replacing placeholder hosts such as `your-domain.atlassian.net`). `src/labels.js` exports `loadLabels({ labels, tenants })`, which reads each `<v>.rwxmap.review.json` for request keys (via `rwxmap/match`). The letters come only from the matching `<v>.rwxmap.json` file's `bareguard.tools`, the file you review and can edit; rwxmap's own guessed letter is never used. A bad or missing label file fails `sbx run` before any agent starts.
|
|
47
|
+
- The tool for a request is the label's key when a label documents it, else a model endpoint key (`r`), else `http.<METHOD>`. A key a label documents but the gate file lacks (a row you deleted) is denied (`rwx.unlisted`).
|
|
48
|
+
- Model endpoints are `r`: Anthropic `/v1/messages` and `/v1/messages/count_tokens`; OpenAI `/v1/chat/completions`, `/v1/responses` and `/v1/embeddings`; and on each `localLlm` host:port `/api/chat`, `/api/generate`, `/api/embed`, `/v1/chat/completions` and `/v1/completions` (http only).
|
|
49
|
+
- `src/policy.js` exports `buildTools`, `toolFor` and `emptyMatcher`; `gateFor` takes `tools`; `createProxy` and `run()` take `labels`; `launch()` takes `maskDirs`.
|
|
50
|
+
- `npm run bench:agents` (`scripts/bench-agents.mjs`): the proxy's memory at 10 / 20 / 30 / 40 agents, each at the full worst case (1 parked + 16 waiting + a filled body slot), proxy in its own process with forced GC. Exits 1 above 175 MB at up to 40 agents, or above 10 MB per sandbox walls.
|
|
51
|
+
- One proxy serves at most 40 agents: `addAgent` throws an error naming the limit and telling you to run another proxy. The TCP door's `tcp` agent does not count; `removeAgent` frees a place.
|
|
52
|
+
- Held bodies are spooled to disk and released from memory as soon as they are written (68 held bodies grow `arrayBuffers` by 0.28 MB).
|
|
53
|
+
- New dependency: `rwxmap` 0.8.0 (exact). Label files written before rwxmap 0.8.0 fail to load with rwxmap's "regenerate" message.
|
|
54
|
+
|
|
55
|
+
### Changed
|
|
56
|
+
|
|
57
|
+
- The proxy memory budget is a range, about 145-175 MB in the full worst case at 40 agents (was 80 MB, retired: about 53 MB is Node's own code). barebox is for small teams: free, local and lightweight, built to assist and to connect to many tools, not to run swarms or thousands of agents. Measured about 100 / 113-120 / 127-133 / 143-172 MB at 10 / 20 / 30 / 40 agents, quiet to busy machine; normal use about 85-120 MB.
|
|
58
|
+
- `hold.maxBody` now defaults to 52428800 (50 MB), was 1048576. A body over the cap is denied `403 body too large to hold`.
|
|
59
|
+
- The audit file carries a body's length and SHA-256 only (the `body` line), never its content. The ask payload carries the 4 KB `bodyPreview` (card numbers masked except the last 4).
|
|
60
|
+
- Long audit fields are cut before they reach bareguard (`url` to 400 characters, `note` and `reason` to 200), so the ids that join an ask to its outcome survive bareguard's 1000-byte `meta` limit.
|
|
61
|
+
- A denial reads `403 denied: <rule>[: reason]`; an ask carries the gate's rule (`rwx.ask`, `flags.cardLike`, `flags.paymentPath`) and letter.
|
|
62
|
+
- Request bodies of 64 KB or less are read in the agent's working slot before the gate decides; a waiting request's body is spooled to `<runtime>/held/<id>` when it enters the hold line.
|
|
63
|
+
- `holds.add` takes `preview`, `bodyBytes` and `bodyFile` in place of `body` (internal shape).
|
|
64
|
+
|
|
65
|
+
### Known
|
|
66
|
+
|
|
67
|
+
- Memory varies with machine load: identical 40-agent runs read 143-172 MB. Audit file size does not move it (205 MB of audit read the same as 3 MB), though the first ask of each gate still reads the whole file. Under 54,000 more allowed requests memory stayed flat (98.7–99.0 MB).
|
|
68
|
+
- `BAREGUARD_RWX_LETTERS` set in the shell that starts `sbx` overrides the mode letters (for example `--mode ask` then allows a POST without asking), because barebox passes no explicit letters. The sandboxed agent cannot set it.
|
|
69
|
+
- Held bodies can add up to about 2 GB on disk in the runtime dir (50 MB cap per request, 40 agents).
|
|
70
|
+
- API keys inside a body still show in the ask file's 4 KB preview.
|
|
71
|
+
|
|
72
|
+
### Removed
|
|
73
|
+
|
|
74
|
+
- **Breaking:** the `createProxy` option `maxLogBody`.
|
|
75
|
+
- **Breaking:** the separate `<runtime>/audit.jsonl` and the `runtimePaths().gateAudit` path; `runtimePaths().audit` is now `gate.jsonl`.
|
|
76
|
+
- The `req` audit line and request-header logging: no request header is written to the audit file. `scrubSecrets` and `SENSITIVE_HEADERS` are gone; the `redact` hook stays and now shapes annotate `meta`.
|
|
77
|
+
- **Breaking:** `hold.shouldHold` and `hold.match` (replace with `gateFor`); `run()`'s internal `shouldHoldForMode` and `holds.js`'s `matchPath` / `ShouldHold` type.
|
|
78
|
+
|
|
79
|
+
### Security
|
|
80
|
+
|
|
81
|
+
- The audit file holds no request header and no body content. Card numbers are masked in the ask files' 4 KB preview. Known gap: other secrets inside a body still show in the ask file's preview until bareguard redaction lands.
|
|
82
|
+
- The config file is hidden inside the sandbox wherever it resolves (the mask follows `XDG_CONFIG_HOME`).
|
|
83
|
+
- Label folders are hidden inside the sandbox the same way, so the agent cannot rewrite a letter for the next run.
|
|
84
|
+
- The modes decide, with no keyword patterns: the gate runs with empty content patterns, so no word in a URL or method (`remove`, `drop`, `TRUNCATE TABLE`) asks or denies on its own. Only the mode letters, the labels and the floor (card number, payment path) decide.
|
|
85
|
+
|
|
7
86
|
## [0.4.0] - 2026-10-29
|
|
8
87
|
|
|
9
88
|
### Changed
|
package/README.md
CHANGED
|
@@ -15,11 +15,8 @@
|
|
|
15
15
|
<img src="https://img.shields.io/github/package-json/v/hamr0/barebox?label=version&color=2a4f8c" alt="version (auto from package.json)">
|
|
16
16
|
<img src="https://img.shields.io/badge/license-Apache%202.0-2a4f8c" alt="license: Apache 2.0">
|
|
17
17
|
<img src="https://img.shields.io/badge/platform-Linux-2a4f8c" alt="platform: Linux">
|
|
18
|
-
<img src="https://img.shields.io/badge/status-POC-c0841a" alt="status: POC">
|
|
19
18
|
</p>
|
|
20
19
|
|
|
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
|
-
|
|
23
20
|
## Why
|
|
24
21
|
|
|
25
22
|
Agents need real access to be useful — shell, files, network. Today you pick one of two bad options:
|
|
@@ -42,9 +39,9 @@ Three letters, each handled differently — the same `r`/`w`/`x` as [bareguard](
|
|
|
42
39
|
The agent works in your house:
|
|
43
40
|
|
|
44
41
|
- **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
|
|
42
|
+
- **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 (a known gap: those tokens refresh themselves).
|
|
46
43
|
- **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
|
-
- **Keys it never holds.** The agent types a placeholder; the doorman puts the real API key in the request header only after
|
|
44
|
+
- **Keys it never holds.** The agent types a placeholder; the doorman puts the real API key in the request header only after the request is allowed, and only for the hosts that key is bound to. Your environment does not reach the sandbox.
|
|
48
45
|
|
|
49
46
|
## What it isn't
|
|
50
47
|
|
|
@@ -75,34 +72,51 @@ The agent works in your house:
|
|
|
75
72
|
- **Walls** are [bubblewrap](https://github.com/containers/bubblewrap), unprivileged: separate net/pid/ipc/uts namespaces, read-only binds, tmpfs over locked paths.
|
|
76
73
|
- **Identity** is the socket, not a header the agent could fake. One socket per agent, all into one proxy.
|
|
77
74
|
- **HTTPS inspection** uses a local CA that exists only inside the sandbox; the proxy reads method, URL, headers and body, then forwards.
|
|
78
|
-
- **The doorman's x-rules**, strongest first: card numbers in the body (Luhn) → payment
|
|
75
|
+
- **The doorman's x-rules**, strongest first: card numbers in the body (Luhn) → payment paths (`/checkout`, `/payment`, `/orders`, `/purchase`; a list of payment domains is not built) → rwxmap labels for known APIs → every other request by its letter and the mode (`ask`, `auto`, `trust`; see `barebox.context.md`). The card and payment floor asks in every mode, `trust` included; card numbers are checked in bodies of 64 KB or less.
|
|
79
76
|
- **Approvals** come from a second terminal (`sbx pending`, `sbx approve <id>`, `sbx deny <id>`). Timeout means deny, with a clear `403` reason. One held request per agent at a time: later ones wait in line (16 at most, then `429 hold queue full`), and the deadline counts from arrival.
|
|
80
77
|
|
|
78
|
+
## Keys the agent never holds
|
|
79
|
+
|
|
80
|
+
Put the key in `~/.config/barebox/config.json`, bound to its hosts:
|
|
81
|
+
|
|
82
|
+
```json
|
|
83
|
+
{
|
|
84
|
+
"secrets": {
|
|
85
|
+
"STRIPE_API_KEY": { "fromEnv": "REAL_STRIPE_KEY", "hosts": ["api.stripe.com"] }
|
|
86
|
+
},
|
|
87
|
+
"env": { "pass": ["MY_TOOL_HOME"] }
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Inside the sandbox `$STRIPE_API_KEY` is a random placeholder, new each run. The agent sends it as it would the key (`curl -H "Authorization: Bearer $STRIPE_API_KEY"`, `curl -u "$STRIPE_API_KEY:"`). The proxy swaps the real value into the request headers only after the request is allowed, and only for `api.stripe.com`. A denied request never leaves. The same placeholder sent to any other host is refused: `403 denied: secret.host`. A real value is swapped only into a request that goes upstream over TLS: a placeholder to a bound host over plain `http://` is refused `403 denied: secret.scheme`. The rest of your environment stays out too, except a short default list (`TERM`, `LANG`, `LC_*`, `TZ`, ...) and the names in `env.pass`; `env.pass` refuses names like `*_TOKEN` and `*_KEY` (use `secrets`). Headers only. Details: `barebox.context.md`.
|
|
92
|
+
|
|
81
93
|
## Numbers
|
|
82
94
|
|
|
83
95
|
Measured, not estimated. Fedora, kernel 7.2, bubblewrap 0.12.0, Node 22.
|
|
84
96
|
|
|
85
97
|
| | barebox (measured) | [srt](https://github.com/anthropic-experimental/sandbox-runtime) 0.0.81 (measured) |
|
|
86
98
|
|---|---|---|
|
|
87
|
-
| Memory per sandbox | **7.8 MB** mean,
|
|
88
|
-
| Proxy | one shared
|
|
89
|
-
| Start + exit | **10 ms** (M0 POC; unmeasured on the rewrite
|
|
90
|
-
|
|
|
99
|
+
| Memory per sandbox | **7.8 MB** mean, 8.0 MB max | ~100 MB (each sandbox runs its own proxy) |
|
|
100
|
+
| Proxy | one shared: **about 85-120 MB** in normal use; **about 100 / 113-120 / 127-133 / 145-175 MB** at 10 / 20 / 30 / 40 agents in the full worst case (each agent with 1 parked + 16 waiting + a filled body slot). The low end is a quiet machine, the high end a busy one | one per sandbox |
|
|
101
|
+
| Start + exit | **10 ms** (M0 POC; unmeasured on the rewrite, TODO re-measure) | 1.87-2.05 s |
|
|
102
|
+
| 10 agents | ~180 MB worst case (proxy + 10 x 8 MB) | ~1 GB |
|
|
103
|
+
| 20 agents | ~275-280 MB worst case | ~2 GB |
|
|
104
|
+
| 40 agents | ~465-495 MB worst case | not measured |
|
|
91
105
|
|
|
92
|
-
|
|
106
|
+
barebox is for small teams: free, local and lightweight, built to assist and to connect to many tools, not to run swarms or thousands of agents. Budget: shared proxy about 145-175 MB in the full worst case at 40 agents, each extra sandbox 10 MB or less. 40 agents per proxy is the maximum and it is enforced: `addAgent` refuses the 41st with an error telling you to run another proxy. Above 40, run more proxies. Machine load moves the number. A long audit file does not: 205 MB of audit measured the same as 3 MB. 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
107
|
|
|
94
108
|
## Roadmap
|
|
95
109
|
|
|
96
|
-
| Module | What |
|
|
97
|
-
|
|
98
|
-
| M0 | Walls + front door |
|
|
99
|
-
| M1 | Proxy sees inside HTTPS (curl, node, python requests, git) |
|
|
100
|
-
| M2 | Hold one `x` request, ask, keep everything else running |
|
|
101
|
-
| M3 | Decide r/w/x deterministically (rwxmap + bareguard), audit log |
|
|
102
|
-
| M4 | Undo layer: `diff`, `commit`, `rollback`, conflict flagging |
|
|
103
|
-
| M5 | Keys the agent never holds |
|
|
104
|
-
| M6 | Scale run: 20 agents + shared proxy |
|
|
105
|
-
| M7 | Demos: payment held for approval; prompt-injected `~/.ssh` exfil blocked |
|
|
110
|
+
| Module | What |
|
|
111
|
+
|---|---|
|
|
112
|
+
| M0 | Walls + front door |
|
|
113
|
+
| M1 | Proxy sees inside HTTPS (curl, node, python requests, git) |
|
|
114
|
+
| M2 | Hold one `x` request, ask, keep everything else running |
|
|
115
|
+
| M3 | Decide r/w/x deterministically (rwxmap + bareguard), audit log |
|
|
116
|
+
| M4 | Undo layer: `diff`, `commit`, `rollback`, conflict flagging |
|
|
117
|
+
| M5 | Keys the agent never holds |
|
|
118
|
+
| M6 | Scale run: 20 agents + shared proxy |
|
|
119
|
+
| M7 | Demos: payment held for approval; prompt-injected `~/.ssh` exfil blocked |
|
|
106
120
|
|
|
107
121
|
M0–M2 are the go/no-go. Later: macOS (`sandbox-exec` + APFS clones), Windows via WSL2, Landlock/seccomp hardening. Full spec: [the PRD](docs/product/agent-sandbox-prd.md).
|
|
108
122
|
|
|
@@ -112,11 +126,11 @@ M0–M2 are the go/no-go. Later: macOS (`sandbox-exec` + APFS clones), Windows v
|
|
|
112
126
|
npm install barebox
|
|
113
127
|
```
|
|
114
128
|
|
|
115
|
-
Requires Node.js >= 22.
|
|
129
|
+
Requires Node.js >= 22.21. Two production dependencies, [bareguard](https://npmjs.com/package/bareguard) (the gate) and [rwxmap](https://npmjs.com/package/rwxmap) (the labels), pinned exactly. 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, copies its Node into `/usr/bin` (the sandbox binds `/usr` only, so a Node installed elsewhere, such as under nvm, is not found inside), 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
130
|
|
|
117
131
|
## Try the POCs
|
|
118
132
|
|
|
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.
|
|
133
|
+
Linux only, with `bwrap` (>= 0.11.0 only for the overlay), `socat`, `openssl`, Node >= 22.21 and Python 3. Needs a normal shell (namespaces + listening sockets), not a tool sandbox. The POCs are throwaway proofs, not the product.
|
|
120
134
|
|
|
121
135
|
```
|
|
122
136
|
git clone https://github.com/hamr0/barebox && cd barebox
|
package/barebox.context.md
CHANGED
|
@@ -5,7 +5,7 @@ nothing leaves the machine without passing the doorman.
|
|
|
5
5
|
|
|
6
6
|
## Install
|
|
7
7
|
|
|
8
|
-
Requires Node >= 22 and Linux with unprivileged user namespaces (bwrap)
|
|
8
|
+
Requires Node >= 22.21 and Linux with unprivileged user namespaces (bwrap)
|
|
9
9
|
for sandboxes; the proxy and CLI run anywhere Node runs.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
@@ -55,8 +55,8 @@ await proxy.close();
|
|
|
55
55
|
|
|
56
56
|
## Holds (human approval)
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
through the file checkpoint (`<runtime>/asks` + `<runtime>/answers`):
|
|
58
|
+
When a request needs a decision (see "Modes and the gate" below), it parks.
|
|
59
|
+
Decide from a second terminal through the file checkpoint (`<runtime>/asks` + `<runtime>/answers`):
|
|
60
60
|
|
|
61
61
|
```bash
|
|
62
62
|
SBX_RUNTIME=/tmp/sbx npx sbx pending
|
|
@@ -69,7 +69,7 @@ time spent in line and reading the body counts too, and a request past its
|
|
|
69
69
|
deadline is denied `hold timeout` whether waiting, sending, or parked. Each
|
|
70
70
|
agent holds at most one request being read or parked; later ones wait in
|
|
71
71
|
line, unread, in order — at most 16, the next gets `429 hold queue full`.
|
|
72
|
-
Approve forwards, deny and timeout answer 403 with the reason. These commands
|
|
72
|
+
Approve forwards, deny and timeout answer 403 with the reason. A held body is spooled to `<runtime>/held/<id>` (never kept in memory, deleted when the hold ends); one over `hold.maxBody` (default 50 MB) is denied `403 body too large to hold`. These commands
|
|
73
73
|
need the proxy to be alive: with no live proxy on the runtime `sbx pending`,
|
|
74
74
|
`approve` and `deny` exit 1 and say so, because nothing would read the answer.
|
|
75
75
|
|
|
@@ -77,9 +77,9 @@ need the proxy to be alive: with no live proxy on the runtime `sbx pending`,
|
|
|
77
77
|
|
|
78
78
|
`run()` starts the proxy, sandboxes one command, answers holds and returns
|
|
79
79
|
the exit code with the ask and audit trail. Modes: `ask`, `auto` (default),
|
|
80
|
-
`trust
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
`trust`; see "Modes and the gate" below. `run()` takes `heldBodyMaxBytes` to
|
|
81
|
+
change the held-body cap and `allowLocal` (the `localLlm` setting) to let
|
|
82
|
+
exact `host:port` pairs, such as a local model server, past the wall.
|
|
83
83
|
|
|
84
84
|
```js no-run
|
|
85
85
|
import { run } from "barebox";
|
|
@@ -102,6 +102,188 @@ line when a request parks and a `decided` line when it ends, then `done`;
|
|
|
102
102
|
with `--json` stdout carries only JSON lines. Its exit code mirrors the
|
|
103
103
|
agent's.
|
|
104
104
|
|
|
105
|
+
`sbx run` reads one optional config file,
|
|
106
|
+
`${XDG_CONFIG_HOME:-$HOME/.config}/barebox/config.json`, with keys `mode`,
|
|
107
|
+
`holdTimeoutSec` (positive integer or `"never"`), `heldBodyMaxMB`
|
|
108
|
+
(positive integer) and `localLlm` (array of `"host:port"`). A flag beats the file, the file beats the default; an
|
|
109
|
+
unknown key, bad value or bad JSON exits 2 naming the file and key. The file
|
|
110
|
+
is hidden inside the sandbox wherever it resolves. The library does not read it.
|
|
111
|
+
Two more keys, `labels` and `tenants`, are described under "Labels and model endpoints". Two more, `env` and `secrets`, are described under "Keys the agent never holds".
|
|
112
|
+
|
|
113
|
+
## Modes and the gate
|
|
114
|
+
|
|
115
|
+
Every request becomes one bareguard `gate.check()`; `run()` builds one gate
|
|
116
|
+
per agent (and one for the TCP door's `tcp` agent), all sharing one tools
|
|
117
|
+
table. The mode picks the agent's rwx letters:
|
|
118
|
+
|
|
119
|
+
| Mode | Letters | Asks for |
|
|
120
|
+
|---|---|---|
|
|
121
|
+
| `ask` | `r--` | `w`, `x` |
|
|
122
|
+
| `auto` (default) | `rw-` | `x` |
|
|
123
|
+
| `trust` | `rwx` | nothing |
|
|
124
|
+
|
|
125
|
+
`GET`/`HEAD` are `r`; `POST`/`PUT`/`PATCH`/`DELETE` are `x`; any other method
|
|
126
|
+
is denied in every mode (`rwx.unlisted`). Without a label a request is the tool
|
|
127
|
+
`http.<METHOD>` (see "Labels and model endpoints"). The gate runs with empty
|
|
128
|
+
content patterns, so no word in a URL or method asks or denies on its own: the
|
|
129
|
+
mode letters, the labels and the floor decide. The floor is two bareguard flags,
|
|
130
|
+
`cardLike` (a body of 64 KB or less holding a card number: 13-19 digits,
|
|
131
|
+
optional single space or dash, first digit 2-6, Luhn-valid) and `paymentPath`
|
|
132
|
+
(`/checkout`, `/payment`, `/orders`, `/purchase`); both ask in every mode,
|
|
133
|
+
`trust` included. Nothing is denied because of a card. Bodies over 64 KB
|
|
134
|
+
stream through unscanned. The body never enters the gate's action.
|
|
135
|
+
|
|
136
|
+
barebox's hold queue is each gate's `humanChannel`: the ask files, `onAsk`
|
|
137
|
+
and `sbx approve|deny` work as above, and the ask carries the gate's `rule`
|
|
138
|
+
(`rwx.ask`, `flags.cardLike`, `flags.paymentPath`) and `letter`. A request
|
|
139
|
+
with a body of 64 KB or less is read in the agent's working slot before the
|
|
140
|
+
gate decides. Denials read `403 denied: <rule>[: reason]` (a human or timeout
|
|
141
|
+
denial reads `denied: <reason>`).
|
|
142
|
+
|
|
143
|
+
`createProxy` takes `gateFor(agent, { humanChannel, tools })`, called once per agent,
|
|
144
|
+
returning a bareguard `Gate` or any object with `async check(action)` that
|
|
145
|
+
resolves `{ outcome: "allow" | "deny" | "askHuman", rule?, reason? }`;
|
|
146
|
+
`askHuman` from a plain object goes to the same queue. Without `gateFor`
|
|
147
|
+
nothing is checked and everything forwards. `policy.js` exports `MODES` and
|
|
148
|
+
`gateFor({ agent, mode, auditPath, humanChannel })`; the mode is the whole policy, so
|
|
149
|
+
`BAREGUARD_RWX_LETTERS` and `BAREGUARD_BUDGET_FILE` in the calling shell do not change it. bareguard writes its
|
|
150
|
+
decisions to `<runtime>/gate.jsonl`, the one audit file (see "The audit file"
|
|
151
|
+
below). `close()` waits up to 3 s for requests
|
|
152
|
+
still inside a `check()`.
|
|
153
|
+
|
|
154
|
+
`localLlm` (config key; `allowLocal` on `run()` and `createProxy()`) is an
|
|
155
|
+
array of `"host:port"` strings. Only those exact pairs pass the wall's
|
|
156
|
+
private/loopback check, never link-local (cloud metadata).
|
|
157
|
+
|
|
158
|
+
## Keys the agent never holds
|
|
159
|
+
|
|
160
|
+
The sandbox does not get your environment. The agent sees only barebox's own
|
|
161
|
+
variables (`HOME`, `PATH`, the proxy and CA variables, `NODE_USE_ENV_PROXY=1`), a short default list
|
|
162
|
+
(`TERM`, `COLORTERM`, `LANG`, `LANGUAGE`, `LC_*`, `TZ`, `USER`, `LOGNAME`,
|
|
163
|
+
`SHELL`, `EDITOR`, `PAGER`), the host variables you name in `env.pass`, the
|
|
164
|
+
values in `env.set`, and one placeholder per secret. Nothing else reaches it,
|
|
165
|
+
`/proc/1/environ` included.
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
"env": { "pass": ["MY_TOOL_HOME"], "set": { "FOO": "bar" } },
|
|
170
|
+
"secrets": {
|
|
171
|
+
"STRIPE_API_KEY": { "fromEnv": "REAL_STRIPE_KEY", "hosts": ["api.stripe.com"] },
|
|
172
|
+
"JIRA_TOKEN": { "value": "...", "hosts": ["acme.atlassian.net"] }
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
- `env.pass` refuses a name with `KEY`, `TOKEN`, `SECRET` or `PASSWORD` in it
|
|
178
|
+
(any case): `env.pass: "GITHUB_TOKEN" looks like a secret; use "secrets" for
|
|
179
|
+
it`. There is no override; `env.set` covers a harmless match.
|
|
180
|
+
- A secret has exactly one of `fromEnv` (a host variable; missing at startup
|
|
181
|
+
exits 2 naming the secret) or `value` (inline; the config file is hidden
|
|
182
|
+
inside the sandbox), and a non-empty `hosts` list of hostnames (no scheme,
|
|
183
|
+
no port).
|
|
184
|
+
- The agent sees a random placeholder, `sbx-ph-<16 hex>`, under the secret's
|
|
185
|
+
name, new on every run. It uses it as it would the key: `curl -H
|
|
186
|
+
"Authorization: Bearer $STRIPE_API_KEY"`, `-u "$STRIPE_API_KEY:"`, an
|
|
187
|
+
`x-api-key` header.
|
|
188
|
+
- The proxy looks for each placeholder in every request header value (as a
|
|
189
|
+
substring, also inside a decoded `Basic <base64>`). It swaps in the real
|
|
190
|
+
value only after the gate allowed the request (by mode or by your approval)
|
|
191
|
+
and only for a host the secret is bound to. A denied request never carries
|
|
192
|
+
it: it does not leave at all.
|
|
193
|
+
- A placeholder headed for a host its secret is not bound to is refused in
|
|
194
|
+
every mode: `403 denied: secret.host`. Nothing goes upstream.
|
|
195
|
+
- A real value is swapped only into a request that goes upstream over TLS. A
|
|
196
|
+
placeholder to a bound host over plain http is refused in every mode, before
|
|
197
|
+
the gate: `403 denied: secret.scheme`. Nothing goes upstream.
|
|
198
|
+
- Headers only. A key in a body, URL or query string is not swapped.
|
|
199
|
+
- Audit: one `annotate` line per hit, `verdict: "secret"`,
|
|
200
|
+
`meta: { agent, rid, name, host, swapped }`, joined to the gate line by
|
|
201
|
+
`rid`. The value is never written to the audit, an ask file or an error body.
|
|
202
|
+
- The same path covers plain requests, decrypted HTTPS (CONNECT) and the TCP
|
|
203
|
+
door.
|
|
204
|
+
|
|
205
|
+
Library callers pass the same shapes to `run()` (no `loadSecrets` call; `run()`
|
|
206
|
+
makes the placeholders once per run):
|
|
207
|
+
|
|
208
|
+
```js no-run
|
|
209
|
+
import { run } from "barebox";
|
|
210
|
+
await run({
|
|
211
|
+
proj: "/path/to/project",
|
|
212
|
+
command: ["bash", "-c", 'curl -H "Authorization: Bearer $STRIPE_API_KEY" https://api.stripe.com/v1/balance'],
|
|
213
|
+
secrets: { STRIPE_API_KEY: { fromEnv: "REAL_STRIPE_KEY", hosts: ["api.stripe.com"] } },
|
|
214
|
+
env: { pass: ["MY_TOOL_HOME"], set: { FOO: "bar" } },
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`createProxy({ secrets })` takes the loaded list (`loadSecrets` in
|
|
219
|
+
`src/secrets.js`, internal) and `launch({ env: { pass, set, placeholders } })`
|
|
220
|
+
takes the environment. Known gaps: the agent's own sign-in in `~/.claude`
|
|
221
|
+
stays readable; an upstream that echoes a request header back in its response
|
|
222
|
+
hands the real value to the agent.
|
|
223
|
+
|
|
224
|
+
## The audit file
|
|
225
|
+
|
|
226
|
+
`<runtime>/gate.jsonl` (`runtimePaths(runtime).audit`; `run()` returns it as
|
|
227
|
+
`audit`) is the only log, one JSON object per line, all in bareguard's shape.
|
|
228
|
+
- Decisions: bareguard's gate lines carry the action (`method`, `url`, `tool`,
|
|
229
|
+
`agent`, `rid`) and an `aid`.
|
|
230
|
+
- Response status: a `phase:"record"` line with the same `aid` and
|
|
231
|
+
`result.status`.
|
|
232
|
+
- barebox's own facts: `phase:"annotate"`, `surface:false`, keyed by `verdict`:
|
|
233
|
+
`deny`, `hold`, `decide`, `hold-abandoned`, `hold-queue-full`, `stale-answer`,
|
|
234
|
+
`malformed-answer`, `body`, `secret`, and `resp` (forward-all mode, no gate). A hold and
|
|
235
|
+
its outcome share `meta.id`; a request with a body gets one `body` line,
|
|
236
|
+
`meta: { agent, rid, bodyBytes, bodySha256 }`, joined to its gate line by
|
|
237
|
+
`action.rid`.
|
|
238
|
+
- Lines for an agent whose gate is not built, and every line when `gateFor` is
|
|
239
|
+
omitted, are written by a runtime-level `sbx` gate (`meta.agent` names the
|
|
240
|
+
agent).
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# every request with its response status, joined by aid
|
|
244
|
+
jq -s 'group_by(.aid)[] | select(.[0].aid) | {url: .[0].action.url, status: (map(.result.status) | map(select(.)) | first)}' <runtime>/gate.jsonl
|
|
245
|
+
# a request's body size and hash, joined by rid
|
|
246
|
+
jq -c 'select(.verdict=="body") | .meta' <runtime>/gate.jsonl
|
|
247
|
+
# one ask from hold to decision
|
|
248
|
+
jq -c 'select(.meta.id=="h1")' <runtime>/gate.jsonl
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Labels and model endpoints
|
|
252
|
+
|
|
253
|
+
Two config keys turn on rwxmap labels. `labels` is an array of folders the
|
|
254
|
+
rwxmap CLI wrote (`rwxmap <spec> -o <dir> --vendor <v>`); a leading `~/` means
|
|
255
|
+
`$HOME`. `tenants` is `{ "<vendor>": ["https://tenant.example.com"] }` (a
|
|
256
|
+
non-empty array of http(s) URLs per vendor); it replaces that vendor's server
|
|
257
|
+
URLs, so a placeholder host such as `your-domain.atlassian.net` matches your
|
|
258
|
+
tenant. A `tenants` vendor that no label folder defines is an error.
|
|
259
|
+
|
|
260
|
+
`loadLabels({ labels, tenants })` (`src/labels.js`) reads each
|
|
261
|
+
`<v>.rwxmap.review.json` for request keys, through `rwxmap/match`. The letters
|
|
262
|
+
come only from the sibling `<v>.rwxmap.json` file's `bareguard.tools`, the file
|
|
263
|
+
you review and can edit; rwxmap's own guessed letter is never used. A folder
|
|
264
|
+
with no review file, a review file without its gate file, or two vendors
|
|
265
|
+
defining the same key fails `sbx run` before any agent starts. A label file
|
|
266
|
+
written before rwxmap 0.8.0 fails with rwxmap's "regenerate it with rwxmap
|
|
267
|
+
0.8.0" message.
|
|
268
|
+
|
|
269
|
+
The tool for a request is chosen in this order: the label's key when a label
|
|
270
|
+
documents the request; else a model endpoint key when known; else
|
|
271
|
+
`http.<METHOD>`. A label key the gate file lacks (a row you deleted) reaches the
|
|
272
|
+
gate unlisted and is denied (`rwx.unlisted`), in every mode: it fails closed.
|
|
273
|
+
|
|
274
|
+
Model endpoints are `r` (free in every mode): `api.anthropic.com`
|
|
275
|
+
`POST /v1/messages` and `/v1/messages/count_tokens`; `api.openai.com`
|
|
276
|
+
`POST /v1/chat/completions`, `/v1/responses` and `/v1/embeddings`; and on each
|
|
277
|
+
`localLlm` host:port `POST /api/chat`, `/api/generate`, `/api/embed`,
|
|
278
|
+
`/v1/chat/completions` and `/v1/completions` (http only). Any other path on
|
|
279
|
+
those hosts is a normal `POST`.
|
|
280
|
+
|
|
281
|
+
Label folders are hidden inside the sandbox like the config file, so the agent
|
|
282
|
+
cannot rewrite a letter. `run()` and `createProxy()` take `labels:
|
|
283
|
+
{ matcher, tools }` (what `loadLabels` returns); omitted means no labels and
|
|
284
|
+
only the built-in model endpoints. `loadLabels` is exported from `barebox`:
|
|
285
|
+
`import { loadLabels } from 'barebox'`.
|
|
286
|
+
|
|
105
287
|
## Undo layer
|
|
106
288
|
|
|
107
289
|
`overlay: true` (`sbx run --overlay`) mounts a per-run upper over the
|
|
@@ -132,18 +314,19 @@ The overlay needs bubblewrap >= 0.11.0 for `--overlay` / `sbx diff|commit|rollba
|
|
|
132
314
|
`GIT_SSL_CAINFO`. Without it every HTTPS call from inside fails
|
|
133
315
|
verification. Only `ca.pem` enters the sandbox, never the key.
|
|
134
316
|
- 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`. Each minted certificate gets a random 128-bit serial (no shared `ca.srl`), and at most 4 mints run at once.
|
|
317
|
+
- Memory and limits: one proxy serves at most 40 agents, enforced. `addAgent` throws `createProxy: agent limit reached (40 agents per proxy); run another proxy for more`; the TCP door's `tcp` agent does not count, and `removeAgent` frees a place. For more than 40 agents run more proxies. Measured worst case (every agent with 1 parked + 16 waiting + a filled 64 KB body slot): proxy about 100 / 113-120 / 127-133 / 143-172 MB at 10 / 20 / 30 / 40 agents, quiet to busy machine (the budget at 40 agents is the range 145-175 MB; needs bareguard 0.30.0), plus about 8 MB per sandbox (limit 10). Normal use is about 85-120 MB. Audit file size does not move these numbers. barebox is for small teams: free, local and lightweight, built to assist and to connect to many tools, not to run swarms or thousands of agents.
|
|
135
318
|
- The TCP door is one agent: every connection through `createProxy`'s TCP `port` counts as the agent `tcp` and shares one hold line. Use `addAgent` sockets (`sbx run` does) for separate lines per agent. `removeAgent(name)` ends that agent's open connections; its held requests end as deny / client gone. `run()` calls it when the sandbox exits, so a request still held then ends as client gone, not `proxy closing`.
|
|
136
319
|
- 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. An IPv4 embedded in IPv6 is checked in every spelling: mapped, compat, uncompressed, NAT64 `64:ff9b::/96` (local-use `/48` denied outright) and 6to4 `2002::/16`; NAT64 and 6to4 of public sites stay reachable. 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.
|
|
137
|
-
- `createProxy` throws synchronously on an unopenable `logFile` (a directory, a missing parent, no permission) and releases the runtime. The runtime root, `asks/`, `answers/` and `socks/` are owner-only (`0700`) whatever the umask. An existing runtime dir you own is tightened to `0700`; one you don't own (such as `/tmp`) is refused with an error naming the dir and its owner and suggesting a subdir like `/tmp/sbx`. The audit
|
|
320
|
+
- `createProxy` throws synchronously on an unopenable `logFile` (a directory, a missing parent, no permission) and releases the runtime. The runtime root, `asks/`, `answers/`, `held/` and `socks/` are owner-only (`0700`) whatever the umask. An existing runtime dir you own is tightened to `0700`; one you don't own (such as `/tmp`) is refused with an error naming the dir and its owner and suggesting a subdir like `/tmp/sbx`. The audit file (`logFile`, `gate.jsonl`) is set to `0600` every time a proxy starts. No request header and no body content is written to it: a body is logged as its length and SHA-256 only. The ask payload's `bodyPreview` (the first 4 KB, card numbers masked except the last 4) lives in the ask file only; other secrets inside a body still show there until bareguard redaction lands. Your `redact` hook shapes the `meta` of barebox's own annotate lines.
|
|
138
321
|
- 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.
|
|
139
|
-
- `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
|
|
322
|
+
- `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 (a known gap: its sign-in tokens refresh themselves, so `secrets` does not cover them). The host environment does not reach the inside: callers that relied on an inherited variable list it in `env.pass` (or pass `launch({ env })` / `extraEnv`). `launch()` finds `bwrap` on your `PATH` but starts it with a fixed `PATH`.
|
|
140
323
|
- `sbx` exits 0 ok, 1 unknown id / refused / no live proxy / run failure, 2 usage; `sbx run` mirrors the agent's exit code.
|
|
141
324
|
- 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.
|
|
142
325
|
|
|
143
326
|
## What this package does not do
|
|
144
327
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
328
|
+
Per-API labels cover only the vendors whose rwxmap folders you list in
|
|
329
|
+
`labels`; every other request is `http.<METHOD>`. The card-in-body floor checks bodies of 64 KB or less;
|
|
330
|
+
larger bodies stream through unchecked for cards. The removed `hold.shouldHold`
|
|
331
|
+
and `hold.match` are gone: pass `gateFor` instead. No Docker, no MCP server, no macOS/Windows —
|
|
149
332
|
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.
|
|
3
|
+
"version": "0.6.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": {
|
|
@@ -30,12 +30,13 @@
|
|
|
30
30
|
],
|
|
31
31
|
"primitives": "./primitives.json",
|
|
32
32
|
"engines": {
|
|
33
|
-
"node": ">=22"
|
|
33
|
+
"node": ">=22.21"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"poc:m0": "bash poc/m0/run-m0.sh",
|
|
37
37
|
"redteam:m0": "bash poc/m0/redteam.sh",
|
|
38
38
|
"bench": "node scripts/bench.mjs",
|
|
39
|
+
"bench:agents": "node scripts/bench-agents.mjs",
|
|
39
40
|
"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
41
|
"typecheck": "tsc --noEmit && tsc -p tsconfig.scripts.json",
|
|
41
42
|
"build:types": "tsc",
|
|
@@ -47,5 +48,9 @@
|
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"@types/node": "22",
|
|
49
50
|
"typescript": "5"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"bareguard": "0.30.0",
|
|
54
|
+
"rwxmap": "0.8.0"
|
|
50
55
|
}
|
|
51
56
|
}
|
package/primitives.json
CHANGED
|
@@ -37,6 +37,15 @@
|
|
|
37
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.",
|
|
38
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
39
|
},
|
|
40
|
+
{
|
|
41
|
+
"name": "loadLabels",
|
|
42
|
+
"category": "labels",
|
|
43
|
+
"when": "Reach for this to build the `labels` value `run()` and `createProxy()` take: it reads rwxmap label folders once at startup and returns the request matcher, the tools table (letters from each gate file) and the absolute folders.",
|
|
44
|
+
"import": "import { loadLabels } from 'barebox'",
|
|
45
|
+
"signature": "loadLabels(cfg: object, env?: NodeJS.ProcessEnv) => { matcher: ReturnType<typeof matcherFrom>, tools: Record<string, any>, dirs: string[] }",
|
|
46
|
+
"fails": "Throws, naming the file or folder, on a folder with no review file, a review file without its gate file, a duplicate key across vendors, a tenants vendor no folder defines, an unreadable folder, or a label file written before rwxmap 0.8.0.",
|
|
47
|
+
"example": "import { loadLabels, run } from \"barebox\";\nconst labels = loadLabels({ labels: [\"/home/me/labels/jira\"], tenants: { jira: [\"https://acme.atlassian.net\"] } });\nawait run({ proj: \"/tmp/proj\", command: [\"bash\", \"-c\", \"true\"], labels });"
|
|
48
|
+
},
|
|
40
49
|
{
|
|
41
50
|
"name": "rollbackOverlay",
|
|
42
51
|
"category": "overlay",
|
|
@@ -52,7 +61,7 @@
|
|
|
52
61
|
"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
62
|
"import": "import { run } from 'barebox'",
|
|
54
63
|
"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.",
|
|
64
|
+
"fails": "Rejects on a missing/unreadable `proj`, an empty `command`, a bad `mode`, a misshapen `onAsk`, a `secrets` entry with no value (a `fromEnv` variable missing from this process's environment; the message names the secret, never a value), 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
65
|
"example": "import { run } from \"barebox\";\nconst { exit, asks, audit } = await run({ proj: \"/tmp/proj\", command: [\"bash\", \"-c\", \"echo hi\"] });"
|
|
57
66
|
}
|
|
58
67
|
]
|
package/src/cardscan.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// cardscan.js — card-number detection on a byte stream, pure (no I/O).
|
|
2
|
+
//
|
|
3
|
+
// A candidate is 13-19 digits, optionally grouped by single spaces or dashes
|
|
4
|
+
// between digits, touching no other digit, first digit 2-6 (card networks;
|
|
5
|
+
// this excludes millisecond timestamps, which start with 1), Luhn-valid.
|
|
6
|
+
// The scanner keeps a TAIL-byte tail between chunks so a number split across
|
|
7
|
+
// chunks is found; memory is constant whatever the body size. A candidate
|
|
8
|
+
// that ends exactly at the end of the data seen so far counts at once: the
|
|
9
|
+
// next chunk may continue the digit run, but an over-detect only asks more.
|
|
10
|
+
|
|
11
|
+
const TAIL = 40; // longest candidate: 19 digits + 18 separators = 37 bytes
|
|
12
|
+
const START = /(?<!\d)[2-6]/g; // a candidate starts on a digit 2-6 with no digit before it
|
|
13
|
+
|
|
14
|
+
/** @param {string} digits */
|
|
15
|
+
function luhn(digits) {
|
|
16
|
+
let sum = 0;
|
|
17
|
+
let dbl = false;
|
|
18
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
19
|
+
let n = digits.charCodeAt(i) - 48;
|
|
20
|
+
if (dbl) { n *= 2; if (n > 9) n -= 9; }
|
|
21
|
+
sum += n;
|
|
22
|
+
dbl = !dbl;
|
|
23
|
+
}
|
|
24
|
+
return sum % 10 === 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Every Luhn-valid candidate in `text`, as `{ index, text }`. At each start,
|
|
29
|
+
* the candidates are the 13-19 digit prefixes (single space/dash between
|
|
30
|
+
* digits allowed) whose next char is not a digit; the longest valid one wins.
|
|
31
|
+
*/
|
|
32
|
+
function candidates(text) {
|
|
33
|
+
const out = [];
|
|
34
|
+
START.lastIndex = 0;
|
|
35
|
+
for (let m; (m = START.exec(text));) {
|
|
36
|
+
let best = null;
|
|
37
|
+
let digits = '';
|
|
38
|
+
let i = m.index;
|
|
39
|
+
for (;;) {
|
|
40
|
+
digits += text[i++];
|
|
41
|
+
if (digits.length >= 13 && !/\d/.test(text[i] ?? '') && luhn(digits)) best = i;
|
|
42
|
+
if (digits.length === 19) break;
|
|
43
|
+
if (/\d/.test(text[i] ?? '')) continue;
|
|
44
|
+
if ((text[i] === ' ' || text[i] === '-') && /\d/.test(text[i + 1] ?? '')) i++;
|
|
45
|
+
else break;
|
|
46
|
+
}
|
|
47
|
+
if (best) {
|
|
48
|
+
out.push({ index: m.index, text: text.slice(m.index, best) });
|
|
49
|
+
START.lastIndex = best;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create a streaming card-number scanner.
|
|
57
|
+
* @returns {{ push(chunk: Buffer): boolean, readonly found: boolean, readonly tailLength: number }}
|
|
58
|
+
* `push` returns `found`; `tailLength` is the retained byte count (<= 40).
|
|
59
|
+
*/
|
|
60
|
+
export function createCardScanner() {
|
|
61
|
+
let found = false;
|
|
62
|
+
let tail = '';
|
|
63
|
+
let prevDigit = false; // was the byte just before `tail` a digit?
|
|
64
|
+
return {
|
|
65
|
+
push(chunk) {
|
|
66
|
+
if (found) return true;
|
|
67
|
+
const text = (prevDigit ? '0' : ' ') + tail + chunk.toString('latin1');
|
|
68
|
+
if (candidates(text).length) found = true;
|
|
69
|
+
const cut = Math.max(1, text.length - TAIL);
|
|
70
|
+
tail = text.slice(cut);
|
|
71
|
+
prevDigit = /\d/.test(text[cut - 1]);
|
|
72
|
+
return found;
|
|
73
|
+
},
|
|
74
|
+
get found() { return found; },
|
|
75
|
+
get tailLength() { return tail.length; },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Replace every card candidate's digits with `*` except the last 4,
|
|
81
|
+
* keeping the separators.
|
|
82
|
+
* @param {string} text
|
|
83
|
+
* @returns {string}
|
|
84
|
+
*/
|
|
85
|
+
export function maskCards(text) {
|
|
86
|
+
const found = candidates(text);
|
|
87
|
+
let out = '';
|
|
88
|
+
let at = 0;
|
|
89
|
+
for (const c of found) {
|
|
90
|
+
out += text.slice(at, c.index);
|
|
91
|
+
let left = c.text.replace(/[ -]/g, '').length - 4;
|
|
92
|
+
out += c.text.replace(/\d/g, (d) => (left-- > 0 ? '*' : d));
|
|
93
|
+
at = c.index + c.text.length;
|
|
94
|
+
}
|
|
95
|
+
return out + text.slice(at);
|
|
96
|
+
}
|