@b3os/cli 0.2.1 → 0.2.2

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.
Files changed (214) hide show
  1. package/README.md +87 -8
  2. package/assets/b3os-run.py +137 -0
  3. package/assets/skill/b3os/SKILL.md +111 -0
  4. package/dist/commands/_agents.d.ts +14 -0
  5. package/dist/commands/_agents.js +33 -0
  6. package/dist/commands/_agents.js.map +1 -0
  7. package/dist/commands/_common.js +6 -2
  8. package/dist/commands/_common.js.map +1 -1
  9. package/dist/commands/_context.d.ts +49 -0
  10. package/dist/commands/_context.js +260 -0
  11. package/dist/commands/_context.js.map +1 -0
  12. package/dist/commands/_next.d.ts +39 -0
  13. package/dist/commands/_next.js +77 -0
  14. package/dist/commands/_next.js.map +1 -0
  15. package/dist/commands/agent.d.ts +42 -0
  16. package/dist/commands/agent.js +218 -0
  17. package/dist/commands/agent.js.map +1 -0
  18. package/dist/commands/app.d.ts +2 -5
  19. package/dist/commands/app.js +229 -69
  20. package/dist/commands/app.js.map +1 -1
  21. package/dist/commands/auth.d.ts +70 -2
  22. package/dist/commands/auth.js +308 -33
  23. package/dist/commands/auth.js.map +1 -1
  24. package/dist/commands/docs.d.ts +54 -0
  25. package/dist/commands/docs.js +202 -0
  26. package/dist/commands/docs.js.map +1 -0
  27. package/dist/commands/doctor.d.ts +23 -0
  28. package/dist/commands/doctor.js +313 -0
  29. package/dist/commands/doctor.js.map +1 -0
  30. package/dist/commands/init.d.ts +38 -1
  31. package/dist/commands/init.js +259 -60
  32. package/dist/commands/init.js.map +1 -1
  33. package/dist/commands/listen.d.ts +30 -0
  34. package/dist/commands/listen.js +194 -0
  35. package/dist/commands/listen.js.map +1 -0
  36. package/dist/commands/manifest.d.ts +13 -1
  37. package/dist/commands/manifest.js +59 -7
  38. package/dist/commands/manifest.js.map +1 -1
  39. package/dist/commands/mcp.d.ts +25 -2
  40. package/dist/commands/mcp.js +120 -11
  41. package/dist/commands/mcp.js.map +1 -1
  42. package/dist/commands/sandbox.d.ts +35 -6
  43. package/dist/commands/sandbox.js +208 -9
  44. package/dist/commands/sandbox.js.map +1 -1
  45. package/dist/commands/setup.d.ts +39 -0
  46. package/dist/commands/setup.js +203 -0
  47. package/dist/commands/setup.js.map +1 -0
  48. package/dist/commands/tool.d.ts +109 -1
  49. package/dist/commands/tool.js +635 -47
  50. package/dist/commands/tool.js.map +1 -1
  51. package/dist/config.d.ts +30 -6
  52. package/dist/config.js +39 -8
  53. package/dist/config.js.map +1 -1
  54. package/dist/ctx.d.ts +5 -45
  55. package/dist/ctx.js +25 -160
  56. package/dist/ctx.js.map +1 -1
  57. package/dist/docs/index.json +1 -0
  58. package/dist/docs/pages/actions/call.md +300 -0
  59. package/dist/docs/pages/actions/catalog/airtable.md +737 -0
  60. package/dist/docs/pages/actions/catalog/arxiv.md +166 -0
  61. package/dist/docs/pages/actions/catalog/chainalysis-sanctions.md +125 -0
  62. package/dist/docs/pages/actions/catalog/coingecko.md +1558 -0
  63. package/dist/docs/pages/actions/catalog/deps-dev.md +465 -0
  64. package/dist/docs/pages/actions/catalog/dexscreener.md +568 -0
  65. package/dist/docs/pages/actions/catalog/discord.md +784 -0
  66. package/dist/docs/pages/actions/catalog/finnhub.md +776 -0
  67. package/dist/docs/pages/actions/catalog/frankfurter.md +438 -0
  68. package/dist/docs/pages/actions/catalog/github.md +1853 -0
  69. package/dist/docs/pages/actions/catalog/gmail.md +575 -0
  70. package/dist/docs/pages/actions/catalog/google-calendar.md +654 -0
  71. package/dist/docs/pages/actions/catalog/google-drive.md +502 -0
  72. package/dist/docs/pages/actions/catalog/google-sheets.md +700 -0
  73. package/dist/docs/pages/actions/catalog/hacker-news.md +542 -0
  74. package/dist/docs/pages/actions/catalog/http.md +824 -0
  75. package/dist/docs/pages/actions/catalog/hyperliquid.md +942 -0
  76. package/dist/docs/pages/actions/catalog/jira.md +920 -0
  77. package/dist/docs/pages/actions/catalog/kalshi.md +917 -0
  78. package/dist/docs/pages/actions/catalog/linear.md +1030 -0
  79. package/dist/docs/pages/actions/catalog/markets.md +21 -0
  80. package/dist/docs/pages/actions/catalog/morpho.md +247 -0
  81. package/dist/docs/pages/actions/catalog/notion.md +1077 -0
  82. package/dist/docs/pages/actions/catalog/nws.md +485 -0
  83. package/dist/docs/pages/actions/catalog/open-meteo.md +559 -0
  84. package/dist/docs/pages/actions/catalog/polymarket.md +1523 -0
  85. package/dist/docs/pages/actions/catalog/pushbullet.md +220 -0
  86. package/dist/docs/pages/actions/catalog/resend.md +307 -0
  87. package/dist/docs/pages/actions/catalog/s3.md +513 -0
  88. package/dist/docs/pages/actions/catalog/sec-edgar.md +487 -0
  89. package/dist/docs/pages/actions/catalog/slack.md +2629 -0
  90. package/dist/docs/pages/actions/catalog/stripe.md +1405 -0
  91. package/dist/docs/pages/actions/catalog/wikipedia.md +379 -0
  92. package/dist/docs/pages/actions/catalog.md +46 -0
  93. package/dist/docs/pages/actions/limits.md +50 -0
  94. package/dist/docs/pages/actions/model-tools.md +225 -0
  95. package/dist/docs/pages/actions/packs.md +148 -0
  96. package/dist/docs/pages/actions/settings.md +69 -0
  97. package/dist/docs/pages/actions/tools.md +244 -0
  98. package/dist/docs/pages/actions/triggers.md +149 -0
  99. package/dist/docs/pages/actions.md +88 -0
  100. package/dist/docs/pages/compat/anthropic.md +168 -0
  101. package/dist/docs/pages/compat/e2b.md +194 -0
  102. package/dist/docs/pages/compat/firecrawl.md +138 -0
  103. package/dist/docs/pages/compat/openai.md +168 -0
  104. package/dist/docs/pages/concepts/auth.md +151 -0
  105. package/dist/docs/pages/concepts/beta.md +55 -0
  106. package/dist/docs/pages/concepts/glossary.md +71 -0
  107. package/dist/docs/pages/concepts/ids.md +98 -0
  108. package/dist/docs/pages/concepts/jobs.md +229 -0
  109. package/dist/docs/pages/concepts/latency.md +138 -0
  110. package/dist/docs/pages/concepts/limits.md +191 -0
  111. package/dist/docs/pages/concepts/stack.md +59 -0
  112. package/dist/docs/pages/concepts/timing.md +86 -0
  113. package/dist/docs/pages/concepts/usage.md +110 -0
  114. package/dist/docs/pages/design/b3os-yaml.md +370 -0
  115. package/dist/docs/pages/design/deploy-from-github.md +122 -0
  116. package/dist/docs/pages/design/observability.md +134 -0
  117. package/dist/docs/pages/errors.md +1824 -0
  118. package/dist/docs/pages/infer/chat.md +570 -0
  119. package/dist/docs/pages/infer/limits.md +55 -0
  120. package/dist/docs/pages/infer/messages.md +185 -0
  121. package/dist/docs/pages/infer/responses.md +173 -0
  122. package/dist/docs/pages/infer/settings.md +154 -0
  123. package/dist/docs/pages/infer/speech.md +323 -0
  124. package/dist/docs/pages/infer.md +154 -0
  125. package/dist/docs/pages/introduction.md +162 -0
  126. package/dist/docs/pages/platform/addresses.md +174 -0
  127. package/dist/docs/pages/platform/call-log.md +99 -0
  128. package/dist/docs/pages/platform/custom-domains.md +104 -0
  129. package/dist/docs/pages/platform/keys.md +79 -0
  130. package/dist/docs/pages/platform/limits.md +57 -0
  131. package/dist/docs/pages/platform/members.md +101 -0
  132. package/dist/docs/pages/platform/requests.md +116 -0
  133. package/dist/docs/pages/platform/settings.md +129 -0
  134. package/dist/docs/pages/platform/webhooks.md +68 -0
  135. package/dist/docs/pages/platform.md +67 -0
  136. package/dist/docs/pages/quickstart/mcp.md +94 -0
  137. package/dist/docs/pages/quickstart/sandbox-agent.md +205 -0
  138. package/dist/docs/pages/quickstart/scrape.md +134 -0
  139. package/dist/docs/pages/quickstart.md +45 -0
  140. package/dist/docs/pages/render/inspections.md +162 -0
  141. package/dist/docs/pages/render/limits.md +72 -0
  142. package/dist/docs/pages/render/screenshots.md +179 -0
  143. package/dist/docs/pages/render/settings.md +431 -0
  144. package/dist/docs/pages/render/styles.md +342 -0
  145. package/dist/docs/pages/render/videos.md +272 -0
  146. package/dist/docs/pages/render.md +118 -0
  147. package/dist/docs/pages/routines/callables.md +174 -0
  148. package/dist/docs/pages/routines/definitions.md +361 -0
  149. package/dist/docs/pages/routines/limits.md +117 -0
  150. package/dist/docs/pages/routines/runs.md +328 -0
  151. package/dist/docs/pages/routines/settings.md +104 -0
  152. package/dist/docs/pages/routines/triggers.md +339 -0
  153. package/dist/docs/pages/routines.md +216 -0
  154. package/dist/docs/pages/sandboxes/agents.md +217 -0
  155. package/dist/docs/pages/sandboxes/commands.md +272 -0
  156. package/dist/docs/pages/sandboxes/images.md +166 -0
  157. package/dist/docs/pages/sandboxes/limits.md +143 -0
  158. package/dist/docs/pages/sandboxes/ports.md +260 -0
  159. package/dist/docs/pages/sandboxes/settings.md +358 -0
  160. package/dist/docs/pages/sandboxes/snapshots.md +423 -0
  161. package/dist/docs/pages/sandboxes/swarms.md +146 -0
  162. package/dist/docs/pages/sandboxes/volumes.md +131 -0
  163. package/dist/docs/pages/sandboxes.md +231 -0
  164. package/dist/docs/pages/sdks/cli.md +121 -0
  165. package/dist/docs/pages/sdks/mcp.md +169 -0
  166. package/dist/docs/pages/sdks/python.md +146 -0
  167. package/dist/docs/pages/sdks/typescript.md +202 -0
  168. package/dist/docs/pages/sdks.md +282 -0
  169. package/dist/docs/pages/settings.md +33 -0
  170. package/dist/docs/pages/vault/limits.md +46 -0
  171. package/dist/docs/pages/vault.md +133 -0
  172. package/dist/docs/pages/vision/agent-browser.md +115 -0
  173. package/dist/docs/pages/vision/crawl.md +333 -0
  174. package/dist/docs/pages/vision/extract.md +152 -0
  175. package/dist/docs/pages/vision/fetcher.md +15 -0
  176. package/dist/docs/pages/vision/limits.md +79 -0
  177. package/dist/docs/pages/vision/profiles.md +111 -0
  178. package/dist/docs/pages/vision/proxy.md +131 -0
  179. package/dist/docs/pages/vision/scrape.md +356 -0
  180. package/dist/docs/pages/vision/sessions.md +311 -0
  181. package/dist/docs/pages/vision/settings.md +656 -0
  182. package/dist/docs/pages/vision.md +175 -0
  183. package/dist/errors.d.ts +129 -0
  184. package/dist/errors.js +326 -0
  185. package/dist/errors.js.map +1 -0
  186. package/dist/main.d.ts +1 -1
  187. package/dist/main.js +26 -13
  188. package/dist/main.js.map +1 -1
  189. package/dist/manifest/domains.d.ts +50 -0
  190. package/dist/manifest/domains.js +159 -0
  191. package/dist/manifest/domains.js.map +1 -0
  192. package/dist/manifest/link.d.ts +20 -0
  193. package/dist/manifest/link.js +24 -0
  194. package/dist/manifest/link.js.map +1 -0
  195. package/dist/manifest/record.d.ts +1 -1
  196. package/dist/tool/archive.d.ts +33 -0
  197. package/dist/tool/archive.js +174 -0
  198. package/dist/tool/archive.js.map +1 -0
  199. package/dist/tool/calls.d.ts +46 -0
  200. package/dist/tool/calls.js +274 -0
  201. package/dist/tool/calls.js.map +1 -0
  202. package/dist/tool/checks.d.ts +21 -0
  203. package/dist/tool/checks.js +145 -0
  204. package/dist/tool/checks.js.map +1 -0
  205. package/dist/tool/elf.d.ts +19 -0
  206. package/dist/tool/elf.js +107 -0
  207. package/dist/tool/elf.js.map +1 -0
  208. package/dist/tool/predict.d.ts +8 -0
  209. package/dist/tool/predict.js +38 -0
  210. package/dist/tool/predict.js.map +1 -0
  211. package/dist/tool/ustar.d.ts +5 -0
  212. package/dist/tool/ustar.js +220 -0
  213. package/dist/tool/ustar.js.map +1 -0
  214. package/package.json +6 -5
