@b3os/cli 0.2.0 → 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.
- package/README.md +87 -7
- package/assets/b3os-run.py +137 -0
- package/assets/skill/b3os/SKILL.md +111 -0
- package/dist/commands/_agents.d.ts +14 -0
- package/dist/commands/_agents.js +33 -0
- package/dist/commands/_agents.js.map +1 -0
- package/dist/commands/_common.js +6 -2
- package/dist/commands/_common.js.map +1 -1
- package/dist/commands/_context.d.ts +49 -0
- package/dist/commands/_context.js +260 -0
- package/dist/commands/_context.js.map +1 -0
- package/dist/commands/_next.d.ts +39 -0
- package/dist/commands/_next.js +77 -0
- package/dist/commands/_next.js.map +1 -0
- package/dist/commands/agent.d.ts +42 -0
- package/dist/commands/agent.js +218 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/app.d.ts +2 -0
- package/dist/commands/app.js +559 -54
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/auth.d.ts +88 -2
- package/dist/commands/auth.js +354 -44
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/docs.d.ts +54 -0
- package/dist/commands/docs.js +202 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/commands/doctor.d.ts +23 -0
- package/dist/commands/doctor.js +313 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/init.d.ts +38 -1
- package/dist/commands/init.js +259 -60
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/listen.d.ts +30 -0
- package/dist/commands/listen.js +194 -0
- package/dist/commands/listen.js.map +1 -0
- package/dist/commands/manifest.d.ts +13 -1
- package/dist/commands/manifest.js +81 -18
- package/dist/commands/manifest.js.map +1 -1
- package/dist/commands/mcp.d.ts +25 -2
- package/dist/commands/mcp.js +120 -11
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/sandbox.d.ts +35 -6
- package/dist/commands/sandbox.js +208 -9
- package/dist/commands/sandbox.js.map +1 -1
- package/dist/commands/setup.d.ts +39 -0
- package/dist/commands/setup.js +203 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/tool.d.ts +154 -0
- package/dist/commands/tool.js +785 -0
- package/dist/commands/tool.js.map +1 -0
- package/dist/config.d.ts +30 -6
- package/dist/config.js +39 -8
- package/dist/config.js.map +1 -1
- package/dist/ctx.d.ts +5 -45
- package/dist/ctx.js +25 -160
- package/dist/ctx.js.map +1 -1
- package/dist/docs/index.json +1 -0
- package/dist/docs/pages/actions/call.md +300 -0
- package/dist/docs/pages/actions/catalog/airtable.md +737 -0
- package/dist/docs/pages/actions/catalog/arxiv.md +166 -0
- package/dist/docs/pages/actions/catalog/chainalysis-sanctions.md +125 -0
- package/dist/docs/pages/actions/catalog/coingecko.md +1558 -0
- package/dist/docs/pages/actions/catalog/deps-dev.md +465 -0
- package/dist/docs/pages/actions/catalog/dexscreener.md +568 -0
- package/dist/docs/pages/actions/catalog/discord.md +784 -0
- package/dist/docs/pages/actions/catalog/finnhub.md +776 -0
- package/dist/docs/pages/actions/catalog/frankfurter.md +438 -0
- package/dist/docs/pages/actions/catalog/github.md +1853 -0
- package/dist/docs/pages/actions/catalog/gmail.md +575 -0
- package/dist/docs/pages/actions/catalog/google-calendar.md +654 -0
- package/dist/docs/pages/actions/catalog/google-drive.md +502 -0
- package/dist/docs/pages/actions/catalog/google-sheets.md +700 -0
- package/dist/docs/pages/actions/catalog/hacker-news.md +542 -0
- package/dist/docs/pages/actions/catalog/http.md +824 -0
- package/dist/docs/pages/actions/catalog/hyperliquid.md +942 -0
- package/dist/docs/pages/actions/catalog/jira.md +920 -0
- package/dist/docs/pages/actions/catalog/kalshi.md +917 -0
- package/dist/docs/pages/actions/catalog/linear.md +1030 -0
- package/dist/docs/pages/actions/catalog/markets.md +21 -0
- package/dist/docs/pages/actions/catalog/morpho.md +247 -0
- package/dist/docs/pages/actions/catalog/notion.md +1077 -0
- package/dist/docs/pages/actions/catalog/nws.md +485 -0
- package/dist/docs/pages/actions/catalog/open-meteo.md +559 -0
- package/dist/docs/pages/actions/catalog/polymarket.md +1523 -0
- package/dist/docs/pages/actions/catalog/pushbullet.md +220 -0
- package/dist/docs/pages/actions/catalog/resend.md +307 -0
- package/dist/docs/pages/actions/catalog/s3.md +513 -0
- package/dist/docs/pages/actions/catalog/sec-edgar.md +487 -0
- package/dist/docs/pages/actions/catalog/slack.md +2629 -0
- package/dist/docs/pages/actions/catalog/stripe.md +1405 -0
- package/dist/docs/pages/actions/catalog/wikipedia.md +379 -0
- package/dist/docs/pages/actions/catalog.md +46 -0
- package/dist/docs/pages/actions/limits.md +50 -0
- package/dist/docs/pages/actions/model-tools.md +225 -0
- package/dist/docs/pages/actions/packs.md +148 -0
- package/dist/docs/pages/actions/settings.md +69 -0
- package/dist/docs/pages/actions/tools.md +244 -0
- package/dist/docs/pages/actions/triggers.md +149 -0
- package/dist/docs/pages/actions.md +88 -0
- package/dist/docs/pages/compat/anthropic.md +168 -0
- package/dist/docs/pages/compat/e2b.md +194 -0
- package/dist/docs/pages/compat/firecrawl.md +138 -0
- package/dist/docs/pages/compat/openai.md +168 -0
- package/dist/docs/pages/concepts/auth.md +151 -0
- package/dist/docs/pages/concepts/beta.md +55 -0
- package/dist/docs/pages/concepts/glossary.md +71 -0
- package/dist/docs/pages/concepts/ids.md +98 -0
- package/dist/docs/pages/concepts/jobs.md +229 -0
- package/dist/docs/pages/concepts/latency.md +138 -0
- package/dist/docs/pages/concepts/limits.md +191 -0
- package/dist/docs/pages/concepts/stack.md +59 -0
- package/dist/docs/pages/concepts/timing.md +86 -0
- package/dist/docs/pages/concepts/usage.md +110 -0
- package/dist/docs/pages/design/b3os-yaml.md +370 -0
- package/dist/docs/pages/design/deploy-from-github.md +122 -0
- package/dist/docs/pages/design/observability.md +134 -0
- package/dist/docs/pages/errors.md +1824 -0
- package/dist/docs/pages/infer/chat.md +570 -0
- package/dist/docs/pages/infer/limits.md +55 -0
- package/dist/docs/pages/infer/messages.md +185 -0
- package/dist/docs/pages/infer/responses.md +173 -0
- package/dist/docs/pages/infer/settings.md +154 -0
- package/dist/docs/pages/infer/speech.md +323 -0
- package/dist/docs/pages/infer.md +154 -0
- package/dist/docs/pages/introduction.md +162 -0
- package/dist/docs/pages/platform/addresses.md +174 -0
- package/dist/docs/pages/platform/call-log.md +99 -0
- package/dist/docs/pages/platform/custom-domains.md +104 -0
- package/dist/docs/pages/platform/keys.md +79 -0
- package/dist/docs/pages/platform/limits.md +57 -0
- package/dist/docs/pages/platform/members.md +101 -0
- package/dist/docs/pages/platform/requests.md +116 -0
- package/dist/docs/pages/platform/settings.md +129 -0
- package/dist/docs/pages/platform/webhooks.md +68 -0
- package/dist/docs/pages/platform.md +67 -0
- package/dist/docs/pages/quickstart/mcp.md +94 -0
- package/dist/docs/pages/quickstart/sandbox-agent.md +205 -0
- package/dist/docs/pages/quickstart/scrape.md +134 -0
- package/dist/docs/pages/quickstart.md +45 -0
- package/dist/docs/pages/render/inspections.md +162 -0
- package/dist/docs/pages/render/limits.md +72 -0
- package/dist/docs/pages/render/screenshots.md +179 -0
- package/dist/docs/pages/render/settings.md +431 -0
- package/dist/docs/pages/render/styles.md +342 -0
- package/dist/docs/pages/render/videos.md +272 -0
- package/dist/docs/pages/render.md +118 -0
- package/dist/docs/pages/routines/callables.md +174 -0
- package/dist/docs/pages/routines/definitions.md +361 -0
- package/dist/docs/pages/routines/limits.md +117 -0
- package/dist/docs/pages/routines/runs.md +328 -0
- package/dist/docs/pages/routines/settings.md +104 -0
- package/dist/docs/pages/routines/triggers.md +339 -0
- package/dist/docs/pages/routines.md +216 -0
- package/dist/docs/pages/sandboxes/agents.md +217 -0
- package/dist/docs/pages/sandboxes/commands.md +272 -0
- package/dist/docs/pages/sandboxes/images.md +166 -0
- package/dist/docs/pages/sandboxes/limits.md +143 -0
- package/dist/docs/pages/sandboxes/ports.md +260 -0
- package/dist/docs/pages/sandboxes/settings.md +358 -0
- package/dist/docs/pages/sandboxes/snapshots.md +423 -0
- package/dist/docs/pages/sandboxes/swarms.md +146 -0
- package/dist/docs/pages/sandboxes/volumes.md +131 -0
- package/dist/docs/pages/sandboxes.md +231 -0
- package/dist/docs/pages/sdks/cli.md +121 -0
- package/dist/docs/pages/sdks/mcp.md +169 -0
- package/dist/docs/pages/sdks/python.md +146 -0
- package/dist/docs/pages/sdks/typescript.md +202 -0
- package/dist/docs/pages/sdks.md +282 -0
- package/dist/docs/pages/settings.md +33 -0
- package/dist/docs/pages/vault/limits.md +46 -0
- package/dist/docs/pages/vault.md +133 -0
- package/dist/docs/pages/vision/agent-browser.md +115 -0
- package/dist/docs/pages/vision/crawl.md +333 -0
- package/dist/docs/pages/vision/extract.md +152 -0
- package/dist/docs/pages/vision/fetcher.md +15 -0
- package/dist/docs/pages/vision/limits.md +79 -0
- package/dist/docs/pages/vision/profiles.md +111 -0
- package/dist/docs/pages/vision/proxy.md +131 -0
- package/dist/docs/pages/vision/scrape.md +356 -0
- package/dist/docs/pages/vision/sessions.md +311 -0
- package/dist/docs/pages/vision/settings.md +656 -0
- package/dist/docs/pages/vision.md +175 -0
- package/dist/errors.d.ts +129 -0
- package/dist/errors.js +326 -0
- package/dist/errors.js.map +1 -0
- package/dist/main.d.ts +1 -1
- package/dist/main.js +26 -13
- package/dist/main.js.map +1 -1
- package/dist/manifest/apply.d.ts +4 -0
- package/dist/manifest/apply.js +2 -0
- package/dist/manifest/apply.js.map +1 -1
- package/dist/manifest/domains.d.ts +50 -0
- package/dist/manifest/domains.js +159 -0
- package/dist/manifest/domains.js.map +1 -0
- package/dist/manifest/link.d.ts +20 -0
- package/dist/manifest/link.js +24 -0
- package/dist/manifest/link.js.map +1 -0
- package/dist/manifest/record.d.ts +1 -1
- package/dist/tool/archive.d.ts +33 -0
- package/dist/tool/archive.js +174 -0
- package/dist/tool/archive.js.map +1 -0
- package/dist/tool/calls.d.ts +46 -0
- package/dist/tool/calls.js +274 -0
- package/dist/tool/calls.js.map +1 -0
- package/dist/tool/checks.d.ts +21 -0
- package/dist/tool/checks.js +145 -0
- package/dist/tool/checks.js.map +1 -0
- package/dist/tool/elf.d.ts +19 -0
- package/dist/tool/elf.js +107 -0
- package/dist/tool/elf.js.map +1 -0
- package/dist/tool/predict.d.ts +8 -0
- package/dist/tool/predict.js +38 -0
- package/dist/tool/predict.js.map +1 -0
- package/dist/tool/ustar.d.ts +5 -0
- package/dist/tool/ustar.js +220 -0
- package/dist/tool/ustar.js.map +1 -0
- package/package.json +6 -5
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Volumes
|
|
2
|
+
|
|
3
|
+
> Data that outlives the sandboxes that mount it. A deployed service keeps its files across deploys, rollbacks and restarts.
|
|
4
|
+
|
|
5
|
+
Source: https://docs.beta.b3os.org/sandboxes/volumes.md
|
|
6
|
+
|
|
7
|
+
A volume is a disk that outlives the sandboxes that mount it: an ext4 file system on the node, mounted at the paths
|
|
8
|
+
you name, held by one running or paused sandbox at a time. A service in [b3os.yaml](https://docs.beta.b3os.org/design/b3os-yaml#volumes) keeps
|
|
9
|
+
its database, its reports or its index on one across every deploy, rollback, restart and keepalive. Volumes are on
|
|
10
|
+
production since node release 1118 (2026-11-20); `b3os apply` and the `b3os sandbox volumes` commands come with CLI
|
|
11
|
+
0.2.2, the **next** release.
|
|
12
|
+
|
|
13
|
+
## Said plainly
|
|
14
|
+
|
|
15
|
+
- **One copy, no backup.** A volume is one file on the node's one drive. A drive failure loses it, and nothing copies
|
|
16
|
+
it elsewhere in this beta. Keep your own copy of what you cannot lose (a `pg_dump` through `b3os sandbox exec`).
|
|
17
|
+
Snapshots of a volume and an export come next.
|
|
18
|
+
- **Not encrypted at rest**, like every sandbox disk today.
|
|
19
|
+
- **Fsync what matters.** The volume's drive passes a guest `fsync` to the node's disk, so what your code flushed
|
|
20
|
+
survives a microVM that stops without warning, and a host that crashes. What it wrote and did not flush is lost
|
|
21
|
+
then. Before a planned stop (a deploy, a delete, a take down) the guest syncs and unmounts the volume first: a
|
|
22
|
+
process that still has files open on it gets `SIGTERM` and half of the node's release wait to exit (time for a
|
|
23
|
+
database to checkpoint), then `SIGKILL`. On 2026-11-20, a plain delete of a running Postgres killed nothing, and
|
|
24
|
+
its next start found a clean shutdown. Stopping every microVM of a test node at once lost neither a committed
|
|
25
|
+
Postgres row nor a flushed file, and the volume's journal replayed at the next mount.
|
|
26
|
+
- **One writer.** A volume another running or paused sandbox holds answers `409 volume_in_use`, naming the holder.
|
|
27
|
+
The node checks it twice: in its records, and in the process that places the file in a microVM. On production, a
|
|
28
|
+
create that named a running database's volume got `409 volume_in_use` with the database's sandbox as `holder`.
|
|
29
|
+
- **Only its owner deletes it.** No deploy, rollback, prune, keepalive, take down or node cleanup deletes a volume.
|
|
30
|
+
A deleted volume stays restorable for 7 days.
|
|
31
|
+
|
|
32
|
+
## Create one and mount it
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
curl -s -X POST https://beta-api.b3os.org/v1/sandboxes/volumes \
|
|
36
|
+
-H "Authorization: Bearer $B3OS_API_KEY" -H "Content-Type: application/json" \
|
|
37
|
+
-d '{"name": "reports", "size_gib": 2}'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Its blocks are allocated and reserved on the node's disk at once, so a node whose disk fills cannot fail a write to
|
|
41
|
+
it. On a test node (2026-11-20), a volume filled to `ENOSPC`, first sequentially and then with small random writes,
|
|
42
|
+
left its pool's free space where it was, because the blocks were already the volume's, and its file system stayed
|
|
43
|
+
writable. Mount it when you create a sandbox, by `vol_` ID or name, at one or more paths, each from a folder of the volume
|
|
44
|
+
(`subpath`, made on first use) or its root:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
curl -s -X POST https://beta-api.b3os.org/v1/sandboxes \
|
|
48
|
+
-H "Authorization: Bearer $B3OS_API_KEY" -H "Content-Type: application/json" \
|
|
49
|
+
-d '{"template": "base", "volumes": [{"volume": "reports", "mounts": [
|
|
50
|
+
{"path": "/workspace/app/outputs", "subpath": "outputs"},
|
|
51
|
+
{"path": "/workspace/app/data", "subpath": "data"}]}]}'
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
- At most one volume per sandbox in this beta; mount several of its folders with `subpath`.
|
|
55
|
+
- A mount path is absolute, not a system folder or under one (`/proc`, `/sys`, `/dev`, `/run`, `/etc`, `/usr`,
|
|
56
|
+
`/boot`, `/bin`, `/sbin`, `/lib*`, `/mnt`, `/var/run`): mount under `/workspace`, `/data`, `/home`, `/srv`, `/opt`
|
|
57
|
+
or `/var/lib`. Two mounts never overlap.
|
|
58
|
+
- The volume's root and each subpath folder belong to the account commands run as (`user`, or an image's `USER`) when
|
|
59
|
+
they are first made, or to `owner` (`"uid"` or `"uid:gid"`). Later mounts change no owner.
|
|
60
|
+
- A sandbox that holds a volume cannot be snapshotted or forked (`409 volume_attached`): its memory has the volume's
|
|
61
|
+
file system mounted, and a restore would be a second writer. `forkable: true` is refused with it.
|
|
62
|
+
- A create with a volume starts a microVM of its own instead of taking one the node keeps started, so it starts more
|
|
63
|
+
slowly than a create the node has a microVM ready for.
|
|
64
|
+
|
|
65
|
+
The sandbox's `volumes` lists what it holds and where. `GET /v1/sandboxes/{sandbox_id}/stats` reports the volume's
|
|
66
|
+
used bytes, and so does the volume.
|
|
67
|
+
|
|
68
|
+
## Grow, delete, restore, purge
|
|
69
|
+
|
|
70
|
+
| Call | What it does |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `GET /v1/sandboxes/volumes` | The project's volumes on this node; `?status=deleted` lists deleted ones in their grace |
|
|
73
|
+
| `GET /v1/sandboxes/volumes/{volume_id}` | One, by its `vol_` ID (these routes take IDs only: list with `?name=` to find one by name; the CLI does that for you) |
|
|
74
|
+
| `PATCH /v1/sandboxes/volumes/{volume_id}` | `size_gib` grows it while no sandbox holds it (`409 volume_attached` otherwise); its file system grows at the next mount. A volume never shrinks. `metadata` at any time |
|
|
75
|
+
| `DELETE /v1/sandboxes/volumes/{volume_id}` | Marks it deleted: not listed, not mountable, billed no more, its data kept until `purge_at`, 7 days later. Refused while a sandbox holds it |
|
|
76
|
+
| `POST /v1/sandboxes/volumes/{volume_id}/restore` | A deleted volume is `available` again, with its data, until its `purge_at`; after it, `404 volume_not_found` |
|
|
77
|
+
| `POST /v1/sandboxes/volumes/{volume_id}/purge` | `{"confirm": "<its name>"}`: its data is gone now. This cannot be undone. Only from a key, never from code in a sandbox (`403 forbidden`, reason `sandbox`) |
|
|
78
|
+
|
|
79
|
+
The CLI has the same, by name or ID:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
b3os sandbox volumes # list; --status deleted for those in their grace
|
|
83
|
+
b3os sandbox volumes create reports --size-gib 2
|
|
84
|
+
b3os sandbox volumes grow reports 4
|
|
85
|
+
b3os sandbox volumes rm reports --yes # restorable for 7 days
|
|
86
|
+
b3os sandbox volumes restore reports
|
|
87
|
+
b3os sandbox volumes purge reports --confirm reports # gone now
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
A deleted volume keeps its name until it is purged: a create with the name answers `409 volume_name_taken`. A project
|
|
91
|
+
that keeps a volume, or a deleted one still in its grace, is not deleted (`409 project_not_empty`): purge them first.
|
|
92
|
+
|
|
93
|
+
## Limits and price
|
|
94
|
+
|
|
95
|
+
| Limit | Default |
|
|
96
|
+
|---|---|
|
|
97
|
+
| The largest volume (`sandboxes.volume_max`) | 16 GiB |
|
|
98
|
+
| Volumes an organization keeps on a node (`sandboxes.volumes_max`) | 10, deleted ones in their grace included |
|
|
99
|
+
| GiB of volumes an organization keeps on a node (`sandboxes.volume_storage_max`) | 32 GiB, deleted ones in their grace included |
|
|
100
|
+
|
|
101
|
+
Past one, a create or a grow answers `422 limit_exceeded` naming it. A volume is metered as `sandboxes.volume_gib_h`,
|
|
102
|
+
its size times the hours it exists, mounted or not, from its create to its delete; it is priced at 0 in the beta.
|
|
103
|
+
|
|
104
|
+
## In b3os.yaml
|
|
105
|
+
|
|
106
|
+
A deployed service declares its volume, and the deploy creates it by name (`<application>.<volume>`), keeps it,
|
|
107
|
+
grows it, and mounts it in every new generation:
|
|
108
|
+
|
|
109
|
+
```yaml
|
|
110
|
+
volumes:
|
|
111
|
+
reports:
|
|
112
|
+
size_gib: 2
|
|
113
|
+
services:
|
|
114
|
+
- name: researcher
|
|
115
|
+
mounts:
|
|
116
|
+
- { volume: reports, path: /workspace/app/outputs, subpath: outputs }
|
|
117
|
+
- { volume: reports, path: /workspace/app/data, subpath: data }
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
A deploy of a service with a volume stops its old generation first, then starts the new one, and the service serves
|
|
121
|
+
nothing in between: [b3os.yaml, Volumes](https://docs.beta.b3os.org/design/b3os-yaml#volumes) has what the plan says, what survives a deploy,
|
|
122
|
+
and what `b3os app down` keeps. `examples/deploy/postgres-volume/` in the repository runs Postgres 16 with pgvector,
|
|
123
|
+
from Ubuntu's packages, on a volume.
|
|
124
|
+
|
|
125
|
+
## Errors
|
|
126
|
+
|
|
127
|
+
[`volume_not_found`](https://docs.beta.b3os.org/errors#volume_not_found), [`volume_name_taken`](https://docs.beta.b3os.org/errors#volume_name_taken),
|
|
128
|
+
[`volume_in_use`](https://docs.beta.b3os.org/errors#volume_in_use), [`volume_attached`](https://docs.beta.b3os.org/errors#volume_attached),
|
|
129
|
+
[`volume_drive_missing`](https://docs.beta.b3os.org/errors#volume_drive_missing) (a snapshot from before the node had volumes: take it again;
|
|
130
|
+
a deploy builds again on its own), [`volume_unmountable`](https://docs.beta.b3os.org/errors#volume_unmountable), and
|
|
131
|
+
[`guest_outdated`](https://docs.beta.b3os.org/errors#guest_outdated) for a template whose guest agent predates volumes.
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Sandboxes
|
|
2
|
+
|
|
3
|
+
> Firecracker microVMs claimed from warm pools on the B3OS node, with commands, files, a terminal, ports, snapshots and a scoped API grant.
|
|
4
|
+
|
|
5
|
+
Source: https://docs.beta.b3os.org/sandboxes.md
|
|
6
|
+
|
|
7
|
+
A sandbox is a Firecracker microVM with its own kernel, claimed from a pool of microVMs that were restored from a snapshot ahead of time. Your request does not wait for a boot. Use one to run code an agent wrote, to give an agent a computer of its own, or to run the agent itself on the node, next to the model the node serves.
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { B3OS } from "@b3os/sdk";
|
|
11
|
+
const b3os = new B3OS();
|
|
12
|
+
const sandbox = await b3os.sandboxes.createSandbox({ template: "base" });
|
|
13
|
+
const run = await b3os.sandboxes.exec(sandbox.id, { cmd: "python3 -c 'print(2 + 2)'" });
|
|
14
|
+
console.log(run.stdout); // 4
|
|
15
|
+
await b3os.sandboxes.deleteSandbox(sandbox.id);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
A sandbox created with `forkable: true` can [fork](https://docs.beta.b3os.org/sandboxes/snapshots#fork): its running microVM, memory and processes included, is copied into up to 10 children that start where it was. An agent tries several fixes at once that way and keeps the one that passes.
|
|
19
|
+
|
|
20
|
+
Measured on the B3OS node, from the [benchmark board](https://docs.beta.b3os.org/benchmarks#headline-results). Each figure links its raw data; the board has the conditions.
|
|
21
|
+
|
|
22
|
+
- **Under 3 ms**: Sandbox claimed, first command run (warm sandbox pool, p50 from a client on the same host, 2026-11-02; pool misses 0% of 200 claims). [Raw data](https://beta.b3os.org/raw/bench/bench/results/20261102T092119Z-w4q-mixed/sandboxes-claim-exec-mixed/sandboxes.claim_first_exec.gap-100ms+bg.result.json)
|
|
23
|
+
- **Under 1.2 ms**: POST /v1/sandboxes, timed by the server (warm slot in the pool, p50 timed by the server, 2026-11-02; pool misses 0% of 200 claims). [Raw data](https://beta.b3os.org/raw/bench/bench/results/20261102T092119Z-w4q-mixed/sandboxes-claim-exec-mixed/sandboxes.claim_first_exec.gap-100ms+bg.result.json)
|
|
24
|
+
- **0.306 ms**: A command in a running sandbox (/bin/true, p50 timed by the server, 2026-11-02). [Raw data](https://beta.b3os.org/raw/bench/bench/results/20261102T082836Z-w4q-idle/sandboxes-exec-rtt/sandboxes.exec_rtt.b2b-c1.result.json)
|
|
25
|
+
- **Under 35 ms**: Fork of a running sandbox, timed by the server (128 MiB sandbox with no memory written since boot, p50 timed by the server, 2026-11-21). [Raw data](https://beta.b3os.org/raw/bench/sandboxes/results/20261121T080844Z-w3-prod-fork-overlay/fork-128mib-dirty0mib.result.json)
|
|
26
|
+
- **Under 60 ms**: 5 forks in one call, timed by the server (one POST …/fork with count 5 of a 128 MiB sandbox with no memory written since boot, p50 timed by the server, 2026-11-24). [Raw data](https://beta.b3os.org/raw/bench/sandboxes/results/20261124T231112Z-w3-n2-fanout/fanout-128mib-dirty0mib-x5.result.json)
|
|
27
|
+
|
|
28
|
+
Next to what others publish, each timed the same way, server or client, from the same kind of vantage point. A multiplier is the other provider's published figure divided by B3OS's p50, rounded down.
|
|
29
|
+
|
|
30
|
+
- **4x to 4.6x below boxd's published p50**: Sandbox create, timed by the server. B3OS 1.09 to 1.24 ms (p50, 4 configurations, 2026-11-08); boxd publishes 5 ms ([source](https://boxd.sh/blog/moyai/)). [How it was measured](https://beta.b3os.org/benchmarks#sandboxes)
|
|
31
|
+
- **13x to 16x below CubeSandbox's published mean**: Sandbox create to running, from a client on the same host. B3OS 2.81 to 3.61 ms (p50, 4 configurations, 2026-11-08); CubeSandbox publishes 47.8 ms ([source](https://github.com/TencentCloud/CubeSandbox/blob/master/docs/blog/posts/2026-06-01-cubesandbox-perf-benchmark.md)). [How it was measured](https://beta.b3os.org/benchmarks#sandboxes)
|
|
32
|
+
|
|
33
|
+
## Create a sandbox
|
|
34
|
+
|
|
35
|
+
**curl**
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
curl -s https://beta-api.b3os.org/v1/sandboxes \
|
|
39
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
40
|
+
-H "Content-Type: application/json" \
|
|
41
|
+
-d '{"template": "base", "vcpu": 2, "memory_mib": 2048, "timeout_s": 900}'
|
|
42
|
+
```
|
|
43
|
+
**TypeScript**
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { B3OS } from "@b3os/sdk";
|
|
47
|
+
|
|
48
|
+
const b3os = new B3OS();
|
|
49
|
+
const sandbox = await b3os.sandboxes.createSandbox({ template: "base", vcpu: 2, memory_mib: 2048, timeout_s: 900 });
|
|
50
|
+
console.log(sandbox.id, sandbox.status, sandbox.expires_at);
|
|
51
|
+
```
|
|
52
|
+
**Python**
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from b3os import B3OS
|
|
56
|
+
|
|
57
|
+
b3os = B3OS()
|
|
58
|
+
sandbox = b3os.sandboxes.create_sandbox({"template": "base", "vcpu": 2, "memory_mib": 2048, "timeout_s": 900})
|
|
59
|
+
print(sandbox["id"], sandbox["status"], sandbox["expires_at"])
|
|
60
|
+
```
|
|
61
|
+
**MCP**
|
|
62
|
+
|
|
63
|
+
```text
|
|
64
|
+
Start a sandbox and run `python3 -c "import sys; print(sys.version)"` in it.
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The agent calls `sandbox_create`, then `sandbox_exec` with the sandbox ID and the command, and `sandbox_delete` when it is done.
|
|
68
|
+
|
|
69
|
+
The sandbox comes back `running`. Its `timing` shows where the time went: `validate_ms`, then `claim_ms` and `resume_ms` when a microVM came from the pool, or `restore_ms` when none was waiting (a restore on demand, or from a snapshot), then `bind_ms` (the sandbox's identity and environment reaching the guest) and `total_ms`.
|
|
70
|
+
|
|
71
|
+
| Field | Default | Meaning |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `template` | `base` | The template to start from, by name or `tpl_` ID |
|
|
74
|
+
| `snapshot` | none | Restore one of your [snapshots](https://docs.beta.b3os.org/sandboxes/snapshots) instead of a template |
|
|
75
|
+
| `vcpu` | 1 | Virtual CPUs, up to your plan's maximum (2 in the beta) |
|
|
76
|
+
| `memory_mib` | 512 | Memory in MiB, up to 2048 in the beta, rounded up to 128 MiB or the next multiple of 256 MiB ([sizes](#sizes)) |
|
|
77
|
+
| `disk_gib` | the template's | Disk size in GiB; in v0.1 at most the template's own disk, since disks do not grow ([`limit_exceeded`](https://docs.beta.b3os.org/errors#limit_exceeded) otherwise) |
|
|
78
|
+
| `timeout_s` | 300 | Lifetime in seconds from creation or from the last extension; the beta allows up to an hour |
|
|
79
|
+
| `on_idle` | `stop` | What happens at `expires_at`: `stop` destroys the sandbox, `pause` keeps it for a later resume. It acts at `expires_at`, not when the sandbox is idle, so the SDKs and CLI 0.1.3 call it `on_timeout` |
|
|
80
|
+
| `env` | none | Environment variables, returned as given |
|
|
81
|
+
| `secrets` | none | Environment variables the API never returns and B3OS never logs, but that any code in the sandbox can read; see [secrets](#secrets) |
|
|
82
|
+
| `ports` | none | Up to 8 ports to reach from outside; see [ports](https://docs.beta.b3os.org/sandboxes/ports) |
|
|
83
|
+
| `api` | no access | What code inside may call on B3OS; see [agents in sandboxes](https://docs.beta.b3os.org/sandboxes/agents) |
|
|
84
|
+
| `egress` | `public` | Where the sandbox's traffic may go: `public`, `allowlist` or `deny` |
|
|
85
|
+
| `forkable` | `false` | Track the memory the sandbox changes, so it can be [forked](https://docs.beta.b3os.org/sandboxes/snapshots#fork) |
|
|
86
|
+
| `metadata` | none | Up to 16 string keys of your own, returned with the sandbox |
|
|
87
|
+
|
|
88
|
+
[Sandbox settings](https://docs.beta.b3os.org/sandboxes/settings) lists every setting, of commands and port URLs too, with its values and an example, and what is fixed in the beta.
|
|
89
|
+
|
|
90
|
+
### Sizes
|
|
91
|
+
|
|
92
|
+
A restored microVM keeps the size its snapshot was taken at, because Firecracker cannot add CPUs to a running VM. `memory_mib` is rounded up to 128 MiB or the next multiple of 256 MiB, and the sandbox shows, and bills `sandboxes.gib_ms` for, the rounded amount, so a request for 600 runs with 768.
|
|
93
|
+
|
|
94
|
+
Each template's default size, under `defaults` in `GET /v1/sandboxes/templates`, has a pool of microVMs restored ahead of time, and so can a few other sizes the node is set up for. A create at any other `vcpu` and memory is restored on demand: the first one at a new size also builds a snapshot for that size, and every one of them is slower than a claim from a pool and counts as a pool miss in [benchmarks](https://docs.beta.b3os.org/benchmarks). Ask for the template's default size when start-up time matters.
|
|
95
|
+
|
|
96
|
+
Note:
|
|
97
|
+
The build contract plans size classes that each template lists as `size_classes`: its default size and at most one larger class, each with its own pool. The API does not list them yet; until it does, the rounding and pools above are what apply.
|
|
98
|
+
|
|
99
|
+
### If the connection drops
|
|
100
|
+
|
|
101
|
+
A create that has started finishes even if your connection drops before the response: the sandbox then runs, and bills, until its timeout or a delete. Its answer is stored under the `Idempotency-Key`, so a retry with the same key gets the same sandbox with `Idempotent-Replayed: true`, or `409` [`idempotency_request_in_progress`](https://docs.beta.b3os.org/errors#idempotency_request_in_progress) while the create still runs. The SDKs send a key and retry with it. Without a key a retry is a new create: look for the first one with `GET /v1/sandboxes`, by the `metadata` you gave it. Fork, snapshot, pause and resume also finish after a disconnect.
|
|
102
|
+
|
|
103
|
+
## Templates
|
|
104
|
+
|
|
105
|
+
`GET /v1/sandboxes/templates` lists the templates with their OS, runtimes, capabilities and default sizes, not their packages. What each one holds:
|
|
106
|
+
|
|
107
|
+
| Template | Contents |
|
|
108
|
+
|---|---|
|
|
109
|
+
| `base` | Ubuntu 24.04 with Python 3.12, Node 24 and git |
|
|
110
|
+
| `code-interpreter` | `base` plus a Jupyter kernel for [`run_code`](https://docs.beta.b3os.org/sandboxes/commands#run-code-in-a-kernel), in Python and JavaScript |
|
|
111
|
+
| `agent` | `base` plus the Codex CLI, the Claude Agent SDK, the OpenAI Agents SDK, LangGraph and `b3os-harness`, outbound only: a Claude Managed Agents worker or dispatcher (one sandbox per session, paused between turns, optionally forked from a prepared sandbox), the OpenAI Agents API executor, and spawn hooks that start one sandbox per Claude Code self-hosted runner or Cursor pool worker. `b3os-harness` with no arguments lists its commands; the top of its file documents them |
|
|
112
|
+
| `browser` | `base` plus full Chrome (Chrome for Testing, new headless mode), started in the sandbox before you get it, with DevTools on `127.0.0.1:9222` inside the sandbox. Declare port 9222 to reach it through a [port preview](https://docs.beta.b3os.org/sandboxes/ports). A page in that Chrome can load a server you start on the sandbox's own `localhost`, and cannot reach port 9222 or the B3OS API port (`127.0.0.1:7700`). The template lists the `cdp` capability |
|
|
113
|
+
|
|
114
|
+
## Lifecycle
|
|
115
|
+
|
|
116
|
+
```mermaid
|
|
117
|
+
stateDiagram-v2
|
|
118
|
+
[*] --> running: create
|
|
119
|
+
running --> paused: pause
|
|
120
|
+
paused --> running: resume
|
|
121
|
+
running --> stopped: delete or timeout
|
|
122
|
+
paused --> stopped: delete or timeout
|
|
123
|
+
running --> failed: microVM crashed
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- **Extend** with `POST /v1/sandboxes/{sandbox_id}/timeout` and a new `timeout_s`, counted from now. It works on running and paused sandboxes. A longer life is billed, so an extension, like a resume, is admitted the way a create is (spend cap, organization status).
|
|
127
|
+
- **Pause** freezes the vCPUs and keeps memory and disk on the node; **resume** continues exactly where it stopped, with the guest clock corrected. See [snapshots and pausing](https://docs.beta.b3os.org/sandboxes/snapshots).
|
|
128
|
+
- **Delete** stops the sandbox and destroys its memory and disk. It returns the stopped sandbox with its final usage; snapshots taken from it are kept.
|
|
129
|
+
- A stopped sandbox cannot be restarted. Calls that need a running one fail with [`sandbox_not_running`](https://docs.beta.b3os.org/errors#sandbox_not_running), whose `current_status` says why.
|
|
130
|
+
- **Owner.** A sandbox stops when the key that created it is revoked or expires (`stop_reason: revoked`). Create it with `"owner": "project"` and `metadata."b3os.app"` to make it a service of an application instead: it keeps running whatever happens to that key's credential, within its grant, its organization's credits and its spend cap (its grant's, else the key's, shared with everything the key runs), until it is deleted or taken down. What its own code starts ends with it (`root`). Its `owner` and `created_by_key` say which it is; `GET /v1/sandboxes?owner=project&created_by_key=<key_id>` lists the services a key created. See [services belong to their project](https://docs.beta.b3os.org/concepts/auth#services-belong-to-their-project).
|
|
131
|
+
|
|
132
|
+
### What it uses now
|
|
133
|
+
|
|
134
|
+
`GET /v1/sandboxes/{sandbox_id}/stats` reads a running sandbox's CPU, memory, disk and processes without running anything in it. It needs `sandboxes:read`.
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
curl -s "https://beta-api.b3os.org/v1/sandboxes/$SBX/stats" -H "Authorization: Bearer $B3OS_API_KEY"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
An example answer:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"object": "sandbox_stats",
|
|
145
|
+
"sandbox_id": "sbx_01m5t68q1b590rj801nbzsqzkk",
|
|
146
|
+
"taken_at": "2026-11-10T19:30:00.123Z",
|
|
147
|
+
"cpu": { "percent": 12.5, "vcpu": 2, "interval_ms": 5000 },
|
|
148
|
+
"memory": { "used_bytes": 381681664, "available_bytes": 1706033152, "total_bytes": 2087714816 },
|
|
149
|
+
"disk": { "used_bytes": 1610612736, "total_bytes": 4227858432 },
|
|
150
|
+
"processes": { "running": 1, "total": 7 }
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- `cpu.percent` is the share of all the sandbox's vCPUs that was busy over the last `interval_ms`: since your previous stats call for this sandbox when that was 1 second to 5 minutes ago, else over 250 ms. Poll it no faster than every 2 seconds.
|
|
155
|
+
- `memory` is the guest kernel's own count. `total_bytes` is a little under the sandbox's `memory_mib`, because the kernel keeps some for itself.
|
|
156
|
+
- `disk` is the root filesystem, and `processes.total` counts every process in the sandbox (kernel threads left out); both are `null` in a sandbox whose image predates them. `processes.running` counts the background processes `GET /v1/sandboxes/{sandbox_id}/processes` lists as running.
|
|
157
|
+
|
|
158
|
+
Every start gives the sandbox an identity of its own, whether it comes from a template, a snapshot or a fork: before your first command runs, the guest kernel's random generator gets fresh entropy, and the sandbox gets a new machine ID, its own hostname and the current time. So `/dev/urandom` and `getrandom()` give different bytes in every sandbox. Processes that were already running in the template or snapshot a sandbox starts from, or in a fork's source, are another matter, whether you started them or B3OS did. Each sandbox gets them with the same memory, so a random generator they hold in memory (a browser's `Math.random`, a TLS library's) starts in the same state in every sandbox made from that template, snapshot or fork, unless B3OS resets it. B3OS reseeds the code kernel's Python `random` module and NumPy global generator on every start. Chrome is not a process in the `browser` template's snapshot: B3OS starts a new one in every sandbox created from the template, after the guest kernel's generator gets fresh entropy, with a profile directory of its own. On a fork or a restore of your snapshot, Chrome runs in the copied memory, and B3OS resets it by default (`clone_reset`, see [random state on restore and fork](https://docs.beta.b3os.org/sandboxes/snapshots#random-state-on-restore-and-fork)). Start processes of your own after the sandbox starts, or restart them; [what a restore or fork keeps](https://docs.beta.b3os.org/sandboxes/snapshots#what-a-restore-or-fork-keeps) lists the common ones and what each template runs. A sandbox's disk is a copy-on-write clone made for it, of the template's pristine image or of the snapshot's or source's disk, never a disk another sandbox used.
|
|
159
|
+
|
|
160
|
+
Sandboxes keep running when the node's B3OS service restarts. Their microVMs run in a separate unit on the node, and the service that starts next takes over every running and paused sandbox whose microVM is still there, its grant and egress included. A sandbox whose microVM is gone by then (it crashed, or the node itself rebooted) is reported `failed`, with its memory and disk lost. Snapshots survive both.
|
|
161
|
+
|
|
162
|
+
<a href="https://beta.b3os.org/gallery/docs-site/shot-sandboxes/493d7c479740d596.webp"><img src="https://beta.b3os.org/gallery/docs-site/shot-sandboxes/493d7c479740d596.webp" srcset="https://beta.b3os.org/gallery/docs-site/shot-sandboxes/cbf9bb696ac6cb7d.webp 640w, https://beta.b3os.org/gallery/docs-site/shot-sandboxes/74a4b75525486f39.webp 1080w, https://beta.b3os.org/gallery/docs-site/shot-sandboxes/493d7c479740d596.webp 2910w" sizes="(max-width: 640px) calc(100vw - 60px), 760px" alt="Sandboxes in the dashboard: image from the capture docs-site/shot-sandboxes" width="2910" height="2038" loading="lazy" /></a>
|
|
163
|
+
|
|
164
|
+
<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/shot-sandboxes`.</sub>
|
|
165
|
+
|
|
166
|
+
## Networking
|
|
167
|
+
|
|
168
|
+
A sandbox has no network card. Its outbound traffic leaves through the node's egress guard, which allows the public internet by default and never the node's network, loopback or cloud metadata addresses. Narrow it per sandbox:
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{ "template": "base", "egress": { "mode": "allowlist", "allow": ["github.com", "*.githubusercontent.com"] } }
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Each `allow` entry is a host name or a `*.` wildcard, with an optional port: `db.example.com:5432`. An entry without a port opens only ports 80 and 443, so a database, a cache or any other service on another port needs its port in the entry.
|
|
175
|
+
|
|
176
|
+
`deny` blocks outbound traffic entirely. Inbound traffic reaches a sandbox only through its declared [ports](https://docs.beta.b3os.org/sandboxes/ports). Code in a sandbox cannot change its own sandbox's egress, whatever its grant (`403` [`forbidden`](https://docs.beta.b3os.org/errors#forbidden)); only a caller outside it can.
|
|
177
|
+
|
|
178
|
+
Programs that do not follow the transparent route can use the proxies inside the sandbox: SOCKS5 on `127.0.0.1:1080` and HTTP `CONNECT` on `127.0.0.1:3128`. Both go through the same egress guard and policy.
|
|
179
|
+
|
|
180
|
+
A sandbox has at most 512 outbound connections open and 64 DNS queries in flight at once. Past that, new connections are refused (`egress_unavailable`) and queries answered `SERVFAIL`, at once rather than after a timeout. DNS answers carry IPv4 addresses only, so outbound traffic is IPv4. When the sandbox stops, its outbound connections and its connections to `http://127.0.0.1:7700` close at once. Taking a snapshot or a fork resets the source sandbox's open connections to the outside; see [snapshots](https://docs.beta.b3os.org/sandboxes/snapshots#save-a-snapshot).
|
|
181
|
+
|
|
182
|
+
### What egress does not close
|
|
183
|
+
|
|
184
|
+
- **Other products.** A sandbox is closed to the outside only with egress `deny` and an `api` grant with no scopes of products that reach the network for it (`vision`, `render`, `actions`, `infer`). Those products fetch URLs and call services on their own terms, so a `vision:run` grant lets code in the sandbox send data to any page it asks vision to scrape, whatever the sandbox's own egress.
|
|
185
|
+
- **Timing channels between sandboxes.** Sandboxes on one node share physical CPU cores (the two hardware threads of a core can run vCPUs of different sandboxes), the last-level cache, memory bandwidth and the storage path. Egress `deny` and `allowlist` stop network exfiltration, not low-bandwidth signalling through CPU-cache, CPU-contention or storage timing between cooperating code in any two sandboxes on the node, including two of your own. OpenAI described such channels between microVMs in its [training environment write-up](https://openai.com/index/securing-our-frontier-model-training-environment/) (October 2026).
|
|
186
|
+
|
|
187
|
+
What a guest can reach on the host is small: a read-only root drive, its own writable disk, an entropy device and one vsock port. Over that port the agent inside the sandbox opens four kinds of connection to the node: `control` (the node's requests to the agent: commands, files, terminals), `dns` (its resolver), `egress` (each outbound TCP connection, through the egress guard) and `api` (the B3OS API at `http://127.0.0.1:7700`, under the sandbox's grant). The node identifies the sandbox by the socket a connection arrives on, never by what the guest sends.
|
|
188
|
+
|
|
189
|
+
## Secrets
|
|
190
|
+
|
|
191
|
+
`secrets` are environment variables of the sandbox's processes. The API never returns their values (a sandbox lists only `secret_names`) and B3OS never logs them, but any code running in the sandbox can read them: the code your agent writes, a package it installs, a command it runs. A value placed there is only as safe as everything that runs in the VM, and the sandbox's egress decides where it could be sent.
|
|
192
|
+
|
|
193
|
+
When the credential is for a service that a marketplace action calls, keep it out of the VM instead: store it as a [vault connection](https://docs.beta.b3os.org/vault), grant the connection in `api.connections`, and call the action from the sandbox. The node's egress proxy adds the credential to the outgoing request and the sandbox never sees it. Adding credentials at the proxy for the sandbox's own HTTP requests, so that `secrets` values never enter the VM either, is planned. [Agents in sandboxes](https://docs.beta.b3os.org/sandboxes/agents#give-the-sandbox-a-credential) shows each way.
|
|
194
|
+
|
|
195
|
+
## Inside the sandbox
|
|
196
|
+
|
|
197
|
+
The environment includes:
|
|
198
|
+
|
|
199
|
+
| Variable | Value |
|
|
200
|
+
|---|---|
|
|
201
|
+
| `B3OS_API_URL` | `http://127.0.0.1:7700`, the B3OS API without a key |
|
|
202
|
+
| `B3OS_SANDBOX_ID` | The sandbox's `sbx_` ID |
|
|
203
|
+
| `B3OS_PROJECT` | Your project ID |
|
|
204
|
+
| `B3OS_PORT_BASE_PATH` | `/sbx/<host_id>`, the fixed start of every port preview path |
|
|
205
|
+
|
|
206
|
+
The B3OS SDK and CLI detect `B3OS_API_URL` and use it on their own.
|
|
207
|
+
|
|
208
|
+
## Billing and scopes
|
|
209
|
+
|
|
210
|
+
A running sandbox bills `sandboxes.vcpu_ms` (CPU time it used) and `sandboxes.gib_ms` (allocated memory times wall time). A paused sandbox bills neither meter: no CPU time and no memory, though its memory stays reserved on the node. The sandbox's `usage` shows what it was charged. Prices are zero during the beta; see [pricing](https://docs.beta.b3os.org/concepts/usage#pricing).
|
|
211
|
+
|
|
212
|
+
| Scope | For |
|
|
213
|
+
|---|---|
|
|
214
|
+
| `sandboxes:write` | Create, delete, pause, resume, snapshot and extend sandboxes |
|
|
215
|
+
| `sandboxes:run` | Run commands and code, read and write files, open terminals, read logs, mint port URLs |
|
|
216
|
+
| `sandboxes:read` | List and read sandboxes, snapshots and templates |
|
|
217
|
+
|
|
218
|
+
## Guides
|
|
219
|
+
|
|
220
|
+
- [Commands, code and files](https://docs.beta.b3os.org/sandboxes/commands)
|
|
221
|
+
Exec, streaming output, background processes, run_code, files and a terminal.
|
|
222
|
+
- [Ports and previews](https://docs.beta.b3os.org/sandboxes/ports)
|
|
223
|
+
Reach a server in the sandbox through a signed URL.
|
|
224
|
+
- [Snapshots, pausing and forks](https://docs.beta.b3os.org/sandboxes/snapshots)
|
|
225
|
+
Pause and resume, save a sandbox, start new ones from it, and fork a running one.
|
|
226
|
+
- [Agents in sandboxes](https://docs.beta.b3os.org/sandboxes/agents)
|
|
227
|
+
Grants, the in-sandbox API, secrets from the vault and nested sandboxes.
|
|
228
|
+
- [E2B compatibility](https://docs.beta.b3os.org/compat/e2b)
|
|
229
|
+
Run code written for the e2b SDKs here by changing three environment variables.
|
|
230
|
+
|
|
231
|
+
[Limits and FAQ](https://docs.beta.b3os.org/sandboxes/limits) lists the caps and the common questions.
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# CLI
|
|
2
|
+
|
|
3
|
+
> The b3os command line for signing in, scraping, screenshots, sandboxes, routines, actions and the MCP server, built for scripts and agents too.
|
|
4
|
+
|
|
5
|
+
Source: https://docs.beta.b3os.org/sdks/cli.md
|
|
6
|
+
|
|
7
|
+
The CLI is the `@b3os/cli` package on npm, a Node program (Node 22.3 or later) built on the TypeScript SDK. Run it without installing, or install it globally:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx -y @b3os/cli@0.2 --help
|
|
11
|
+
npm install -g @b3os/cli@0.2
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Set up in one line
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx -y @b3os/cli@0.2 init
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`init` does three things and reports each. It checks your credential with `GET /v1/ping` (`--api-key`, `B3OS_API_KEY` or a stored login); without a working one it runs the device login below, asking for the default agent scopes (every product's read, write and run; vault read and run; platform read), which you can narrow when you approve it. It adds the B3OS MCP server to each agent it finds on this machine: Claude Code (the `claude` CLI on your PATH), Cursor (`~/.cursor`) and Codex (`codex` on your PATH or `~/.codex`), or only the ones you name with `--client cursor,codex`. Then it pings again and prints the first call's time, connection included, and the warm round trip. The first measurements, from the node's own uplink, are in the repository's `bench/edge/README.md` ("Time to a first call"). It exits non-zero when a step failed and `--json` prints one summary; `--no-mcp` and `--no-login` skip those steps.
|
|
21
|
+
|
|
22
|
+
## Sign in
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
b3os login
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`login` starts a device login: it prints a short code and a link to `https://beta.b3os.org/app/device`, and opens a browser when there is a terminal. Approve it there for one organization and project, with scopes no wider than your own, and the CLI receives a `b3os_pat_` token. The page shows the CLI's version and your machine's name (CLI 0.1.3 and later), and Choose under Access lets you uncheck scopes before you approve. It stores the token in `~/.config/b3os/credentials.json` (or under `$XDG_CONFIG_HOME`), readable only by you, and never prints it. `--scope 'vision:run sandboxes:*'` asks for fewer scopes.
|
|
29
|
+
|
|
30
|
+
In a coding agent's shell, or without a terminal, `login` does not wait (0.2.2, the **next** release): it prints the link and code and exits, and a person approves the link. Then `b3os login --resume` stores the token, waiting up to `--timeout-s` (default 90) and exiting 8 if the wait ends first. `--no-wait` does the same from a terminal, `--wait` waits as before, and with `--json` the start prints one object: `status`, `verification_url`, `user_code`, `expires_at`, `invite_only`, `access_url` and `next`. To store an API key instead, pipe it in on stdin, never as an argument:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
printf %s "$B3OS_API_KEY" | b3os login --with-key
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
The CLI, the MCP server and the SDKs read the stored credential; `B3OS_API_KEY` and `--api-key` win over it.
|
|
37
|
+
|
|
38
|
+
The token lasts 30 days. `b3os logout` revokes it on the server and removes the file; CLI 0.1.0 only removes the file, and the token works until it expires. To end a token from elsewhere, revoke it on the API keys page of the dashboard, where CLI tokens are listed.
|
|
39
|
+
|
|
40
|
+
A routine you publish while signed in runs as the token, so its triggers pause when the token is revoked or expires, and a key you make with `b3os keys create` while signed in expires with the token. Publish routines and make keys for CI with an API key from the dashboard (`B3OS_API_KEY`). From CLI 0.1.3, `logout` names the routines that run as the token and asks before it revokes it, and `logout --local` only removes the file.
|
|
41
|
+
|
|
42
|
+
The CLI uses `--api-key` first, then `B3OS_API_KEY`, then the stored token, so in CI you set `B3OS_API_KEY` and skip `login`. From CLI 0.1.3 the stored token goes only to the API host it was issued by, so `--base-url` naming another host runs without it. `b3os whoami` shows which credential is in use, with its organization, project and scopes, and where node operations go. Inside a B3OS sandbox the CLI sends node operations to `B3OS_API_URL` and needs no key for them.
|
|
43
|
+
|
|
44
|
+
## Commands
|
|
45
|
+
|
|
46
|
+
| Command | Does |
|
|
47
|
+
|---|---|
|
|
48
|
+
| `init` | Sign in if needed, add the MCP server to the agents on this machine, ping and print the times |
|
|
49
|
+
| `login`, `logout`, `whoami` | Sign in, revoke and remove the stored token, show the credential in use |
|
|
50
|
+
| `keys ls`, `create`, `get`, `update`, `revoke` | Manage API keys; `create --name ci --scope vision:run,sandboxes:*` prints the secret once |
|
|
51
|
+
| `scrape <url>` | Scrape a page; Markdown on stdout by default, `--format html`, `raw_html`, `text`, `links` or `json` for others, `--out` to save |
|
|
52
|
+
| `screenshot <url>` | Take a screenshot and save it with `--out` (its extension picks the format, WebP by default); `--frame`, `--background`, `--theme`, `--full-page`, `--selector`, `--hide` style it, `--html FILE` renders your own HTML |
|
|
53
|
+
| `screenshot ls`, `rm` | List your screenshots (kept 7 days) and delete them by `shot_` ID |
|
|
54
|
+
| `video <script.json>` | Record a video from a JSON script, follow its progress and save the MP4 (`--kind gif`, `poster` or `vtt` for the others, `--no-wait` to only start it), `--formats mp4,gif,poster` for several |
|
|
55
|
+
| `video ls`, `rm` | List your videos and delete them by `vid_` ID; one still rendering is canceled first |
|
|
56
|
+
| `sandbox create` | `--template`, `--snapshot`, `--vcpu`, `--memory-mib`, `--disk-gib`, `--timeout-s`, `--on-timeout`, `--env K=V`, `--port N[:public]`, `--api-scope SCOPES`; prints the sandbox ID |
|
|
57
|
+
| `sandbox exec <id> -- <command>` | Run a command and stream its output; `--stdin` sends your stdin, `--background` starts it and returns, `--json` prints the buffered result |
|
|
58
|
+
| `sandbox shell <id>` | A terminal in the sandbox; resizing your window resizes it |
|
|
59
|
+
| `sandbox ls`, `get`, `logs`, `url`, `rm` | List, inspect, follow a background process's logs, mint a port URL, delete |
|
|
60
|
+
| `routine deploy <file>` | Publish a routine from YAML or JSON under its `name`; the first deploy creates it |
|
|
61
|
+
| `routine run <routine>` | Start a run with `--input JSON` or `--input @file`, wait and print the output; `--follow` streams step events, `--no-wait` prints the run ID |
|
|
62
|
+
| `routine logs <run_id>` | A run's steps, or `--follow` its events |
|
|
63
|
+
| `routine get`, `runs` | One routine's version, status and triggers; its runs |
|
|
64
|
+
| `routine pause`, `resume`, `rm` | Stop or restart a routine's triggers, or delete it |
|
|
65
|
+
| `action search`, `describe`, `call` | Find, inspect and call marketplace actions (`b3os action call io.b3os/github/create-issue@1 --input @issue.json`) |
|
|
66
|
+
| `mcp install --client claude` | Register the MCP server with Claude Code, Cursor or Codex (below) |
|
|
67
|
+
| `mcp serve` | Run the stdio MCP server in this process; `--packs github,slack` adds those packs' actions as tools |
|
|
68
|
+
| `bench ping`, `bench scrape`, `bench exec` | Time calls from where you run it (below) |
|
|
69
|
+
| `api <METHOD> <path>` | Any operation, with `--data JSON` or `--data @file`, `--query k=v` and `--header k=v` |
|
|
70
|
+
| `apply` | Deploy a [`b3os.yaml`](https://docs.beta.b3os.org/design/b3os-yaml): `--dry-run` prints the plan, `--keepalive` renews what runs and recreates a lost service (CLI 0.2.0), and `--keepalive --dry-run` prints what it would renew or recreate (CLI 0.2.1) |
|
|
71
|
+
| `app status`, `logs`, `requests` | A deployed application's services (a service whose process exited is down), its output and its calls to B3OS (CLI 0.2.0) |
|
|
72
|
+
| `app open [APP] [--service NAME]` | Open the application's address in the browser (a link address with a link that ends in 60 s); without a terminal, or when no browser starts, print the address. On Windows it starts the browser with `rundll32`, untested on Windows (CLI 0.2.1) |
|
|
73
|
+
| `app link [APP] [--service NAME [--port N]] [--ttl S] [--rotate] [--yes]` | Print a link to the application's own address, or to the address of service NAME (`--port N` when it has more than one), valid `--ttl` seconds (default 604800, 7 days; 60 to 7776000): anyone who has it gets in. `--rotate` first makes every link stop working within 6 s (streams and WebSockets already open can run up to an hour more), then makes the new link (CLI 0.2.1) |
|
|
74
|
+
| `app down --app NAME [--yes]` | Stop its addresses (each label stays the application's) and wait 7 s (CLI 0.2.1), then delete: each running generation (TERM, up to 30 s to exit, then delete; one an address serves again by then is kept), then the routines, then the build snapshots (CLI 0.2.0) |
|
|
75
|
+
| `app rollback [APP] [--to DEPLOY]` | Deploy again the commit of the last deploy before the current one that went live with another commit (the current one is the newest a running service generation or a routine names), or of `--to`, the exact deploy you name, from your clone without a checkout: your working tree and HEAD stay as they are, the plan and the deploy say it is a rollback, and keepalive keeps it until the next `b3os apply`. With `platform:read` the deploy records decide: a failed or undone deploy is never the target, and the plan's first line says when the target went live. Without it the service generations' tags decide: a failed deploy of a service with no older generation can pass for one that went live, and the first line says when its generation started. Read that line, or run `--dry-run`, before `--yes`. With the workflow's keepalive schedule on, a rollback (or `b3os apply`) run from a clone can overlap a scheduled keepalive; the workflow run by hand with `ref` is the rollback that queues behind it (CLI 0.2.0) |
|
|
76
|
+
|
|
77
|
+
`b3os <command> --help` shows each command's options. `sandbox create --api-scope` gives the new sandbox an [API grant](https://docs.beta.b3os.org/sandboxes/agents#grant-access). `screenshot`, `video` and `routine run` print the ID they made on stderr, so stdout holds only the file or the result.
|
|
78
|
+
|
|
79
|
+
CLI 0.1.3 names each option after the request field it sets, unit included, and still takes the older names: `--lifetime` is `--timeout-s`, `--memory` `--memory-mib`, `--disk` `--disk-gib`, `--grant` `--api-scope`, `--depth` `--max-depth`, `--include` and `--exclude` `--include-paths` and `--exclude-paths`, `--wait-for` `--wait-for-ms`, `--max-age` `--max-age-ms`, `--concurrency` `--max-concurrency`, and `--timeout` `--request-timeout-ms`. `routine deploy` is `routine publish`, `action run` `action call` and `sandbox url` `sandbox port-url`. Two set a field the API still calls by its old name: `--on-timeout` (formerly `--on-idle`) sets `on_idle`, and crawl's `--include-subdomains` sets `allow_subdomains`.
|
|
80
|
+
|
|
81
|
+
## Built for scripts and agents
|
|
82
|
+
|
|
83
|
+
The docs teach the release npm serves. A page that says a command comes with the next release names that release's version, and `npx -y @b3os/cli@0.2` does not have it yet.
|
|
84
|
+
|
|
85
|
+
- `--json` prints machine-readable output; errors then go to stderr as `{"error": {code, status, title, detail, type, request_id, errors}}`.
|
|
86
|
+
- `--yes` answers confirmations. Without a terminal the CLI never prompts, and a destructive command without `--yes` exits with code 2.
|
|
87
|
+
- Every command also takes `--quiet`, `--api-key`, `--base-url` and `--request-timeout-ms MS` (formerly `--timeout`), how long the CLI waits for each answer.
|
|
88
|
+
|
|
89
|
+
Exit codes are stable, so a script can branch on them:
|
|
90
|
+
|
|
91
|
+
| Code | Meaning |
|
|
92
|
+
|---|---|
|
|
93
|
+
| 0 | Success |
|
|
94
|
+
| 1 | An error not listed here |
|
|
95
|
+
| 2 | Usage error, or a confirmation refused without `--yes` |
|
|
96
|
+
| 3 | Not signed in, authentication or authorization (401, 403), or a `b3os login` that was denied in the dashboard or whose code expired |
|
|
97
|
+
| 4 | Not found (404) |
|
|
98
|
+
| 5 | Invalid request, conflict or state error (other 4xx, including 421 `edge_only`) |
|
|
99
|
+
| 6 | Rate limited, quota or credits (429, 402) |
|
|
100
|
+
| 7 | Server error or unavailable (5xx) |
|
|
101
|
+
| 8 | Timeout |
|
|
102
|
+
| 9 | Connection error (also a `sandbox shell` whose connection closed before the shell exited) |
|
|
103
|
+
| 10 | A job or routine run failed, or a remote command (`sandbox exec`, `sandbox shell`) exited non-zero or was killed |
|
|
104
|
+
| 130 | Interrupted |
|
|
105
|
+
|
|
106
|
+
`sandbox exec` and `sandbox shell` keep these meanings: they exit 0 when the remote command exits 0 and 10 when it exits non-zero or is killed, and print the remote exit code on stderr, so a remote code of 3 never reads as an authentication error. Pass `--exit-code` to exit with the remote command's own code instead, as `ssh` does, when a script needs it. With `--json`, the printed result carries `exit_code`.
|
|
107
|
+
|
|
108
|
+
## MCP setup
|
|
109
|
+
|
|
110
|
+
`b3os mcp install --client claude` (or `cursor`, `codex`) adds an entry that runs the local server, `npx -y @b3os/mcp@0.2` (the CLI's own minor line). The server reads `B3OS_API_KEY` or your `login` token itself, so the entry holds no secret. Claude Code gets it through `claude mcp add` (or `.mcp.json` with `--scope project` when the `claude` command is missing), Cursor through `~/.cursor/mcp.json` (or `.cursor/mcp.json`), and Codex through `~/.codex/config.toml` (or `.codex/config.toml`, where only the `[mcp_servers.b3os]` table is replaced).
|
|
111
|
+
|
|
112
|
+
- `--scope project` writes the project's configuration instead of your user's.
|
|
113
|
+
- `--packs github,slack` adds those packs' actions as tools.
|
|
114
|
+
- `--print` prints the entry instead of writing it.
|
|
115
|
+
- `--remote` points Claude Code or Cursor at the remote server, `https://beta-api.b3os.org/mcp`. The entry's `Authorization` header refers to the `B3OS_API_KEY` variable (`${B3OS_API_KEY}` for Claude Code, `${env:B3OS_API_KEY}` for Cursor), which the client fills in when it connects, so no key is written to a file, printed or put on a command line. Start the client with `B3OS_API_KEY` in its environment. Codex runs only the local server.
|
|
116
|
+
|
|
117
|
+
See [MCP server](https://docs.beta.b3os.org/sdks/mcp) for the tools.
|
|
118
|
+
|
|
119
|
+
## Bench
|
|
120
|
+
|
|
121
|
+
`b3os bench ping -n 30` (also `scrape --url <url>` and `exec --sandbox <id>`) times calls in sequence from your machine and prints client-side p50, p95 and p99 next to the server's own `Server-Timing` total and phases, so you see how much of each call is network, TLS and the edge. It is a quick probe, not the published benchmark harness: its numbers are client side, from wherever you run it. `--interval-ms` spaces the calls to see latency after idle gaps, and `--json` prints every sample.
|