barebox 0.12.0 → 0.14.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 +32 -0
- package/README.md +69 -135
- package/barebox.context.md +24 -5
- package/package.json +2 -2
- package/src/cli.js +8 -9
- package/src/config.js +18 -2
- package/src/effect.js +139 -0
- package/src/holds.js +68 -20
- package/src/launcher.js +1 -1
- package/src/lists.js +78 -1
- package/src/policy.js +1 -1
- package/src/prompt.js +54 -2
- package/src/proxy.js +166 -21
- package/src/run.js +4 -2
- package/types/config.d.ts +10 -2
- package/types/effect.d.ts +31 -0
- package/types/holds.d.ts +37 -4
- package/types/lists.d.ts +20 -0
- package/types/prompt.d.ts +31 -1
- package/types/proxy.d.ts +8 -0
- package/types/run.d.ts +14 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,38 @@ 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.14.0] - 2026-11-30
|
|
8
|
+
|
|
9
|
+
### Security
|
|
10
|
+
|
|
11
|
+
- A call to a built-in model endpoint (Anthropic, OpenAI) is free only with this run's key: a key header holding a bound secret placeholder, or a key a human allowed in this run. Any other key, or none, is a plain `POST` that asks in `ask` and `auto` (the question shows only the key's last 4 characters), passes in `trust` and keeps the card floor. An allow is remembered by SHA-256 in the proxy's memory for this run only; a deny is not remembered, and parallel calls with one unknown key share one ask (at most 16 waiting per agent, then 429; only a person's answer or the hold timeout denies them, a client that goes lets the next one ask). The question says `no key` or `not this run's` when there is no last 4 to show. A floor question says when the body was read but no recipient, amount or currency field was recognised. `localLlm` endpoints stay free. Key bytes are never logged or written to the audit.
|
|
12
|
+
- A request with an `Upgrade` header (WebSocket, h2c) and a `CONNECT` inside a tunnel are refused at once with `403 denied: upgrade` / `403 denied: connect`, in every mode and for every host, and never resolved or dialed. Before, an upgrade was forwarded as a `GET` and an inner `CONNECT` closed the socket with no reason and no log line. WebSocket is not supported.
|
|
13
|
+
|
|
14
|
+
## [0.13.0] - 2026-11-30
|
|
15
|
+
|
|
16
|
+
### Docs
|
|
17
|
+
|
|
18
|
+
- README: the suite section is now a short map of the bare suite (Hands / Rails / Apps) plus what this pairs well with, linking the full list on github.com/hamr0.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
|
|
22
|
+
- `floor` config key (`floor.pay`, `floor.send`): your own payment and email or chat domains ask in every mode, `trust` included, for any write (a method other than GET or HEAD) to a listed host or `*.domain`, or to a listed `"METHOD host/path"` endpoint. The question shows every recipient, amount and currency field found in a JSON or form body, labelled by its path (shallowest first), or says why none was read (body over 64 KB, multipart, undecoded encoding, bad JSON). No built-in entries: only what you list. A host the floor cannot check is refused with 403. The audit records the floor kind and entry, never body values.
|
|
23
|
+
- New README demo GIF (`assets/demo.gif`): one unedited take of a scripted agent in a real `sbx run --mode auto --hold 8`, showing a free search, a payment allowed (real key swapped in only after the yes), an email allowed, a second payment denied, an unanswered upload denied after 8 s, and the end-of-run report. `examples/demo-gif/record.sh` records a take and fails unless the audit shows exactly those outcomes; `render.mjs` turns it into the GIF with ffmpeg (no new dependency).
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- bareguard pin 0.34.0 to 0.38.0 (the precompiled host-pattern matcher the floor uses).
|
|
28
|
+
|
|
29
|
+
### Security
|
|
30
|
+
|
|
31
|
+
- The floor's effect list cannot hide the real recipient: up to 5 recipient, amount or currency fields are all listed, and more than 5 lists none ("more than 5 fields") instead of a first few. Each list is capped while the body is read, and paths are cut at 200 characters, so a 64 KB body cannot make the question slow or large.
|
|
32
|
+
- A floor endpoint entry matches the path however it is spelled: case, `%XX` of unreserved characters and `;params` no longer slip past it (`/v1/%63harges`, `/V1/charges`, `/v1/charges;x=1`). The model-endpoint list stays exact.
|
|
33
|
+
- `sbx pending` and the non-terminal `ask` line name the floor entry (`floor=pay entry=...`), and `sbx pending` prints the recipient, amount and currency lines, so an approver in a second terminal sees what the same-terminal question shows.
|
|
34
|
+
|
|
35
|
+
### Removed
|
|
36
|
+
|
|
37
|
+
- `assets/demo-a.gif` (the Nov 3 live take stays as `assets/demo-a.webm`, linked from the README).
|
|
38
|
+
|
|
7
39
|
## [0.12.0] - 2026-11-12
|
|
8
40
|
|
|
9
41
|
### Changed
|
package/README.md
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
barebox
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
> A lightweight sandbox
|
|
12
|
-
>
|
|
11
|
+
> A safe, lightweight sandbox for agents that spawns in under a second. Reads pass, file writes can be undone, and anything that can't be undone (pay, send, publish, push) waits for your yes.
|
|
12
|
+
> For solo devs and small teams: up to 40 sandboxes share one proxy, one gate and one audit file.
|
|
13
13
|
|
|
14
14
|
<p align="center">
|
|
15
15
|
<img src="https://img.shields.io/github/package-json/v/hamr0/barebox?label=version&color=2a4f8c" alt="version (auto from package.json)">
|
|
@@ -17,149 +17,97 @@
|
|
|
17
17
|
<img src="https://img.shields.io/badge/platform-Linux-2a4f8c" alt="platform: Linux">
|
|
18
18
|
</p>
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
<img src="assets/demo.gif" width="800" alt="A scripted agent books a trip inside barebox: the search goes out free, a payment asks and gets the real key only after a yes, an email is allowed, a second payment is denied and never leaves, an unanswered upload is denied after 8 s, then the report of what barebox decided">
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
## What you get
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
- **Spawn in 0.7 s,** about 8 MB per sandbox. No root, no daemon, no image: the agent uses your installed tools.
|
|
25
|
+
- **Three modes, one flag:** `ask`, `auto` (default), `trust`.
|
|
26
|
+
- **Your payment and email domains ask in every mode,** `trust` included. List them once in the config file.
|
|
27
|
+
- **Keys the agent never holds:** it gets a placeholder, and the real key goes in only after the gate allows the request.
|
|
28
|
+
- **Up to 40 sandboxes share one proxy,** in about 95-245 MB for all of them.
|
|
29
|
+
- **One config file** (`~/.config/barebox/config.json`) and **one audit file** (`gate.jsonl`).
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
git clone https://github.com/hamr0/barebox && cd barebox && npm install
|
|
28
|
-
bash examples/demo-a/run.sh # Demo A scripted: book a trip, all three modes, every cell asserted
|
|
29
|
-
bash examples/demo-a/run.sh --driver muse --live --mode auto # the live run above; needs BASETEN_API_KEY, you answer the holds
|
|
30
|
-
bash examples/demo-b/run.sh # Demo B: a prompt-injected agent tries 3 exfiltrations in every mode
|
|
31
|
-
```
|
|
31
|
+
**[The guide](https://github.com/hamr0/barebox/blob/main/docs/wiki/guide.md)** covers every setting, what is and isn't blocked, how asks work, and all the numbers.
|
|
32
32
|
|
|
33
|
-
##
|
|
33
|
+
## Quick start
|
|
34
34
|
|
|
35
35
|
```
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
| locked: ~/.ssh, cloud creds, token files -> empty |
|
|
41
|
-
| network: none of its own; 127.0.0.1:3128 -> its unix socket |
|
|
42
|
-
+-----+-------------------------------------------------------------+
|
|
43
|
-
| one unix socket per agent (the socket is the identity, not a header)
|
|
44
|
-
v
|
|
45
|
-
ONE proxy, HTTP and HTTPS -> ONE gate (bareguard) -> world
|
|
46
|
-
| |
|
|
47
|
-
| '-> gate.jsonl, one audit line per decision
|
|
48
|
-
'-> held request: asks you in the terminal, forwards or 403
|
|
36
|
+
npm install -g barebox
|
|
37
|
+
sbx run -- claude # auto mode: reads and model calls pass, sends ask
|
|
38
|
+
sbx run --mode ask --overlay -- node agent.js
|
|
39
|
+
sbx diff && sbx commit # keep the file changes, or: sbx rollback
|
|
49
40
|
```
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
- **One proxy for all sandboxes**, plain HTTP and HTTPS. HTTPS is read through a local CA that exists only inside the sandbox, so the gate sees method, URL, headers and body.
|
|
53
|
-
- **One gate decides every request** by its letter and the mode (below). It is a simple policy for spawning sandboxed agents on the fly: one flag, no rule files.
|
|
54
|
-
- **One audit file**, `<runtime>/gate.jsonl`, one JSON line per decision in [bareguard](https://github.com/hamr0/bareguard)'s shape. It is append-only, so `tail -f` it, pipe it to `jq`, or ship it to your log stack.
|
|
55
|
-
|
|
56
|
-
## r, w, x and the three modes
|
|
57
|
-
|
|
58
|
-
Every request gets one letter:
|
|
59
|
-
|
|
60
|
-
| Letter | What | How barebox gets the letter |
|
|
61
|
-
|---|---|---|
|
|
62
|
-
| `r` | reads, changes nothing | `GET`, `HEAD`, and calls to model APIs (Anthropic, OpenAI, a `localLlm`) |
|
|
63
|
-
| `w` | a change that can be set back | only where an [rwxmap](https://github.com/hamr0/rwxmap) label for that API says so |
|
|
64
|
-
| `x` | can't be undone: send, pay, publish, push, delete | every other `POST`, `PUT`, `PATCH`, `DELETE`; any other method is denied |
|
|
65
|
-
|
|
66
|
-
File writes are a separate layer: with `--overlay` every change lands on an undo layer, and at the end you `sbx diff`, `sbx commit` or `sbx rollback`.
|
|
67
|
-
|
|
68
|
-
The mode (`sbx run --mode ...`) picks which letters pass without asking:
|
|
69
|
-
|
|
70
|
-
| Mode | Passes | Asks |
|
|
71
|
-
|---|---|---|
|
|
72
|
-
| `ask` | `r` | `w`, `x` |
|
|
73
|
-
| `auto` (default) | `r`, `w` | `x` |
|
|
74
|
-
| `trust` | `r`, `w`, `x` | nothing |
|
|
42
|
+
## Modes
|
|
75
43
|
|
|
76
|
-
|
|
44
|
+
| Mode | `r` read<br>GET, HEAD, model calls | `w` reversible<br>where an [rwxmap](https://github.com/hamr0/rwxmap) label says so | `x` can't be undone<br>every other POST, PUT, PATCH, DELETE |
|
|
45
|
+
|---|---|---|---|
|
|
46
|
+
| `ask` | free | asks | asks |
|
|
47
|
+
| `auto` (default) | free | free | asks |
|
|
48
|
+
| `trust` | free | free | free |
|
|
77
49
|
|
|
78
|
-
|
|
50
|
+
**Asks in every mode, `trust` included:** a card number in the body, a payment path (`/checkout`, `/payment`, `/orders`, `/purchase`), and any write to a domain you listed under `floor`:
|
|
79
51
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## What you see
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"floor": {
|
|
55
|
+
"pay": ["api.stripe.com", "*.paypal.com"],
|
|
56
|
+
"send": ["api.sendgrid.com", "POST slack.com/api/chat.postMessage"]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
90
60
|
|
|
91
|
-
|
|
61
|
+
Then a payment stops like this, with the recipient, amount and currency pulled from the body:
|
|
92
62
|
|
|
93
63
|
```
|
|
94
|
-
⏸
|
|
95
|
-
Why:
|
|
96
|
-
URL: POST https://
|
|
97
|
-
|
|
64
|
+
⏸ agent wants to SEND data to api.stripe.com
|
|
65
|
+
Why: a payment to a domain you listed (api.stripe.com)
|
|
66
|
+
URL: POST https://api.stripe.com/v1/payment_intents
|
|
67
|
+
To: customer.email=buyer@example.com
|
|
68
|
+
Amount: amount=35000
|
|
69
|
+
Currency: currency=usd
|
|
98
70
|
Allow? [y/N] (hold h1)
|
|
99
|
-
y
|
|
100
|
-
→ sent ✓ allowed
|
|
101
71
|
```
|
|
102
72
|
|
|
103
|
-
|
|
73
|
+
`y` allows it, anything else denies it (403, nothing leaves). An answer counts for that one request; nothing is saved. One held request per agent at a time; up to 16 more wait in line, plus up to 16 model calls waiting behind one new-key question; past either, `429`.
|
|
104
74
|
|
|
105
|
-
|
|
75
|
+
## Blocked by default
|
|
106
76
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
DELETE /anything/bookings/old-123 1 held: 0 allowed, 1 denied
|
|
114
|
-
model calls 18 free (labelled read-only)
|
|
115
|
-
key swaps 1 (the real test key went into the header only after your yes; the agent only ever had the placeholder)
|
|
116
|
-
```
|
|
77
|
+
- **Credential files** (`~/.ssh`, `~/.aws`, `~/.kube`, `~/.docker`, `~/.config/gh`, `~/.netrc`, `~/.npmrc`, keyrings, browser profiles, ...) read as empty.
|
|
78
|
+
- **Your environment** is cleared; only names you pass get in, and names like `*_TOKEN` and `*_KEY` are refused.
|
|
79
|
+
- **Any network but the proxy:** a direct IP, a raw socket or `--noproxy` fails. UDP is denied.
|
|
80
|
+
- **Private and local addresses,** checked after DNS on every resolved IP.
|
|
81
|
+
- **Real API keys,** swapped in only after a yes, only over HTTPS, only to the key's own hosts.
|
|
82
|
+
- **The agent answering its own asks,** and reading the config file.
|
|
117
83
|
|
|
118
|
-
|
|
84
|
+
## Not blocked yet
|
|
119
85
|
|
|
120
|
-
|
|
121
|
-
{"ts":"2026-11-03T21:41:04.869Z","seq":8,"aid":"1a541f36","phase":"gate","action":{"type":"net","tool":"http.POST","url":"https://httpbin.org/post","method":"POST","agent":"rdme","rid":"r2"},"decision":"deny","rule":"rwx.ask","reason":"hold timeout"}
|
|
122
|
-
```
|
|
86
|
+
barebox is a guardrail against mistakes and prompt-injected agents, not a VM. Known gaps (details in [the guide](https://github.com/hamr0/barebox/blob/main/docs/wiki/guide.md#what-it-does-not-block)):
|
|
123
87
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
"secrets": {
|
|
129
|
-
"STRIPE_API_KEY": { "fromEnv": "REAL_STRIPE_KEY", "hosts": ["api.stripe.com"] }
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
In `~/.config/barebox/config.json`. Inside, `$STRIPE_API_KEY` is a random placeholder, new each run, and the agent uses it like the key (`curl -H "Authorization: Bearer $STRIPE_API_KEY" ...`). The real value goes into the request header only after the gate allows it, only to `api.stripe.com`, only over HTTPS. Anywhere else the placeholder is refused (`403 denied: secret.host`, `secret.scheme`, `secret.url`).
|
|
88
|
+
- data in a `GET` URL, and data hidden in a hostname (DNS resolves before the gate);
|
|
89
|
+
- bodies over 64 KB are not scanned for card numbers;
|
|
90
|
+
- `~/.claude` stays readable.
|
|
135
91
|
|
|
136
92
|
## Numbers
|
|
137
93
|
|
|
138
|
-
Measured
|
|
139
|
-
|
|
140
|
-
| | barebox | [srt](https://github.com/anthropic-experimental/sandbox-runtime) 0.0.81 |
|
|
141
|
-
|---|---|---|
|
|
142
|
-
| Memory per sandbox | **7.8 MB** mean, 8.0 MB max | ~100 MB (a proxy per sandbox) |
|
|
143
|
-
| Shared proxy, normal use (HTTPS, 10-40 agents) | **95-160 MB** | one per sandbox |
|
|
144
|
-
| Shared proxy, worst case (HTTPS, every agent with a held request, a full line and a full body slot) | **117 / 133-151 / 177-207 / 207-241 MB** at 10 / 20 / 30 / 40 agents | |
|
|
145
|
-
| Total, worst case (proxy + walls) | ~195-200 MB at 10, ~295-310 MB at 20, ~525-560 MB at 40 agents | ~1 GB at 10, ~2 GB at 20 |
|
|
146
|
-
| Start to exit, `sbx run -- true` | **0.70 s** median (0.80 s with `--overlay`; bwrap alone 6 ms) | 1.87-2.05 s |
|
|
147
|
-
| One real agent (Claude Code) | 248 MB inside vs 249 MB bare; barebox adds ~91 MB for the first agent, ~11 MB per further one | not measured |
|
|
148
|
-
| Agents per proxy | **40 max**, enforced (the 41st is refused; run another proxy) | |
|
|
149
|
-
| Demo B, 3 exfiltration attempts | **3 of 3 blocked** in every mode | |
|
|
94
|
+
Measured on Fedora with Node 22 ([all numbers](https://github.com/hamr0/barebox/blob/main/docs/wiki/guide.md#numbers)):
|
|
150
95
|
|
|
151
|
-
|
|
96
|
+
- **0.70 s** start to exit, vs 1.87-2.05 s for [srt](https://github.com/anthropic-experimental/sandbox-runtime);
|
|
97
|
+
- **~8 MB** per sandbox, vs ~100 MB for srt (a proxy each);
|
|
98
|
+
- **95-160 MB** for the shared proxy in normal use at 10-40 agents, and at most 245 MB in the worst case;
|
|
99
|
+
- **40 agents** per proxy, enforced;
|
|
100
|
+
- **3 of 3** exfiltration attempts blocked in every mode (Demo B).
|
|
152
101
|
|
|
153
|
-
##
|
|
102
|
+
## Demos
|
|
154
103
|
|
|
155
|
-
|
|
104
|
+
```
|
|
105
|
+
git clone https://github.com/hamr0/barebox && cd barebox && npm install
|
|
106
|
+
bash examples/demo-a/run.sh # book a trip, all three modes, every cell asserted
|
|
107
|
+
bash examples/demo-b/run.sh # a prompt-injected agent tries 3 exfiltrations in every mode
|
|
108
|
+
```
|
|
156
109
|
|
|
157
|
-
|
|
158
|
-
- The proxy resolves DNS before the gate decides, so data hidden in a hostname can leak.
|
|
159
|
-
- Model API calls pass with any key, an attacker's included.
|
|
160
|
-
- Bodies over 64 KB are not scanned for card numbers. `gzip` and `deflate` bodies are decoded for the scan (up to 64 KB of output); `br`, `zstd` and bodies that fail to decode are scanned as sent, so a card inside their compressed bytes is not found.
|
|
161
|
-
- `~/.claude` stays readable: Claude Code's tokens refresh themselves.
|
|
162
|
-
- Writes over local sockets (a Postgres, a Docker daemon) are not on the undo layer.
|
|
110
|
+
The GIF above is a scripted agent in real barebox, one unedited take. In a live run with a real model (Meta's muse), 31 requests went out: 23 with no question, and 8 stopped for a person (3 allowed, 5 denied). The real payment key reached the server once, after a yes ([video](assets/demo-a.webm)).
|
|
163
111
|
|
|
164
112
|
## Install
|
|
165
113
|
|
|
@@ -169,27 +117,13 @@ npm install barebox
|
|
|
169
117
|
|
|
170
118
|
Linux. Node.js >= 22.21, `bwrap`, `socat`, `openssl`; bubblewrap >= 0.11.0 for `--overlay` (Ubuntu 24.04 ships 0.9.0). Two dependencies, [bareguard](https://npmjs.com/package/bareguard) and [rwxmap](https://npmjs.com/package/rwxmap), pinned exactly. The `sbx` CLI comes with it; the API is in [`barebox.context.md`](barebox.context.md).
|
|
171
119
|
|
|
172
|
-
##
|
|
173
|
-
|
|
174
|
-
Local-first, composable agent infrastructure. Same API patterns throughout —
|
|
175
|
-
mix and match, each module works standalone.
|
|
176
|
-
|
|
177
|
-
**Core** — the brain, the gate, the walls, the memory.
|
|
178
|
-
|
|
179
|
-
- **[bareagent](https://npmjs.com/package/bare-agent)** — the think→act→observe loop. *Goal in → coordinated actions out.* Replaces LangChain, CrewAI, AutoGen.
|
|
180
|
-
- **[bareguard](https://npmjs.com/package/bareguard)** — the single gate every action passes through. *Action in → allow / deny / ask-a-human out. Work in → green / red.* Replaces hand-rolled allowlists and scattered policy code.
|
|
181
|
-
- **[barebox](https://github.com/hamr0/barebox)** — the walls and the front door, this repo. *Agent in → contained run out: writes undoable, irreversible actions held for a human.* Replaces Docker/VM isolation and approve-everything prompts.
|
|
182
|
-
- **[litectx](https://npmjs.com/package/litectx)** — tree-sitter code + memory graph with activation decay, plus lightweight context engineering (write · select · compress · isolate). *Query in → ranked context out.*
|
|
183
|
-
|
|
184
|
-
**Add-on for bareguard** — labels API operations for the gate.
|
|
185
|
-
|
|
186
|
-
- **[rwxmap](https://github.com/hamr0/rwxmap)** [WIP] — labels every OpenAPI operation r/w/x as a starting point, marked for review. *API spec in → per-operation letter out.* barebox's doorman uses its labels for known APIs.
|
|
120
|
+
## bare suite
|
|
187
121
|
|
|
188
|
-
|
|
122
|
+
- **Hands** · [barebrowse](https://github.com/hamr0/barebrowse) · [baremobile](https://github.com/hamr0/baremobile) · [beeperbox](https://github.com/hamr0/beeperbox)
|
|
123
|
+
- **Rails** · [bareagent](https://github.com/hamr0/bareagent) · [bareguard](https://github.com/hamr0/bareguard) · **barebox** · [litectx](https://github.com/hamr0/litectx)
|
|
124
|
+
- **Apps** · [fwdloop](https://github.com/hamr0/fwdloop) · [bareloop](https://github.com/hamr0/bareloop)
|
|
189
125
|
|
|
190
|
-
|
|
191
|
-
- **[baremobile](https://npmjs.com/package/baremobile)** — Android + iOS device control. *Screen in → pruned snapshot out.* Replaces Appium, Espresso, XCUITest.
|
|
192
|
-
- **[beeperbox](https://github.com/hamr0/beeperbox)** — 50+ messaging networks via one MCP server (headless Beeper Desktop in Docker). *Chat in → unified message stream out.* Replaces Twilio, per-platform bot APIs.
|
|
126
|
+
Built on [bareguard](https://github.com/hamr0/bareguard) and [rwxmap](https://github.com/hamr0/rwxmap). → [The whole suite](https://github.com/hamr0)
|
|
193
127
|
|
|
194
128
|
## License
|
|
195
129
|
|
package/barebox.context.md
CHANGED
|
@@ -71,7 +71,11 @@ after the run), and every other command takes `--name docs-bot` instead of
|
|
|
71
71
|
|
|
72
72
|
A second terminal can answer at the same time through the file checkpoint
|
|
73
73
|
(`<runtime>/asks` + `<runtime>/answers`); the first answer wins and the
|
|
74
|
-
prompt prints `✓ answered elsewhere (allowed)` or
|
|
74
|
+
prompt prints `✓ answered elsewhere (allowed)` or
|
|
75
|
+
`✗ answered elsewhere (<reason>)` when the proxy decides. A write that fails
|
|
76
|
+
prints `✗ not sent (<code>), try again:` with the same question, and the next
|
|
77
|
+
line typed retries; the hold also stays open for another terminal or its
|
|
78
|
+
deadline:
|
|
75
79
|
|
|
76
80
|
```bash
|
|
77
81
|
npx sbx pending --name docs-bot
|
|
@@ -131,7 +135,7 @@ Its exit code mirrors the agent's.
|
|
|
131
135
|
(positive integer) and `localLlm` (array of `"host:port"`). A flag beats the file, the file beats the default; an
|
|
132
136
|
unknown key, bad value or bad JSON exits 2 naming the file and key. The file
|
|
133
137
|
is hidden inside the sandbox wherever it resolves. The library does not read it.
|
|
134
|
-
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".
|
|
138
|
+
Two more keys, `labels` and `tenants`, are described under "Labels and model endpoints". `floor` (`{ pay?: string[], send?: string[] }`) lists your own payment and send domains: an entry is a host, `*.domain` (subdomains only) or `"METHOD host/path"`; any write to a listed host, or the one listed endpoint, asks in every mode, `trust` included, and the question shows the recipient, amount and currency fields found in the body (labelled by path), or says why none was read. Each of the three lists in the effect holds at most 6 fields, and 6 means "more than 5": a list of more than 5 is shown as "more than 5 fields", none listed. Endpoint entries match the request path case-insensitively, with `%XX` of unreserved characters decoded and `;params` dropped; `sbx pending` shows the floor entry and the effect lines. There are no built-in entries; an absent `floor` lists nothing. Two more, `env` and `secrets`, are described under "Keys the agent never holds".
|
|
135
139
|
|
|
136
140
|
## Modes and the gate
|
|
137
141
|
|
|
@@ -149,10 +153,11 @@ table. The mode picks the agent's rwx letters:
|
|
|
149
153
|
is denied in every mode (`rwx.unlisted`). Without a label a request is the tool
|
|
150
154
|
`http.<METHOD>` (see "Labels and model endpoints"). The gate runs with empty
|
|
151
155
|
content patterns, so no word in a URL or method asks or denies on its own: the
|
|
152
|
-
mode letters, the labels and the floor decide. The floor is
|
|
156
|
+
mode letters, the labels and the floor decide. The floor is three bareguard flags,
|
|
153
157
|
`cardLike` (a body of 64 KB or less holding a card number: 13-19 digits,
|
|
154
158
|
optional single space or dash, first digit 2-6, Luhn-valid) and `paymentPath`
|
|
155
|
-
(`/checkout`, `/payment`, `/orders`, `/purchase`)
|
|
159
|
+
(`/checkout`, `/payment`, `/orders`, `/purchase`), and `floor` (`pay` or
|
|
160
|
+
`send`: the request hit a `floor` config entry); all three ask in every mode,
|
|
156
161
|
`trust` included. Nothing is denied because of a card. One exception: a call
|
|
157
162
|
to a model endpoint (see "Labels and model endpoints") is never card-scanned,
|
|
158
163
|
in any mode. `gzip` and `deflate` bodies are decoded for the scan and the ask preview (decoded output capped at 64 KB; the upstream still gets the original bytes); `br` and other encodings are scanned as sent. Bodies over 64 KB stream through unscanned. The body never enters the gate's action.
|
|
@@ -162,7 +167,10 @@ and `sbx approve|deny` work as above, and the ask carries the gate's `rule`
|
|
|
162
167
|
(`rwx.ask`, `flags.cardLike`, `flags.paymentPath`) and `letter`. A request
|
|
163
168
|
with a body of 64 KB or less is read in the agent's working slot before the
|
|
164
169
|
gate decides. Denials read `403 denied: <rule>[: reason]` (a human or timeout
|
|
165
|
-
denial reads `denied: <reason>`).
|
|
170
|
+
denial reads `denied: <reason>`). Two refusals never reach the gate, in every mode and for every host, model hosts
|
|
171
|
+
included: a request with an `Upgrade` header (WebSocket, h2c) is answered `403 denied: upgrade`, and a `CONNECT` inside
|
|
172
|
+
a tunnel `403 denied: connect`. Nothing is resolved, gated or dialed; each leaves one `deny` line in the proxy's own
|
|
173
|
+
log with the agent and target (no headers).
|
|
166
174
|
|
|
167
175
|
`createProxy` takes `gateFor(agent, { humanChannel, tools })`, called once per agent,
|
|
168
176
|
returning a bareguard `Gate` or any object with `async check(action)` that
|
|
@@ -178,6 +186,9 @@ still inside a `check()`.
|
|
|
178
186
|
`localLlm` (config key; `allowLocal` on `run()` and `createProxy()`) is an
|
|
179
187
|
array of `"host:port"` strings. Only those exact pairs pass the wall's
|
|
180
188
|
private/loopback check, never link-local (cloud metadata).
|
|
189
|
+
An entry names no scheme and drops a default port, so `localhost:80` also
|
|
190
|
+
matches an https server on `localhost` (port 443), and `127.0.0.1:443` over
|
|
191
|
+
plain http is not matched (it asks as a plain POST); use a non-default port.
|
|
181
192
|
|
|
182
193
|
## Keys the agent never holds
|
|
183
194
|
|
|
@@ -310,6 +321,14 @@ those hosts is a normal `POST`. A host written with a trailing dot
|
|
|
310
321
|
`paymentPath` mark still applies): a model call carries the whole conversation,
|
|
311
322
|
and a card number in it must not kill the agent.
|
|
312
323
|
|
|
324
|
+
A call to a built-in model endpoint (Anthropic, OpenAI) is a model call only with this run's key:
|
|
325
|
+
a key header (`x-api-key`, or `Authorization` without `Bearer `) that holds a bound secret placeholder, or a key
|
|
326
|
+
a human already allowed in this run. Any other key, or none, makes it a plain `http.POST` (`x`): it asks in `ask`
|
|
327
|
+
and `auto`, passes in `trust`, and the card floor applies. The ask shows only the key's last 4 characters; an allow
|
|
328
|
+
remembers the key's SHA-256 in the proxy's memory for this run (nothing is stored, a deny is not remembered, and
|
|
329
|
+
parallel calls with one unknown key share one ask: they wait behind it, at most 16 waiting per agent, past that 429 `hold queue full`; only a person's answer or the hold timeout denies them, a client that goes or a full hold line lets the next one ask). With no key the question says `a model call with no key`; with a key under 8 characters it shows no last 4. The audit action carries `modelKey: "other"`, never key bytes.
|
|
330
|
+
`localLlm` endpoints are always model calls, with no key check.
|
|
331
|
+
|
|
313
332
|
Label folders are hidden inside the sandbox like the config file, so the agent
|
|
314
333
|
cannot rewrite a letter. `run()` and `createProxy()` take `labels:
|
|
315
334
|
{ matcher, tools }` (what `loadLabels` returns); omitted means no labels and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "barebox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"typescript": "5"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"bareguard": "0.
|
|
53
|
+
"bareguard": "0.38.0",
|
|
54
54
|
"rwxmap": "0.11.1"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/cli.js
CHANGED
|
@@ -38,8 +38,8 @@ import { resolveConfig } from './config.js';
|
|
|
38
38
|
import { loadLabels } from './labels.js';
|
|
39
39
|
import { MODES } from './policy.js';
|
|
40
40
|
import { run as sandboxRun } from './run.js';
|
|
41
|
-
import { createTerminalPrompt, paint, ANSI } from './prompt.js';
|
|
42
|
-
import { DEFAULT_POLL_MS } from './holds.js';
|
|
41
|
+
import { createTerminalPrompt, paint, ANSI, effectLines, floorTail, keyTail } from './prompt.js';
|
|
42
|
+
import { DEFAULT_POLL_MS, writeTmpFile } from './holds.js';
|
|
43
43
|
import { diffOverlay, commitOverlay, rollbackOverlay } from './overlay.js';
|
|
44
44
|
import { assertAgentName, createRuntime, namedRuntime, hostNode, runtimePaths, runtimeLive, safe, shellQuote } from './runtime.js';
|
|
45
45
|
|
|
@@ -218,7 +218,7 @@ async function run(args) {
|
|
|
218
218
|
usage();
|
|
219
219
|
}
|
|
220
220
|
if (values.mode !== undefined && !MODES.includes(values.mode)) usage();
|
|
221
|
-
/** @type {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} */
|
|
221
|
+
/** @type {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, floor?: { pay?: string[], send?: string[] }, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} */
|
|
222
222
|
let cfg;
|
|
223
223
|
try {
|
|
224
224
|
cfg = resolveConfig({ mode: values.mode, hold: values.hold });
|
|
@@ -271,7 +271,7 @@ async function run(args) {
|
|
|
271
271
|
if (prompt?.ask(h)) { prompted.add(h.id); return; }
|
|
272
272
|
const c = clean(h, ['id', 'agent', 'method', 'url', 'rule', 'bodyPreview']);
|
|
273
273
|
if (json) out(JSON.stringify({ ev: 'ask', ...c }));
|
|
274
|
-
else out(`ask ${c.id} ${c.agent} ${c.method} ${c.url} rule=${c.rule}`);
|
|
274
|
+
else out(`ask ${c.id} ${c.agent} ${c.method} ${c.url} rule=${c.rule}${floorTail(h)}${keyTail(h)}`);
|
|
275
275
|
};
|
|
276
276
|
const emitDecided = (e) => {
|
|
277
277
|
if (!json && prompted.delete(e.id)) return;
|
|
@@ -295,7 +295,7 @@ async function run(args) {
|
|
|
295
295
|
result = await sandboxRun({
|
|
296
296
|
runtime, proj: process.cwd(), command, mode, timeoutMs,
|
|
297
297
|
...(name !== undefined ? { agent: name } : {}),
|
|
298
|
-
allowLocal: cfg.localLlm, labels, secrets: cfg.secrets, env: cfg.env,
|
|
298
|
+
allowLocal: cfg.localLlm, floor: cfg.floor, labels, secrets: cfg.secrets, env: cfg.env,
|
|
299
299
|
...(cfg.heldBodyMaxMB ? { heldBodyMaxBytes: cfg.heldBodyMaxMB * 1048576 } : {}),
|
|
300
300
|
unsafeTestOnly: { allowLoopback: process.env.SBX_UNSAFE_TEST_ALLOW_LOOPBACK === '1' },
|
|
301
301
|
overlay,
|
|
@@ -426,7 +426,8 @@ async function pending(rest) {
|
|
|
426
426
|
// Agent-controlled bytes (URL, rule, body preview): sanitized before
|
|
427
427
|
// they reach the approver's terminal (see `safe`).
|
|
428
428
|
const body = safe(h.bodyPreview).replace(/\s+/g, ' ').slice(0, 200);
|
|
429
|
-
out(`${safe(h.id)} ${safe(h.agent)} ${safe(h.method)} ${safe(h.url)} (${waiting}s) rule=${safe(h.rule)} body=${body}`);
|
|
429
|
+
out(`${safe(h.id)} ${safe(h.agent)} ${safe(h.method)} ${safe(h.url)} (${waiting}s) rule=${safe(h.rule)}${floorTail(h)}${keyTail(h)} body=${body}`);
|
|
430
|
+
for (const line of effectLines(h.effect, false)) out(line);
|
|
430
431
|
}
|
|
431
432
|
process.exit(0);
|
|
432
433
|
}
|
|
@@ -473,9 +474,7 @@ async function answerTarget(rest) {
|
|
|
473
474
|
*/
|
|
474
475
|
function writeAnswer(paths, id, decision, reason) {
|
|
475
476
|
const final = paths.answerFile(id);
|
|
476
|
-
|
|
477
|
-
const tmp = `${final}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;
|
|
478
|
-
fs.writeFileSync(tmp, JSON.stringify(decision === 'allow' ? { decision } : { decision, reason }), { mode: 0o600 });
|
|
477
|
+
const tmp = writeTmpFile(final, JSON.stringify(decision === 'allow' ? { decision } : { decision, reason }));
|
|
479
478
|
try {
|
|
480
479
|
fs.linkSync(tmp, final);
|
|
481
480
|
return true;
|
package/src/config.js
CHANGED
|
@@ -6,6 +6,7 @@ import fs from 'node:fs';
|
|
|
6
6
|
import os from 'node:os';
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { MODES } from './policy.js';
|
|
9
|
+
import { floorList } from './lists.js';
|
|
9
10
|
|
|
10
11
|
const DEFAULTS = { mode: 'auto', localLlm: [], labels: [], tenants: {} };
|
|
11
12
|
|
|
@@ -65,6 +66,20 @@ const checkSecrets = (v) => {
|
|
|
65
66
|
return null;
|
|
66
67
|
};
|
|
67
68
|
|
|
69
|
+
/** @param {unknown} v @returns {string|null} the error for a `floor` value, or null */
|
|
70
|
+
const checkFloor = (/** @type {any} */ v) => {
|
|
71
|
+
if (!isObj(v)) return 'must be an object of { pay?, send? }, each an array of hosts, "*.domain" or "METHOD host/path"';
|
|
72
|
+
for (const [k, list] of Object.entries(v)) {
|
|
73
|
+
if (k !== 'pay' && k !== 'send') return `has unknown field "${k}"`;
|
|
74
|
+
if (!Array.isArray(list)) return `floor.${k} must be an array`;
|
|
75
|
+
for (const [i, e] of list.entries()) {
|
|
76
|
+
if (typeof e !== 'string') return `floor.${k}[${i}] must be a string`;
|
|
77
|
+
try { floorList({ [k]: [e] }); } catch (err) { return `floor.${k}[${i}]: ${err instanceof Error ? err.message : String(err)}`; }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
|
|
68
83
|
/** Validators by key; each returns an error string or null. */
|
|
69
84
|
const KEYS = {
|
|
70
85
|
mode: (v) => (MODES.includes(v) ? null : `must be one of ${MODES.join(', ')}`),
|
|
@@ -78,6 +93,7 @@ const KEYS = {
|
|
|
78
93
|
tenants: (v) => (v !== null && typeof v === 'object' && !Array.isArray(v)
|
|
79
94
|
&& Object.values(v).every((a) => Array.isArray(a) && a.length > 0 && a.every(isHttpUrl))
|
|
80
95
|
? null : 'must be an object of vendor -> non-empty array of http(s) URLs'),
|
|
96
|
+
floor: checkFloor,
|
|
81
97
|
env: checkEnv,
|
|
82
98
|
secrets: checkSecrets,
|
|
83
99
|
};
|
|
@@ -97,7 +113,7 @@ export function configPath(env = process.env) {
|
|
|
97
113
|
* Read the config file over the defaults. No file means defaults.
|
|
98
114
|
*
|
|
99
115
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
100
|
-
* @returns {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
116
|
+
* @returns {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, floor?: { pay?: string[], send?: string[] }, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
101
117
|
* @throws {Error} naming the file (and the key) on invalid JSON, an unknown key or a bad value
|
|
102
118
|
*/
|
|
103
119
|
export function loadConfig(env = process.env) {
|
|
@@ -139,7 +155,7 @@ export function loadConfig(env = process.env) {
|
|
|
139
155
|
* @param {string} [flags.mode] `--mode`
|
|
140
156
|
* @param {string} [flags.hold] `--hold` (`"never"` or a positive integer of seconds, as typed)
|
|
141
157
|
* @param {NodeJS.ProcessEnv} [env] environment to read (default `process.env`)
|
|
142
|
-
* @returns {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
158
|
+
* @returns {{ mode: string, holdTimeoutSec?: number|string, localLlm: string[], labels: string[], tenants: Record<string, string[]>, heldBodyMaxMB?: number, floor?: { pay?: string[], send?: string[] }, env?: { pass?: string[], set?: Record<string, string> }, secrets?: Record<string, { fromEnv?: string, value?: string, hosts: string[] }> }} effective settings (`heldBodyMaxMB` absent means the library default)
|
|
143
159
|
* @throws {Error} as {@link loadConfig}
|
|
144
160
|
*/
|
|
145
161
|
export function resolveConfig(flags = {}, env = process.env) {
|