@@ -0,0 +1,217 @@
1
+ # Agents in sandboxes
2
+
3
+ > Run an agent inside a sandbox with a scoped grant to B3OS, call the model and tools without a key, inject vault credentials and start nested sandboxes safely.
4
+
5
+ Source: https://docs.beta.b3os.org/sandboxes/agents.md
6
+
7
+ Code inside a sandbox can call B3OS at `http://127.0.0.1:7700` (`B3OS_API_URL`). The call travels over vsock to the B3OS daemon on the same machine, with no network in between. It needs no key: the node knows which sandbox is calling and runs the call as that sandbox's own principal.
8
+
9
+ ## Grant access
10
+
11
+ A sandbox has no B3OS access until you grant it in `api` when you create it:
12
+
13
+ **curl**
14
+
15
+ ```bash
16
+ curl -s https://beta-api.b3os.org/v1/sandboxes \
17
+ -H "Authorization: Bearer $B3OS_API_KEY" \
18
+ -H "Content-Type: application/json" \
19
+ -d '{"template": "agent",
20
+ "api": {"scopes": ["infer:read", "infer:run", "vision:run", "actions:run", "vault:run"],
21
+ "spend_cap_usd": 5,
22
+ "connections": ["conn_01m5t6cbgdjs1ketgcqwa2sne8"]}}'
23
+ ```
24
+ **TypeScript**
25
+
26
+ ```ts
27
+ const sandbox = await b3os.sandboxes.createSandbox({
28
+ template: "agent",
29
+ api: {
30
+ scopes: ["infer:read", "infer:run", "vision:run", "actions:run", "vault:run"],
31
+ spend_cap_usd: 5,
32
+ connections: ["conn_01m5t6cbgdjs1ketgcqwa2sne8"],
33
+ },
34
+ });
35
+ ```
36
+ **Python**
37
+
38
+ ```python
39
+ sandbox = b3os.sandboxes.create_sandbox({
40
+ "template": "agent",
41
+ "api": {
42
+ "scopes": ["infer:read", "infer:run", "vision:run", "actions:run", "vault:run"],
43
+ "spend_cap_usd": 5,
44
+ "connections": ["conn_01m5t6cbgdjs1ketgcqwa2sne8"],
45
+ },
46
+ })
47
+ ```
48
+ **MCP**
49
+
50
+ ```text
51
+ Start an agent sandbox whose code may call the model and scrape pages, and no other B3OS product.
52
+ ```
53
+
54
+ On the remote MCP server, `sandbox_create` takes the same body as the API, `api` included, so the agent can ask for this grant; it can never exceed the key's own scopes. The local server's `sandbox_create` takes only the template, size, timeout and environment, so a sandbox it creates cannot call B3OS. From a terminal: `b3os sandbox create --template agent --api-scope infer:read,infer:run,vision:run`.
55
+
56
+ | Field | Rule |
57
+ |---|---|
58
+ | `scopes` | A subset of your key's scopes. `*` and `<product>:*` expand to the scopes you hold, except `sandboxes:write`, the `vault:*` scopes and the `platform:*` scopes, which a grant gets only when it names them exactly. |
59
+ | `spend_cap_usd` | Stops the sandbox's own metered API calls at this spend, so `0` refuses all of them. `null` (the default) means your key's cap applies. A cap above your key's is refused. |
60
+ | `connections` | Up to 16 vault connections the sandbox's action calls may use. |
61
+ | `actions` | `{"allow": [...]}`: only these pack actions, at these versions (`io.b3os/wikipedia/*@1.0.1`, up to 16). The sandbox then gets `B3OS_MCP_URL`, an MCP server of exactly those packs' tools ([Your model's tools](https://docs.beta.b3os.org/actions/model-tools)). Without it, your key's rule, which is none. |
62
+
63
+ Asking for more than you hold fails with [`forbidden`](https://docs.beta.b3os.org/errors#forbidden), reason `scope_escalation`. The grant ends when the sandbox stops.
64
+
65
+ ## Call B3OS from inside
66
+
67
+ The B3OS SDK and CLI read `B3OS_API_URL` and use it without a key. Compatible clients only need the base URL; pass any placeholder as the key:
68
+
69
+ | Client | Base URL inside a sandbox |
70
+ |---|---|
71
+ | B3OS SDK, CLI | Automatic |
72
+ | OpenAI SDK | `http://127.0.0.1:7700/v1/infer` |
73
+ | Firecrawl SDK | `http://127.0.0.1:7700/compat/firecrawl` |
74
+ | Plain HTTP | `http://127.0.0.1:7700/v1/...` |
75
+
76
+ ```python
77
+ import os
78
+ from openai import OpenAI
79
+
80
+ client = OpenAI(base_url=os.environ["B3OS_API_URL"] + "/v1/infer", api_key="unused")
81
+ ```
82
+
83
+ The [sandbox agent quickstart](https://docs.beta.b3os.org/quickstart/sandbox-agent) runs a complete tool-calling loop this way.
84
+
85
+ Recorded from production: a sandbox created with egress `deny` and the grant `{"scopes": ["infer:read"], "spend_cap_usd": 0}` runs Python that reads the model list at `B3OS_API_URL` with no key, then tries `https://example.com`, which egress `deny` blocks.
86
+
87
+ **Response 200**
88
+
89
+ ```json
90
+ {
91
+ "duration_ms": 86.297,
92
+ "exit_code": 0,
93
+ "object": "exec_result",
94
+ "signal": null,
95
+ "stderr": "",
96
+ "stderr_truncated": false,
97
+ "stdout": "B3OS API, no key: ['b3os/qwen3.5-9b', 'b3os/default', 'kokoro-82m']\ninternet: blocked\n",
98
+ "stdout_truncated": false,
99
+ "timed_out": false,
100
+ "timing": {
101
+ "dispatch_ms": 0.5,
102
+ "run_ms": 86.297,
103
+ "spawn_ms": 4.198,
104
+ "total_ms": 91.074
105
+ }
106
+ }
107
+ ```
108
+
109
+ **Request**
110
+
111
+ ```bash
112
+ curl -s -X POST 'https://beta-api.b3os.org/v1/sandboxes/sbx_01m6q3naczn9f2nk8d66cbr2tb/exec' \
113
+ -H "Authorization: Bearer $B3OS_API_KEY" \
114
+ -H 'content-type: application/json' \
115
+ -d '{"cmd":["python3","-c","import json, os, urllib.request\napi = os.environ['\''B3OS_API_URL'\'']\nmodels = json.load(urllib.request.urlopen(api + '\''/v1/infer/models'\'', timeout=10))\nprint('\''B3OS API, no key:'\'', [m['\''id'\''] for m in models['\''data'\'']])\ntry:\n urllib.request.urlopen('\''https://example.com'\'', timeout=5)\n print('\''internet: reached'\'')\nexcept Exception:\n print('\''internet: blocked'\'')\n"]}'
116
+ ```
117
+
118
+ **Server-Timing**
119
+
120
+ ```http
121
+ server-timing: edge_auth;dur=0.000, edge_upstream;dur=104.000, dispatch;dur=0.500, spawn;dur=4.198, run;dur=86.297, total;dur=91.130
122
+ x-request-id: req_01m6q3nb536w2vjs2je6sx06nj
123
+ ```
124
+
125
+ <sub>Captured 2026-11-06 from commit `92bb000d` on the host the node runs on, one call, label `live-recorded` (recorded from production). Case `sandboxes/api-from-inside`.</sub>
126
+
127
+ Account operations (keys, usage, limits, organizations, projects and the pack registry) are not served on the node. From inside a sandbox they answer [`421 edge_only`](https://docs.beta.b3os.org/errors#edge_only); call `https://beta-api.b3os.org` with a key for those.
128
+
129
+ ## Give the sandbox a credential
130
+
131
+ Three ways, from safest to least safe:
132
+
133
+ 1. **Let the egress proxy inject it.** Grant `vault:run` and the connection in `api.connections`, then call a marketplace action. The proxy adds the credential to requests for the hosts the connection is bound to; the sandbox never sees it.
134
+ 2. **Put a connection's secret in an environment variable.** `secrets` takes a vault connection reference. The API never returns the value and B3OS never logs it, but it is an ordinary environment variable inside the VM: any code running in the sandbox can read it, and send it anywhere the sandbox's egress allows.
135
+
136
+ ```json
137
+ { "template": "base", "secrets": { "DATABASE_URL": { "connection": "conn_01m5t6cbgdjs1ketgcqwa2sne8" } } }
138
+ ```
139
+
140
+ `field` picks which secret field to use; it defaults to the one the connection's type injects (`api_key`, `token` or `access_token`), and `basic` connections need `username` or `password`.
141
+
142
+ Because the value leaves the vault, this takes the scope `vault:connections:reveal` as well as `vault:run`. No default key, `*` or `vault:*` holds it: create a key that names it (owners and admins can). Without it the create answers [`403 forbidden`](https://docs.beta.b3os.org/errors#forbidden) with `required_scope: vault:connections:reveal`. Each reference writes a `connection.revealed` event to the vault's audit log, naming the key, the connection, the sandbox and the variable, never the value.
143
+
144
+ A connection bound to `hosts`, which every pack connection is (a GitHub token, a CoinGecko key), is refused here with [`422 connection_host_bound`](https://docs.beta.b3os.org/errors#connection_host_bound): B3OS only ever adds it at the egress proxy, for those hosts. Use it the first way, or store a separate connection without `hosts` for a value the code must read, such as a database password.
145
+ 3. **Pass a literal value** in `secrets`, such as `{"NPM_TOKEN": "..."}`. The VM can read it the same way, and it also passes through your request.
146
+
147
+ Prefer the first: a credential that never enters the sandbox cannot leak from it. Adding credentials at the egress proxy for a sandbox's own HTTP requests, so `secrets` values never enter the VM either, is planned.
148
+
149
+ ## Sandboxes that create sandboxes
150
+
151
+ Code in a sandbox can create sandboxes only if its grant names `sandboxes:write` exactly, and never one its project owns (`"owner": "project"` from inside a sandbox is refused with [`forbidden`](https://docs.beta.b3os.org/errors#forbidden), reason `sandbox`). Every sandbox records the sandbox that created it (`parent`). One that a project's service started, directly or not, also names that service (`root`) and ends when it ends, whatever its own timeout. The child's grant must be a subset of the parent sandbox's, and a child's `spend_cap_usd` above the parent's grant cap is refused, so caps never grow down a chain. A child's `egress` defaults to the parent's own policy; one that reaches further is refused with [`forbidden`](https://docs.beta.b3os.org/errors#forbidden), reason `egress_escalation`, and so is a public port unless the parent's egress is `public`. Restoring a snapshot and forking are bound the same way.
152
+
153
+ Code in a sandbox can also send things into another sandbox of the project (commands, `run_code`, files, the process list, signals, logs, terminals, readiness probes it sets, and port previews), but only into a sandbox within its reach:
154
+
155
+ - its egress is within the calling sandbox's own. A sandbox with a public port, or with a preview URL that may still serve, counts as `public`, since the internet reaches those ports whatever its egress. Otherwise the call is refused with reason `egress_escalation`.
156
+ - its `api` grant holds no scope and no connection the caller's lacks. Otherwise the reason is `scope_escalation`.
157
+
158
+ Reach is checked when a call starts. When a change takes the other sandbox out of reach (its egress is widened, a preview URL is minted for it, the calling sandbox's egress is narrowed, or it stops), what is still open into it is cut: a running command is killed, a terminal closes with code 1008, log streams and file reads end with an error, and a preview request is dropped. What the caller already left there stays: background processes keep running and written files remain. Getting, listing, pausing, resuming, snapshotting or deleting another sandbox, and narrowing its egress, are not bound this way. Other products reach the network on their own terms, so give a sandbox whose egress is `deny` no `vision`, `actions` or `infer` scopes either.
159
+
160
+ ## Limit where it can reach
161
+
162
+ `egress` controls outbound traffic: `public` (the default) allows any public address, `allowlist` allows only the hosts in `allow` (exact names or `*.` wildcards, each with an optional port such as `db.example.com:5432`; an entry without a port opens only ports 80 and 443), and `deny` blocks everything. Private networks, loopback, the node's own addresses and cloud metadata are always refused. The policy covers traffic bound for the internet; calls to `http://127.0.0.1:7700` go to B3OS itself, under the grant.
163
+
164
+ ## Run code from a pull request
165
+
166
+ Code from a pull request you did not write can read every environment variable and file in the sandbox, so keep the repository credential out of both, and close the network before that code runs:
167
+
168
+ 1. **Clone with the credential in one command's `env` only.** Git reads `GIT_CONFIG_COUNT`, `GIT_CONFIG_KEY_<n>` and `GIT_CONFIG_VALUE_<n>` as configuration for that process. Unlike `git -c`, the value is not in the command line, and nothing is written to `.git/config`. Do not put the token in the sandbox's `secrets`, which every later process can read.
169
+
170
+ ```bash
171
+ curl -s -X POST "https://beta-api.b3os.org/v1/sandboxes/$SBX/exec" \
172
+ -H "Authorization: Bearer $B3OS_API_KEY" -H "Content-Type: application/json" \
173
+ -d '{"cmd": "git clone -q --depth 1 https://github.com/OWNER/REPO /workspace/repo",
174
+ "env": {"GIT_CONFIG_COUNT": "1",
175
+ "GIT_CONFIG_KEY_0": "http.https://github.com/.extraHeader",
176
+ "GIT_CONFIG_VALUE_0": "Authorization: Bearer '"$GITHUB_TOKEN"'"}}'
177
+ ```
178
+
179
+ 2. **Narrow egress before the repository's code runs** (install scripts and tests included). Allow only the package registry the install needs; GitHub is then refused, so a stolen value has nowhere to go from this sandbox:
180
+
181
+ ```bash
182
+ curl -s -X POST "https://beta-api.b3os.org/v1/sandboxes/$SBX/egress" \
183
+ -H "Authorization: Bearer $B3OS_API_KEY" -H "Content-Type: application/json" \
184
+ -d '{"mode": "allowlist", "allow": ["registry.npmjs.org"]}'
185
+ ```
186
+
187
+ Narrowing also closes the sandbox's open connections that the new policy does not allow.
188
+
189
+ 3. **Install and run the tests.** Turn off an agent harness's repository hooks and project MCP files when it reads an untrusted pull request, since those run code from the repository too.
190
+
191
+ 4. **Start later runs warm from a snapshot taken before any pull-request code ran.** A sandbox created from a snapshot gets the snapshot's files and its running processes back. If the pull request's code ran before the snapshot, whatever it left behind runs again in every sandbox made from it: a background process can read the environment of your next `git fetch`, and a hook or a setting it wrote into `.git` runs inside that fetch or the checkout after it. So take the warm snapshot after the clone and a dependency install of a commit you trust (your default branch, with egress narrowed as in step 2), and never send the credential to a sandbox created from a snapshot taken after untrusted code ran. For each pull request: create from the trusted snapshot, fetch the pull request's head with the credential in that command's `env`, narrow egress, then install and test as in step 3.
192
+
193
+ What this does not close: the token stays valid until it expires or you revoke it, and whatever the clone wrote stays in the VM, so delete the sandbox when the run ends and use a token scoped to the one repository with read access only.
194
+
195
+ The checks `bench/sandboxes/scripts/repo-start.mjs` made on production on 2026-11-01, with a random header value in place of a token on a public repository. Express 4.21.1 plays the trusted commit the snapshot is taken from, and 4.21.2 the pull request that each warm run fetches:
196
+
197
+ ```text
198
+ ok clone 4.21.1 with the header in that exec's env only
199
+ ok the clone's git config has no extraHeader
200
+ ok the header value is in no file and not in the next exec's env
201
+ ok egress narrowed to registry.npmjs.org before repo code runs
202
+ ok api.github.com is refused after narrowing
203
+ ok npm install from the allowlisted registry
204
+ ok the first test file passes
205
+ ok snapshot of the prepared repo
206
+ ok warm runs that fetched 4.21.2 and passed
207
+ ```
208
+
209
+ ## See what it did
210
+
211
+ Every call a sandbox makes is in the request log with `connection: sandbox` and its `sandbox_id`:
212
+
213
+ ```bash
214
+ curl -s "https://beta-api.b3os.org/v1/requests?sandbox_id=$SBX" -H "Authorization: Bearer $B3OS_API_KEY"
215
+ ```
216
+
217
+ Usage from those calls is recorded with the sandbox's ID and billed to the key that created it.
@@ -0,0 +1,272 @@
1
+ # Commands, code and files
2
+
3
+ > Run commands in a sandbox buffered, streamed or in the background, run code in a Jupyter kernel, move files in and out, and open a terminal.
4
+
5
+ Source: https://docs.beta.b3os.org/sandboxes/commands.md
6
+
7
+ All of these need `sandboxes:run` and a running sandbox. Set `SBX` to your sandbox's ID in the examples. A call to a paused or stopped sandbox answers `409` [`sandbox_not_running`](https://docs.beta.b3os.org/errors#sandbox_not_running); when the agent inside the microVM does not answer, a call fails with `502` [`guest_unreachable`](https://docs.beta.b3os.org/errors#guest_unreachable).
8
+
9
+ ## Run a command
10
+
11
+ `POST /v1/sandboxes/{sandbox_id}/exec` runs a command and, by default, waits for it to exit:
12
+
13
+ **curl**
14
+
15
+ ```bash
16
+ curl -s "https://beta-api.b3os.org/v1/sandboxes/$SBX/exec" \
17
+ -H "Authorization: Bearer $B3OS_API_KEY" \
18
+ -H "Content-Type: application/json" \
19
+ -d '{"cmd": "python3 -c \"print(2 + 2)\""}'
20
+ ```
21
+ **TypeScript**
22
+
23
+ ```ts
24
+ import { B3OS } from "@b3os/sdk";
25
+
26
+ const b3os = new B3OS();
27
+ const sbx = process.env.SBX!; // a sandbox ID, sbx_...
28
+ const result = await b3os.sandboxes.exec(sbx, { cmd: 'python3 -c "print(2 + 2)"' });
29
+ console.log(result.exit_code, result.stdout);
30
+ ```
31
+ **Python**
32
+
33
+ ```python
34
+ import os
35
+ from b3os import B3OS
36
+
37
+ b3os = B3OS()
38
+ sbx = os.environ["SBX"] # a sandbox ID, sbx_...
39
+ result = b3os.sandboxes.exec(sbx, {"cmd": 'python3 -c "print(2 + 2)"'})
40
+ if result["object"] == "exec_result": # with "background": True you get the process instead
41
+ print(result["exit_code"], result["stdout"])
42
+ ```
43
+ **MCP**
44
+
45
+ ```text
46
+ In my sandbox, run the test suite with `npm test` in /workspace/app and tell me what failed.
47
+ ```
48
+
49
+ The agent calls `sandbox_exec` with `sandbox_id`, `cmd` and `cwd`, and reads `exit_code`, `stdout` and `stderr`.
50
+
51
+ The command above, recorded from production:
52
+
53
+ **Response 200**
54
+
55
+ ```json
56
+ {
57
+ "duration_ms": 27.445,
58
+ "exit_code": 0,
59
+ "object": "exec_result",
60
+ "signal": null,
61
+ "stderr": "",
62
+ "stderr_truncated": false,
63
+ "stdout": "4\n",
64
+ "stdout_truncated": false,
65
+ "timed_out": false,
66
+ "timing": {
67
+ "dispatch_ms": 0.511,
68
+ "run_ms": 27.445,
69
+ "spawn_ms": 1.562,
70
+ "total_ms": 29.6
71
+ }
72
+ }
73
+ ```
74
+
75
+ **Request**
76
+
77
+ ```bash
78
+ curl -s -X POST 'https://beta-api.b3os.org/v1/sandboxes/sbx_01m6q3naemvk1zxgst0992ejrr/exec' \
79
+ -H "Authorization: Bearer $B3OS_API_KEY" \
80
+ -H 'content-type: application/json' \
81
+ -d '{"cmd":"python3 -c \"print(2 + 2)\""}'
82
+ ```
83
+
84
+ **Server-Timing**
85
+
86
+ ```http
87
+ server-timing: edge_auth;dur=0.000, edge_upstream;dur=40.000, dispatch;dur=0.511, spawn;dur=1.562, run;dur=27.445, total;dur=29.667
88
+ x-request-id: req_01m6q3nb8x0sm4402fxxsp5gr5
89
+ ```
90
+
91
+ <sub>Captured 2026-11-06 from commit `92bb000d` on the host the node runs on, one call, label `live-recorded` (recorded from production). Case `sandboxes/exec`.</sub>
92
+
93
+ The answer is an `exec_result` object: `exit_code` (`null` when a signal ended the command), `signal` (such as `KILL`, else `null`), `timed_out`, `stdout` and `stderr` as strings, `stdout_truncated` and `stderr_truncated`, and `duration_ms`, the time the command ran. For the command above, `stdout` is `"4\n"` and `exit_code` is `0`.
94
+
95
+ `cmd` as a string runs through `/bin/sh -c`; as an array (`["node", "--version"]`) it runs directly. Other fields: `cwd` (default `/workspace`), `env`, `stdin` (written to the command, then closed), `user` (`user` or `root`) and `timeout_ms`. A buffered call waits at most 60 seconds and returns up to 1 MiB of each stream; `stdout_truncated` says when output was dropped. A command killed at its timeout returns `timed_out: true` and the signal, `KILL`.
96
+
97
+ The same command from the dashboard's playground. The answer and timing replay a production call made Nov 6 from the host the node runs on.
98
+
99
+ [Open the video](https://beta.b3os.org/gallery/docs-site/demo-exec/81ae622cb15b2442.mp4) · [Transcript (WebVTT)](https://beta.b3os.org/gallery/docs-site/demo-exec/0f782b8a2541463c.vtt)
100
+
101
+ <details>
102
+ <summary>Transcript</summary>
103
+
104
+ `0:00` Pick a running sandbox and type a command.
105
+
106
+ `0:04` Run it. The output and exit code come back.
107
+
108
+ `0:07` The waterfall splits the time between the edge and the sandbox.
109
+
110
+ </details>
111
+
112
+ <sub>Captured 2026-11-15 from commit `2aac696d` on a GitHub Actions runner (colo MSP), one call, label `mock` (the dashboard in mock mode). Case `docs-site/demo-exec`.</sub>
113
+
114
+ ### Stream the output
115
+
116
+ Add `?stream=true` (or send `Accept: text/event-stream`) to get output while the command runs, as `exec.stdout` and `exec.stderr` events, then `exec.exit` with the exit code. A streamed command may run up to an hour. Output is UTF-8; bytes that are not valid UTF-8 arrive as U+FFFD. A snapshot or fork of the sandbox resets open streams, so a client that needs every byte should run long commands in the background and read their logs.
117
+
118
+ ```bash
119
+ curl -N -s "https://beta-api.b3os.org/v1/sandboxes/$SBX/exec?stream=true" \
120
+ -H "Authorization: Bearer $B3OS_API_KEY" \
121
+ -H "Content-Type: application/json" \
122
+ -d '{"cmd": "for i in 1 2 3; do echo $i; sleep 1; done", "timeout_ms": 60000}'
123
+ ```
124
+
125
+ ### Run in the background
126
+
127
+ `background: true` returns at once with the process, for servers and long jobs. A background command runs until it exits or the sandbox stops; give it a `timeout_ms` (up to an hour) to have it killed sooner:
128
+
129
+ ```bash
130
+ curl -s "https://beta-api.b3os.org/v1/sandboxes/$SBX/exec" \
131
+ -H "Authorization: Bearer $B3OS_API_KEY" \
132
+ -H "Content-Type: application/json" \
133
+ -d '{"cmd": "npm run dev", "cwd": "/workspace/app", "background": true}'
134
+ # {"object": "process", "pid": 812, "cmd": "npm run dev", "status": "running", ...}
135
+ ```
136
+
137
+ - `GET /v1/sandboxes/{sandbox_id}/processes` lists background processes, running or exited.
138
+ - `GET /v1/sandboxes/{sandbox_id}/logs` streams their output as `log.stdout` and `log.stderr` events, then `process.exited`. It starts with up to 1 MiB of buffered output per process; filter with `pid`, and pass `follow=false` to stop after the buffered output.
139
+
140
+ This sends `TERM` (or `KILL`, `INT`, `HUP`) to the process and its process group:
141
+
142
+ ```http
143
+ POST /v1/sandboxes/{sandbox_id}/processes/{pid}/kill
144
+ ```
145
+
146
+ ### Restart a server when it exits
147
+
148
+ Add `restart` to a background command and the node starts it again, in the same sandbox, when it exits: `on-failure` after a non-zero exit code or a signal, `always` after any exit. The first restart is at once; more in a row wait 1, 2, 4, 8, 16, 32 and then 60 seconds, and a run of 60 seconds starts the count over. Before a restart the node kills what is left of the command's process group, so a child that still holds the port does not block it. It does so only for an exit it saw within 60 seconds of last seeing the process alive, while the pid is still that process's; after a restart of the node itself it leaves the group alone.
149
+
150
+ ```bash
151
+ curl -s -X POST "$B3OS_BASE_URL/v1/sandboxes/sbx_01example/exec" \
152
+ -H "Authorization: Bearer $B3OS_API_KEY" -H 'content-type: application/json' \
153
+ -d '{"cmd": ["python3", "-m", "http.server", "8000"], "background": true, "restart": "on-failure"}'
154
+ ```
155
+
156
+ - The sandbox's `supervised` list shows each supervised process: its current `pid`, `state` (`running`, `starting` until the sandbox's readiness probe passes again, `backoff`, `crash_loop`, `exited`, `stopped`), `restarts` and `last_exit`. The process list marks the current one `supervised: true`, with `restart_of` naming the process it replaced.
157
+ - Five exits within 5 minutes read `crash_loop`. The node goes on starting it, at most a minute apart, until a run lasts 60 seconds, so a server that waits on a database comes back by itself when the database does.
158
+ - A signal sent from inside the sandbox (`kill -9`, `pkill`) counts as an exit and is restarted. `POST …/processes/{pid}/kill` stops it for good: the node ends the supervision before it sends the signal. Add `"restart": true` to the kill to have the process started again instead. A process still running 10 seconds after that signal ignored it: the request lapses, and its next exit counts as a crash. Send `KILL` to restart one that ignores `TERM`.
159
+ - `restart` needs `background: true` and takes no `stdin`; a sandbox supervises at most 8 processes. The command, its `cwd`, `env` and `user` are kept with the sandbox on the node's disk for its restarts, so pass secrets with the create's `secrets`, not on the command line.
160
+ - A fork, or a sandbox restored from a snapshot, supervises nothing: the processes it took over run on unsupervised.
161
+
162
+ ### Retry a command without running it twice
163
+
164
+ Send an `Idempotency-Key` with a command, and a command runs at most once per key. A retry with the same key and body within 24 hours gets the first answer again, with `Idempotent-Replayed: true`; a retry while it still runs gets `409` [`idempotency_request_in_progress`](https://docs.beta.b3os.org/errors#idempotency_request_in_progress). If the connection drops before a buffered or background command answers, the command still runs to its end and its answer is kept, so a retry with the key gets it. The general rules are in [Retry writes safely](https://docs.beta.b3os.org/concepts/jobs#retry-writes-safely).
165
+
166
+ - Once a command was handed to the sandbox, its key is kept even when no answer is stored. When the node cannot tell whether the command ran (`502` [`guest_unreachable`](https://docs.beta.b3os.org/errors#guest_unreachable) after the hand-off, whose detail says the command may have run), or the answer was a stream, a retry gets `409` [`idempotency_outcome_unknown`](https://docs.beta.b3os.org/errors#idempotency_outcome_unknown) and the command does not run again. Check what it did, then use a new key to run it again.
167
+ - A keyed buffered answer is kept in the node's memory for replay, so its output is cut to fit the store (256 KiB of JSON), the longer stream first, with `stdout_truncated` or `stderr_truncated` set. Have the command write a large output to a file and read the file.
168
+ - Command output is never written to the node's disk. The node keeps only a record that the command ran, how it ended and how many bytes it wrote (for a background command, its process ID), so after a node restart a retry gets `409` [`idempotency_response_evicted`](https://docs.beta.b3os.org/errors#idempotency_response_evicted), which says that, instead of the output, and the command does not run again.
169
+
170
+ The SDKs send a key with a command only when you pass one (`idempotencyKey` in TypeScript, `idempotency_key` in Python), and the MCP server sends none. Neither sends a command again on its own after an answer that does not show it was refused before it ran: a `5xx` from the node, a proxy's error page, a timeout or a dropped connection ends the call with an error that says the command may have run. That includes `503` [`node_unavailable`](https://docs.beta.b3os.org/errors#node_unavailable), which the API also sends when the node went away while it held your request. The SDKs do retry a refusal such as `429` [`rate_limited`](https://docs.beta.b3os.org/errors#rate_limited), and `409` `idempotency_request_in_progress` for your key, after which they return the recorded answer. To get the answer after a dropped connection, call again with the same key.
171
+
172
+ ## Run code in a kernel
173
+
174
+ Sandboxes from the `code-interpreter` template have a Jupyter kernel. `POST /v1/sandboxes/{sandbox_id}/run_code` runs code in it and returns rich results; state persists between calls, like cells in a notebook:
175
+
176
+ ```bash
177
+ curl -s "https://beta-api.b3os.org/v1/sandboxes/$SBX/run_code" \
178
+ -H "Authorization: Bearer $B3OS_API_KEY" \
179
+ -H "Content-Type: application/json" \
180
+ -d '{"code": "import math\nmath.sqrt(2)\n"}'
181
+ ```
182
+
183
+ Recorded from production, in a new `code-interpreter` sandbox:
184
+
185
+ **Response 200**
186
+
187
+ ```json
188
+ {
189
+ "duration_ms": 13.604,
190
+ "error": null,
191
+ "execution_count": 3,
192
+ "language": "python",
193
+ "object": "run_code_result",
194
+ "results": [
195
+ {
196
+ "data": "1.4142135623730951",
197
+ "is_main_result": true,
198
+ "mime_type": "text/plain"
199
+ }
200
+ ],
201
+ "stderr": "",
202
+ "stdout": "",
203
+ "timing": {
204
+ "kernel_ms": 13.604,
205
+ "total_ms": 37.524
206
+ }
207
+ }
208
+ ```
209
+
210
+ **Request**
211
+
212
+ ```bash
213
+ curl -s -X POST 'https://beta-api.b3os.org/v1/sandboxes/sbx_01m6q3na9a1t9wjyx2w62stqce/run_code' \
214
+ -H "Authorization: Bearer $B3OS_API_KEY" \
215
+ -H 'content-type: application/json' \
216
+ -d '{"code":"import math\nmath.sqrt(2)\n"}'
217
+ ```
218
+
219
+ **Server-Timing**
220
+
221
+ ```http
222
+ server-timing: edge_auth;dur=0.000, edge_upstream;dur=49.000, kernel;dur=13.604, total;dur=37.574
223
+ x-request-id: req_01m6q3nbqyjh1bwf4yzt8a0vgg
224
+ ```
225
+
226
+ <sub>Captured 2026-11-06 from commit `92bb000d` on the host the node runs on, one call, label `live-recorded` (recorded from production). Case `sandboxes/run-code`.</sub>
227
+
228
+ `language` is `python` (the default) or `javascript`. Results carry their MIME type, so plots come back as images and data frames as HTML. A cell that raises returns the exception in `error`. Other templates answer [`kernel_unavailable`](https://docs.beta.b3os.org/errors#kernel_unavailable).
229
+
230
+ ## Files
231
+
232
+ | Call | Does |
233
+ |---|---|
234
+ | `GET /v1/sandboxes/{sandbox_id}/files?path=/workspace/main.py` | Returns the file's bytes |
235
+ | `GET /v1/sandboxes/{sandbox_id}/files?path=/workspace&list=1` | Lists a directory as JSON: name, path, type, size, mode, modified time |
236
+ | `PUT /v1/sandboxes/{sandbox_id}/files?path=/workspace/main.py` | Writes the request body to the path, replacing any file; `mkdir=1` creates parent directories, `mode` sets a new file's permissions |
237
+ | `GET /v1/sandboxes/{sandbox_id}/files/stat?path=/workspace/data` | Returns one entry without reading it; a symlink is reported as a symlink, with its `target` |
238
+ | `DELETE /v1/sandboxes/{sandbox_id}/files?path=/workspace/build` | Deletes a file, a symlink (never its target) or an empty directory; `recursive=1` deletes a directory and everything in it. A directory with files and no `recursive=1` is `409` [`directory_not_empty`](https://docs.beta.b3os.org/errors#directory_not_empty) |
239
+ | `POST /v1/sandboxes/{sandbox_id}/files/move` with `{"from": "/workspace/out.tmp", "to": "/workspace/out.csv"}` | Moves or renames. An existing `to` is `409` [`file_exists`](https://docs.beta.b3os.org/errors#file_exists) unless you pass `"overwrite": true` |
240
+ | `POST /v1/sandboxes/{sandbox_id}/files/mkdir` with `{"path": "/workspace/data/raw"}` | Creates the directory and missing parents, like `mkdir -p`: `201` when it made it, `200` when it was there |
241
+
242
+ ```bash
243
+ curl -s -X PUT "https://beta-api.b3os.org/v1/sandboxes/$SBX/files?path=/workspace/data/input.csv&mkdir=1" \
244
+ -H "Authorization: Bearer $B3OS_API_KEY" \
245
+ -H "Content-Type: application/octet-stream" \
246
+ --data-binary @input.csv
247
+ ```
248
+
249
+ Paths are absolute. A transfer carries at most 64 MiB; for larger files, fetch them from inside the sandbox. Delete and move refuse `/` and paths that end in `.` or `..`, as `rm` does. A move between filesystems inside the sandbox (from `/tmp` to `/workspace`) copies a regular file and removes the source; move a directory across them with `mv` through `exec`. The Sandbox handle in the SDKs has the same calls as `sbx.files.stat`, `delete`, `move` and `mkdir`.
250
+
251
+ Stat, delete, move and mkdir need the agent inside the sandbox to know them. A sandbox whose template image was built before they existed answers `409` [`guest_outdated`](https://docs.beta.b3os.org/errors#guest_outdated); run `stat`, `rm`, `mv` or `mkdir -p` with `exec` there.
252
+
253
+ ## Open a terminal
254
+
255
+ `GET /v1/sandboxes/{sandbox_id}/pty` upgrades to a WebSocket attached to a new pseudo-terminal running the login shell, or `cmd`. Binary frames carry terminal bytes both ways. Text frames carry JSON control messages: send `{"type": "resize", "cols": 120, "rows": 40}`; the server sends `{"type": "exit", "code": 0}` before it closes. Pass `cols`, `rows`, `cmd` and `cwd` as query parameters.
256
+
257
+ From a browser, get a [stream ticket](https://docs.beta.b3os.org/concepts/auth#stream-tickets) with `POST /v1/sandboxes/{sandbox_id}/ticket` and open the socket within 30 seconds:
258
+
259
+ ```js
260
+ const { ticket } = await (await fetch(`/api/my-backend/ticket?sandbox=${sandboxId}`)).json();
261
+ const socket = new WebSocket(
262
+ `wss://beta-api.b3os.org/v1/sandboxes/${sandboxId}/pty?cols=120&rows=40`,
263
+ ["b3os.v1", `b3os.ticket.${ticket}`],
264
+ );
265
+ socket.binaryType = "arraybuffer";
266
+ ```
267
+
268
+ Mint the ticket on your server with your key, never in the browser. The CLI opens the same terminal with `b3os sandbox shell`.
269
+
270
+ ### Keep a terminal across reloads
271
+
272
+ Add `session=new` and the terminal can outlive its socket. The server's first frame is `{"type": "session", "id": "pts_...", "resumed": false}`; keep the `id`. If the socket closes while the shell runs (a page reload, a dropped network), the shell keeps running for a few minutes and the end of its output is kept. Open the socket again with `session=<id>` and the first frame says `"resumed": true`, then a binary frame replays the kept output and the terminal takes the new `cols` and `rows`. An expired or unknown id opens a new terminal with a new id. Send `{"type": "end"}` to hang a kept terminal up at once. The dashboard's shells work this way.