@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.
- package/README.md +87 -8
- 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 -5
- package/dist/commands/app.js +229 -69
- package/dist/commands/app.js.map +1 -1
- package/dist/commands/auth.d.ts +70 -2
- package/dist/commands/auth.js +308 -33
- 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 +59 -7
- 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 +109 -1
- package/dist/commands/tool.js +635 -47
- package/dist/commands/tool.js.map +1 -1
- 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/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,166 @@
|
|
|
1
|
+
# Start sandboxes from an image
|
|
2
|
+
|
|
3
|
+
> Import a public container image once, from Docker Hub, GHCR or any OCI registry, then start sandboxes from it as you do from a template.
|
|
4
|
+
|
|
5
|
+
Source: https://docs.beta.b3os.org/sandboxes/images.md
|
|
6
|
+
|
|
7
|
+
## Availability
|
|
8
|
+
|
|
9
|
+
Imports are on for every organization on the beta since 2026-11-16. Two switches govern them:
|
|
10
|
+
|
|
11
|
+
- **Your organization.** The preview flag `images.import`, on for every organization. An organization it is off for gets `404` [`feature_not_enabled`](https://docs.beta.b3os.org/errors#feature_not_enabled) from every `/v1/images` route, and from a sandbox create with `image`.
|
|
12
|
+
- **The node.** The node needs an image store that B3OS reserves for imports. On a node without one, `POST /v1/images` answers `503` [`capacity_unavailable`](https://docs.beta.b3os.org/errors#capacity_unavailable), and the detail says why. The same answer comes back while the store is full.
|
|
13
|
+
|
|
14
|
+
Note:
|
|
15
|
+
The SDK methods on this page (`b3os.images`) come with SDK 0.2.2, the **next** release. Until then, call the
|
|
16
|
+
HTTP API as the curl examples do.
|
|
17
|
+
|
|
18
|
+
## Import an image
|
|
19
|
+
|
|
20
|
+
**curl**
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
curl -s https://beta-api.b3os.org/v1/images \
|
|
24
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
25
|
+
-H "Content-Type: application/json" \
|
|
26
|
+
-d '{"ref": "python:3.11-slim"}'
|
|
27
|
+
```
|
|
28
|
+
**TypeScript**
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { B3OS } from "@b3os/sdk";
|
|
32
|
+
|
|
33
|
+
const b3os = new B3OS();
|
|
34
|
+
let image = await b3os.images.importImage({ ref: "python:3.11-slim" });
|
|
35
|
+
while (!["ready", "failed", "evicted"].includes(image.status)) {
|
|
36
|
+
image = await b3os.images.getImage(image.id, { wait: 30 });
|
|
37
|
+
}
|
|
38
|
+
console.log(image.status, image.template);
|
|
39
|
+
```
|
|
40
|
+
**Python**
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from b3os import B3OS
|
|
44
|
+
|
|
45
|
+
b3os = B3OS()
|
|
46
|
+
image = b3os.images.import_image({"ref": "python:3.11-slim"})
|
|
47
|
+
while image["status"] not in ("ready", "failed", "evicted"):
|
|
48
|
+
image = b3os.images.get_image(image["id"], wait=30)
|
|
49
|
+
print(image["status"], image["template"])
|
|
50
|
+
```
|
|
51
|
+
**CLI**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
b3os api POST /v1/images --data '{"ref": "python:3.11-slim"}'
|
|
55
|
+
b3os api GET /v1/images/$IMAGE --query wait=30
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
No MCP tool imports images yet.
|
|
59
|
+
|
|
60
|
+
`ref` names a public image: `python:3.11-slim` on Docker Hub, `ghcr.io/<owner>/<repo>:<tag>`, or any of them pinned with `@sha256:<digest>`. B3OS resolves a tag to the image's `linux/amd64` manifest, and the image's `digest` records which one. Each layer is pulled and checked against its digest while it streams into a builder microVM that has no network. The builder writes the image's files onto one read-only file system. Nothing of the image is unpacked on the host.
|
|
61
|
+
|
|
62
|
+
The answer is `202` with the image, `status: "queued"`. The same request again from the same project answers `200` with the same image while it imports and once it is ready: one image per project, image digest, warm-up and size.
|
|
63
|
+
|
|
64
|
+
An image B3OS cannot import is refused at once with `422` [`image_refused`](https://docs.beta.b3os.org/errors#image_refused), and its `reason` says why:
|
|
65
|
+
|
|
66
|
+
| `reason` | The image |
|
|
67
|
+
|---|---|
|
|
68
|
+
| `ref_invalid` | `ref` is not a reference B3OS reads |
|
|
69
|
+
| `not_found` | the registry has no such repository, tag or digest |
|
|
70
|
+
| `platform` | has no `linux/amd64` image |
|
|
71
|
+
| `media_type` | has a layer that is not a tar, tar+gzip or tar+zstd layer, or a foreign layer |
|
|
72
|
+
| `manifest_too_large`, `config_too_large` | has a manifest or config past the node's cap |
|
|
73
|
+
| `layers` | has more layers than `images.layers_max` |
|
|
74
|
+
| `too_large` | has layers that add up to more than `images.rootfs_max` |
|
|
75
|
+
|
|
76
|
+
Trouble with the registry while resolving answers [`upstream_error`](https://docs.beta.b3os.org/errors#upstream_error), [`upstream_unreachable`](https://docs.beta.b3os.org/errors#upstream_unreachable) or [`upstream_timeout`](https://docs.beta.b3os.org/errors#upstream_timeout).
|
|
77
|
+
|
|
78
|
+
## Statuses
|
|
79
|
+
|
|
80
|
+
| `status` | Meaning |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `queued` | Waiting for its turn. One import per organization and two per node run at once |
|
|
83
|
+
| `pulling` | Layers are streaming into the builder |
|
|
84
|
+
| `flattening` | Every layer arrived; the builder finishes the file system |
|
|
85
|
+
| `warming` | The image boots once, runs its warm-up and becomes a warm snapshot |
|
|
86
|
+
| `ready` | Sandboxes start from it |
|
|
87
|
+
| `rebuilding` | B3OS updated the node and the warm snapshot is being taken again; sandboxes already running keep running |
|
|
88
|
+
| `failed` | It stopped; `error` says where and why |
|
|
89
|
+
| `evicted` | The node removed it to make room; import it again |
|
|
90
|
+
|
|
91
|
+
`GET /v1/images/{image_id}?wait=30` holds the answer until the image is `ready`, `failed` or `evicted`, at most 30 seconds; ask again until it is. `GET /v1/images` lists your project's images, newest first.
|
|
92
|
+
|
|
93
|
+
A failed image carries `error` with `code` [`import_failed`](https://docs.beta.b3os.org/errors#import_failed), the `stage` it stopped at (`resolve`, `pull`, `flatten`, `adopt`, `golden`, `rebuild`, or `interrupted` when the node restarted during the import), a `detail`, and `output`: the last 4 KiB of what the builder or the warm-up printed. Nothing of a failed import stays on the node. `POST` the same image again to start it again under the same ID. An image that failed at `rebuild` keeps its root file system, and the node tries it again at its next start; a `POST` of it imports it again over that file system, except while a sandbox or a snapshot uses it (`409` [`image_in_use`](https://docs.beta.b3os.org/errors#image_in_use)).
|
|
94
|
+
|
|
95
|
+
## Start a sandbox from an image
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
curl -s https://beta-api.b3os.org/v1/sandboxes \
|
|
99
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
100
|
+
-H "Content-Type: application/json" \
|
|
101
|
+
-d '{"image": "img_01m5t7k2v9qd8hx3n4p6r8s0tw"}'
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`image` takes the place of `template` and `snapshot` (with either of them it is a `400`). Each ready image has a template of its own, the image's `template` (a `tpl_` ID), and `{"template": "tpl_…"}` starts from it too. `GET /v1/sandboxes/templates` lists your project's image templates (`owner: "project"`) beside the node's.
|
|
105
|
+
|
|
106
|
+
- An image that is not `ready` answers `409` [`image_not_ready`](https://docs.beta.b3os.org/errors#image_not_ready), with `current_status`.
|
|
107
|
+
- Another project's image answers `404` [`image_not_found`](https://docs.beta.b3os.org/errors#image_not_found), and its template `404` [`template_not_found`](https://docs.beta.b3os.org/errors#template_not_found). Images, their templates and their warm snapshots belong to one project, and nothing is shared across projects.
|
|
108
|
+
- An image template has one size, the one the import asked for. Another `vcpu` or `memory_mib` on the create is a `400`.
|
|
109
|
+
|
|
110
|
+
## What runs in the sandbox
|
|
111
|
+
|
|
112
|
+
The image is mounted read-only under a writable layer on the sandbox's own disk, so every change the sandbox makes is its own. The sandbox's guest agent, network setup and init come from B3OS, never from the image: an `/sbin/b3os-guest` or `/etc/b3os/` in the image is ignored. B3OS writes `/etc/resolv.conf`, `/etc/hosts` and `/etc/hostname`. Egress, ports and every other sandbox setting work as for a template.
|
|
113
|
+
|
|
114
|
+
- Commands run as the image's `USER`: a name from the image's `/etc/passwd`, or a numeric `uid[:gid]`, which needs no `/etc/passwd`. An image without `USER` runs commands as root. `"user": "root"` on a command always runs it as root.
|
|
115
|
+
- Commands run in the image's `WORKDIR`, or `/` when it has none.
|
|
116
|
+
- The environment is the image's `ENV`, its `PATH` included, then the sandbox's `env`, then the command's own. B3OS adds only `HOME`, Docker's default `PATH` when the image sets none, and `TERM` in a terminal.
|
|
117
|
+
- Without `/bin/sh` in the image, commands given as an argv list and the files API work, and a command given as a shell string or a terminal answers `422` [`shell_unavailable`](https://docs.beta.b3os.org/errors#shell_unavailable), naming the missing shell.
|
|
118
|
+
- `ENTRYPOINT`, `CMD`, `EXPOSE`, volumes, labels and the healthcheck are shown in the image's `config`. Nothing starts them for you.
|
|
119
|
+
|
|
120
|
+
## Warm-up
|
|
121
|
+
|
|
122
|
+
```json
|
|
123
|
+
{
|
|
124
|
+
"ref": "python:3.11-slim",
|
|
125
|
+
"warmup": { "commands": [["python3", "-c", "import json, sqlite3, urllib.request"]] }
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`warmup.commands` holds up to 16 argv lists. While the warm snapshot is taken, B3OS runs them once each, in order, as root, with no network, and the snapshot keeps the files they read in memory. Each command runs to its end, so no process of yours is in the snapshot. A command that does not exit 0 fails the import at stage `golden`, with its output in `error.output`.
|
|
130
|
+
|
|
131
|
+
## Size
|
|
132
|
+
|
|
133
|
+
`vcpu` and `memory_mib` on the import set the size of every sandbox from the image: 1 vCPU and 1024 MiB when left out, at most the sandbox limits. The writable disk is the `base` template's.
|
|
134
|
+
|
|
135
|
+
## Limits, eviction and deletion
|
|
136
|
+
|
|
137
|
+
Every sandbox limit applies to sandboxes from an image as from a template ([sandbox limits](https://docs.beta.b3os.org/sandboxes/limits)). The image's own:
|
|
138
|
+
|
|
139
|
+
| Limit | Default |
|
|
140
|
+
|---|---|
|
|
141
|
+
| Root file system of one image (`images.rootfs_max`) | 16 GiB |
|
|
142
|
+
| Imports at once per organization (`images.imports.concurrent`) | 1; more wait in the queue, two per node |
|
|
143
|
+
| Layers per image (`images.layers_max`) | 128 |
|
|
144
|
+
|
|
145
|
+
Each image counts as one of your organization's snapshots on the node (`sandboxes.snapshots_max`). Its root file system plus its warm snapshot's memory count toward `sandboxes.snapshot_storage_max`, and an import in progress holds 16 GiB of that storage until it ends. Past either limit, the import answers `422` [`limit_exceeded`](https://docs.beta.b3os.org/errors#limit_exceeded) before anything is pulled.
|
|
146
|
+
|
|
147
|
+
A node keeps warm snapshots for at most 8 imported images. Past that, it evicts the least recently used image that no running or paused sandbox and no snapshot uses: the image turns `evicted` and its template goes. `POST` it again to import it again under the same ID. While every one of them is in use, a new import waits `queued`.
|
|
148
|
+
|
|
149
|
+
`DELETE /v1/images/{image_id}` cancels an import in progress, and nothing of it stays. A ready image is deleted with its template and warm snapshot, except while a running or paused sandbox or a snapshot uses it: then the answer is `409` [`image_in_use`](https://docs.beta.b3os.org/errors#image_in_use).
|
|
150
|
+
|
|
151
|
+
An import's CPU, in the builder and while the warm snapshot is taken, is metered as `images.import_vcpu_ms`. A rebuild after a B3OS update is not.
|
|
152
|
+
|
|
153
|
+
## Random state
|
|
154
|
+
|
|
155
|
+
Every sandbox from an image starts from a copy of the image's warm snapshot. The warm-up's commands run to their end before the snapshot, so it holds no process of yours with random state to share. Each sandbox gets fresh kernel entropy and an identity of its own, as from a template ([random state on restore and fork](https://docs.beta.b3os.org/sandboxes/snapshots#random-state-on-restore-and-fork)). The warm snapshot belongs to one project, so nothing crosses projects.
|
|
156
|
+
|
|
157
|
+
## Updates to the node
|
|
158
|
+
|
|
159
|
+
When B3OS updates the guest agent, the guest kernel or the image support files, each image's warm snapshot is taken again in the background. The image is `rebuilding` until then, and a create from it answers `409` [`image_not_ready`](https://docs.beta.b3os.org/errors#image_not_ready). Sandboxes already running keep running. A rebuild that fails turns the image `failed`, at stage `rebuild`; its root file system and the snapshots taken from it stay, and the node tries it again at its next start.
|
|
160
|
+
|
|
161
|
+
## Not in this version
|
|
162
|
+
|
|
163
|
+
- Private registries and registry credentials (an `auth` field is a `400` today).
|
|
164
|
+
- Building an image from a Dockerfile.
|
|
165
|
+
- A warm-up that keeps a process running into the snapshot (`warmup.start`), and images for hosted tools.
|
|
166
|
+
- Platforms other than `linux/amd64`.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Sandbox limits and FAQ
|
|
2
|
+
|
|
3
|
+
> Concurrency, size and lifetime limits for sandboxes in the beta, per-request caps for commands and files, retention, and common questions.
|
|
4
|
+
|
|
5
|
+
Source: https://docs.beta.b3os.org/sandboxes/limits.md
|
|
6
|
+
|
|
7
|
+
## Limits
|
|
8
|
+
|
|
9
|
+
Per organization, beta defaults. `GET /v1/limits` shows yours with current usage.
|
|
10
|
+
|
|
11
|
+
Note:
|
|
12
|
+
Where B3 sets one of these limits for your organization, above or below the default, `GET /v1/limits` shows your value, and which node runs your sandboxes decides whether it applies:
|
|
13
|
+
|
|
14
|
+
- **Node n2**, from its release of 2026-11-25: your organization's value applies to creates, forks and every child of a [swarm](https://docs.beta.b3os.org/sandboxes/swarms), and to the size, timeout, snapshot, lease and volume checks. A refusal's `limit` member names that value. `sandboxes.memory_max` and `sandboxes.volume_max` can be lowered for an organization, never raised above the default.
|
|
15
|
+
- **Node n1**, until its next release: every organization gets the defaults below, whatever `GET /v1/limits` shows.
|
|
16
|
+
|
|
17
|
+
| Limit | Default |
|
|
18
|
+
|---|---|
|
|
19
|
+
| Sandboxes at once (`sandboxes.concurrent`) | 10 |
|
|
20
|
+
| vCPUs per sandbox (`sandboxes.vcpu_max`) | 2 |
|
|
21
|
+
| Memory per sandbox (`sandboxes.memory_max`) | 4096 MiB, a deployed service's included |
|
|
22
|
+
| Disk per sandbox (`sandboxes.disk_max`) | 16 GiB, and in v0.1 no more than the template's own disk |
|
|
23
|
+
| Longest `timeout_s` (`sandboxes.timeout_max`) | 3,600 seconds |
|
|
24
|
+
| Leases per organization on a node (`sandboxes.leases_max`) | 5: sandboxes the node keeps running past `sandboxes.timeout_max` on its own ([keep a sandbox running](#faq)) |
|
|
25
|
+
| How far ahead a lease is renewed (`sandboxes.lease_term`) | 900 seconds: the node moves a leased sandbox's `expires_at` this far ahead whenever less than half is left, so a sandbox outlives the end of its lease by at most this |
|
|
26
|
+
| Snapshots kept per organization on a node (`sandboxes.snapshots_max`) | 20 |
|
|
27
|
+
| Snapshot storage per organization on a node (`sandboxes.snapshot_storage_max`) | 40 GiB; each snapshot counts its sandbox's memory plus its disk size |
|
|
28
|
+
| Disks of running and paused sandboxes per organization on a node (`sandboxes.disk_total_max`) | The concurrency limit times the largest disk (10 × 16 GiB), so a create the concurrency limit allows is never refused by it |
|
|
29
|
+
| New warm images for sizes outside a template's size classes (`sandboxes.offclass_builds`) | 4 per organization, node and hour |
|
|
30
|
+
| Root file system of one imported image (`images.rootfs_max`) | 16 GiB |
|
|
31
|
+
| Image imports at once per organization (`images.imports.concurrent`) | 1; more wait in the queue, two per node |
|
|
32
|
+
| Layers per imported image (`images.layers_max`) | 128 |
|
|
33
|
+
|
|
34
|
+
An imported image ([images](https://docs.beta.b3os.org/sandboxes/images), behind a preview flag) counts as one snapshot, and its root file system plus its warm snapshot's memory count as snapshot storage. The two snapshot limits and the disk total count on each node separately. A snapshot past either snapshot limit, or a create past the disk total, fails with `422 limit_exceeded`, its `limit` naming which. A create at a size outside the template's size classes needs a warm image of that size; past 4 new ones in an hour it answers `429` [`rate_limited`](https://docs.beta.b3os.org/errors#rate_limited) with `Retry-After`, and sizes that already have one are never refused.
|
|
35
|
+
|
|
36
|
+
The first create in a size that has no warm image on its node yet waits while the node builds one, and the build takes longer the more memory the size has: on node n2, quiet, on 2026-11-25, it took 16.6 s at 2560 MiB and 22.2 s at 3584 MiB (a size's memory is the request's, rounded up to 128 MiB or a multiple of 256 MiB). Creates after it in that size start at once. From each node's next release, the node also builds warm images in the background once it is up, for the sizes creates name most. Node n2 builds all of them: 1 vCPU with `memory_mib` 128, 1024 or 2048 on `base`, and 512 or 2048 on `code-interpreter`. Node n1 builds the three smallest (128 and 1024 on `base`, 512 on `code-interpreter`), and builds the other two on their first create. They never count toward your organization's 4 an hour. A first build that still fails answers `503` [`capacity_unavailable`](https://docs.beta.b3os.org/errors#capacity_unavailable) with `Retry-After` and says so: retry, or pick a size class or one of those sizes.
|
|
37
|
+
|
|
38
|
+
Recorded from production: a create with `timeout_s` 7200 is refused before any sandbox is made, and the answer names the limit.
|
|
39
|
+
|
|
40
|
+
**Response 422**
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"type": "https://docs.beta.b3os.org/errors#limit_exceeded",
|
|
45
|
+
"title": "Limit exceeded",
|
|
46
|
+
"status": 422,
|
|
47
|
+
"code": "limit_exceeded",
|
|
48
|
+
"detail": "timeout_s is 7200; sandboxes in this plan run at most 3600 s",
|
|
49
|
+
"instance": "req_01m6q3nafc51cf479h43807h11",
|
|
50
|
+
"limit": {
|
|
51
|
+
"id": "sandboxes.timeout_max",
|
|
52
|
+
"limit": 3600,
|
|
53
|
+
"unit": "seconds"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Request**
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
curl -s -X POST 'https://beta-api.b3os.org/v1/sandboxes' \
|
|
62
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
63
|
+
-H 'content-type: application/json' \
|
|
64
|
+
-d '{"template":"base","timeout_s":7200,"metadata":{"gallery":"docs"}}'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Server-Timing**
|
|
68
|
+
|
|
69
|
+
```http
|
|
70
|
+
server-timing: edge_auth;dur=0.000, edge_upstream;dur=11.000, total;dur=0.200
|
|
71
|
+
x-request-id: req_01m6q3nafc51cf479h43807h11
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
<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/limit-timeout`.</sub>
|
|
75
|
+
|
|
76
|
+
Per request:
|
|
77
|
+
|
|
78
|
+
| Request | Limit |
|
|
79
|
+
|---|---|
|
|
80
|
+
| Buffered `exec` | 60 seconds; up to 1 MiB of stdout and of stderr returned |
|
|
81
|
+
| Streamed or background `exec` | Up to an hour |
|
|
82
|
+
| `exec` stdin | 1 MiB |
|
|
83
|
+
| `run_code` | 60 seconds; code up to 1 MiB |
|
|
84
|
+
| File read or write | 64 MiB per request |
|
|
85
|
+
| Ports | 8 per sandbox |
|
|
86
|
+
| A preview's response starting | Within the port's `first_byte_s`: 65 seconds by default, 5 to 95 ([slow responses](https://docs.beta.b3os.org/sandboxes/ports#slow-responses)) |
|
|
87
|
+
| Private port URL | Valid from one minute to 24 hours, 10 minutes by default |
|
|
88
|
+
| `env`, `secrets` | 256 and 64 variables |
|
|
89
|
+
| Terminal, logs stream | Up to an hour per connection |
|
|
90
|
+
| Forks in one call | 1 to 10 |
|
|
91
|
+
| Outbound connections open at once | 512 per sandbox |
|
|
92
|
+
| DNS queries in flight | 64 per sandbox |
|
|
93
|
+
|
|
94
|
+
## Retention
|
|
95
|
+
|
|
96
|
+
Stopped sandboxes stay listed for 7 days with their final usage. Snapshots are kept for 7 days. A sandbox paused by `on_idle: "pause"` is kept paused for one hour, then stopped; extend its timeout and resume it within that hour to keep it.
|
|
97
|
+
|
|
98
|
+
## Fixed in the beta
|
|
99
|
+
|
|
100
|
+
No request field changes these in the beta.
|
|
101
|
+
|
|
102
|
+
- [**Paused sandboxes**](https://docs.beta.b3os.org/sandboxes/settings#paused-sandboxes): Kept 1 hour. A sandbox paused by `on_idle: pause` is stopped an hour after it paused. Snapshots are kept 7 days.
|
|
103
|
+
- [**The model variable**](https://docs.beta.b3os.org/sandboxes/settings#the-model-variable): Set with infer:run. A sandbox whose grant includes `infer:run` gets `B3OS_MODEL`, the node's default model, beside `OPENAI_BASE_URL` and `ANTHROPIC_BASE_URL` pointing at the node. A value you set in `env` wins. The node sets the model, and no request field changes it.
|
|
104
|
+
- [**Connections per sandbox**](https://docs.beta.b3os.org/sandboxes/settings#connections-per-sandbox): 512 open, 64 DNS lookups. A sandbox may have 512 outbound connections open and 64 DNS queries in flight. More connections are refused; more queries are answered `SERVFAIL` at once.
|
|
105
|
+
|
|
106
|
+
## FAQ
|
|
107
|
+
|
|
108
|
+
**Does a sandbox have internet access?**
|
|
109
|
+
|
|
110
|
+
Yes, to public IPv4 addresses by default, through the node's egress guard. Narrow it with `egress: {"mode": "allowlist", "allow": [...]}` or turn it off with `"deny"`. A sandbox never reaches the node's network, loopback or cloud metadata.
|
|
111
|
+
**Can code in my sandbox read its secrets?**
|
|
112
|
+
|
|
113
|
+
Yes. `secrets` are environment variables: the API never returns them and B3OS never logs them, but every process in the VM can read them. That is why putting a vault connection into `secrets` needs the scope `vault:connections:reveal`, which no default key holds, and why a connection bound to `hosts` (every pack connection) is refused there. To use a credential without it entering the sandbox, store it in the [vault](https://docs.beta.b3os.org/vault) and call a marketplace action, which gets the credential at the egress proxy.
|
|
114
|
+
**What happens to my sandboxes when the node restarts?**
|
|
115
|
+
|
|
116
|
+
They keep running. Their microVMs run outside the node's B3OS service, and the service that starts next takes over every running and paused sandbox. A reboot of the node itself ends them as `failed`, with their memory and disk lost; snapshots are kept, so snapshot a sandbox whose state you need.
|
|
117
|
+
**Can a sandbox run longer than an hour?**
|
|
118
|
+
|
|
119
|
+
Yes, under a lease. `PUT /v1/sandboxes/{sandbox_id}/lease` with a `key` of your choosing tells the node to keep the sandbox running: whenever less than half of `sandboxes.lease_term` (900 s) is left before `expires_at`, the node moves `expires_at` to 900 s from then, with no call from you. One live sandbox in a project holds a key at a time, so holding the key on a new sandbox ends the old one's lease, and the old sandbox stops within 900 s. The lease ends when you release it (`DELETE …/lease`; the sandbox runs out its current expiry), when the sandbox stops, or when your organization's credits or a spend cap stop it, as they stop any running sandbox. A paused sandbox is not renewed. A sandbox's own credential (the one its in-VM API holds) cannot hold a lease; a real API key you put into a sandbox can, as from anywhere, within `sandboxes.leases_max` and your credits. A leased sandbox is billed like any running one, on `sandboxes.vcpu_ms` and `sandboxes.gib_ms`. `b3os apply` holds one for each deployed service ([how long a service lives](https://docs.beta.b3os.org/design/b3os-yaml#version-1-draft-deploy-with-b3os-apply)).
|
|
120
|
+
**What happens when the timeout passes?**
|
|
121
|
+
|
|
122
|
+
With `on_idle: "stop"` (the default) the sandbox is destroyed, memory and disk included. With `on_idle: "pause"` it is paused instead, so you can extend the timeout and resume it. Extend a running sandbox at any time with `POST /v1/sandboxes/{sandbox_id}/timeout`.
|
|
123
|
+
**How do I keep a sandbox's state for later?**
|
|
124
|
+
|
|
125
|
+
Take a [snapshot](https://docs.beta.b3os.org/sandboxes/snapshots) and create sandboxes from it. Snapshots are kept for 7 days in the beta.
|
|
126
|
+
**Is my sandbox isolated from other customers?**
|
|
127
|
+
|
|
128
|
+
Each sandbox is a Firecracker microVM with its own kernel, and every start gives it fresh kernel entropy, a new machine ID and the current time; processes that a template, snapshot or fork carries over, yours or B3OS's (Chrome, in the `browser` template), keep their memory, random state included, apart from what B3OS reseeds in the code kernel and, on an image of the `browser` template built with the reset, Chrome ([what a restore or fork keeps](https://docs.beta.b3os.org/sandboxes/snapshots#what-a-restore-or-fork-keeps)). Its traffic leaves through the egress guard, and its calls to B3OS run with only the scopes you granted it. Sandboxes on one node share CPU cores, caches and the storage path, so cooperating code in two sandboxes can signal each other through timing even when both have egress `deny`; see [what egress does not close](https://docs.beta.b3os.org/sandboxes#what-egress-does-not-close).
|
|
129
|
+
**Why does a call from my sandbox return 421 edge_only?**
|
|
130
|
+
|
|
131
|
+
Account operations (keys, usage, limits, organizations, projects, the pack registry) live at `https://beta-api.b3os.org`, not on the node. Call them there with a key.
|
|
132
|
+
**Can I get a shell?**
|
|
133
|
+
|
|
134
|
+
Yes: the terminal WebSocket at `GET /v1/sandboxes/{sandbox_id}/pty`, or `b3os sandbox shell` from the CLI.
|
|
135
|
+
**Can sandboxes use GPUs?**
|
|
136
|
+
|
|
137
|
+
Not in v0.1. A GPU tier is planned.
|
|
138
|
+
**What does guest_unreachable mean?**
|
|
139
|
+
|
|
140
|
+
The agent inside the microVM did not answer (`502`), usually because the guest hung or ran out of memory. Retry once; if it repeats, delete the sandbox and create a new one, with more memory if the workload needs it.
|
|
141
|
+
**Why was my snapshot or fork refused with 503?**
|
|
142
|
+
|
|
143
|
+
The node's snapshot store is nearly full, and snapshots and forks wait until it has room again ([`capacity_unavailable`](https://docs.beta.b3os.org/errors#capacity_unavailable), with `Retry-After`). A `422` [`limit_exceeded`](https://docs.beta.b3os.org/errors#limit_exceeded) instead means your organization reached its own snapshot count or storage on this node: delete snapshots you no longer need.
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Ports and previews
|
|
2
|
+
|
|
3
|
+
> Reach a server in a sandbox through the port's own host on b3os.io, where it runs at the root and keeps its cookies, or through a signed preview URL.
|
|
4
|
+
|
|
5
|
+
Source: https://docs.beta.b3os.org/sandboxes/ports.md
|
|
6
|
+
|
|
7
|
+
A server in a sandbox is reachable from outside only on ports you declare when you create the sandbox: through the port's [own host](#a-ports-own-host) on `b3os.io`, where the app runs at `/` and keeps its cookies, or through a preview URL on `usercontent.b3os.org`. Ports 53, 1080, 3128, 7700 and 15001 cannot be declared: B3OS's agent in the sandbox uses them. Once addresses are on for its organization, an application you deploy with `b3os apply` gets an address on `b3os.io` for each port that asks for one instead, at the root of its own origin and the same across deploys: [App addresses](https://docs.beta.b3os.org/platform/addresses).
|
|
8
|
+
|
|
9
|
+
## Declare ports
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{ "template": "base", "ports": [{ "port": 3000 }, { "port": 8080, "public": true }] }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Up to 8 ports, declared when you create the sandbox. A port may also say how long its preview waits for a response to start (`first_byte_s`, [below](#slow-responses)). A port you did not declare answers [`port_not_exposed`](https://docs.beta.b3os.org/errors#port_not_exposed); to reach another one, create a sandbox with it in `ports`.
|
|
16
|
+
|
|
17
|
+
## A port's own host
|
|
18
|
+
|
|
19
|
+
For an app that needs the root path or a sign-in cookie, give the port its own host: `https://<port>-sbx-<id>.b3os.io`, where `<id>` is the sandbox ID without `sbx_`. The app runs at `/` on an origin of its own and keeps the cookies it sets, under the rules of an [app address](https://docs.beta.b3os.org/platform/addresses#cookies). In the console, it is Own host on the sandbox's Ports tab.
|
|
20
|
+
|
|
21
|
+
Note:
|
|
22
|
+
The SDK methods for it (`b3os.sandboxes.createPortHost`, `create_port_host` and a handle's `ports.host`) come with SDK
|
|
23
|
+
0.2.2, the **next** release. Until then, call the HTTP API as the curl example does.
|
|
24
|
+
|
|
25
|
+
**curl**
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
curl -s -X POST "https://beta-api.b3os.org/v1/sandboxes/$SBX/ports/3000/host" \
|
|
29
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
30
|
+
-H "Content-Type: application/json" \
|
|
31
|
+
-d '{"ttl_s": 600}'
|
|
32
|
+
```
|
|
33
|
+
**TypeScript**
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const h = await b3os.sandboxes.createPortHost(sbx, 3000, { ttl_s: 600 });
|
|
37
|
+
console.log(h.host); // safe to show; h.url is a link to share like a password
|
|
38
|
+
```
|
|
39
|
+
**Python**
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
h = b3os.sandboxes.create_port_host(sbx, 3000, {"ttl_s": 600})
|
|
43
|
+
print(h["host"]) # safe to show; h["url"] is a link to share like a password
|
|
44
|
+
```
|
|
45
|
+
**MCP**
|
|
46
|
+
|
|
47
|
+
```text
|
|
48
|
+
Start the dev server in my sandbox on port 3000 and give it its own host.
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The agent starts the server with `sandbox_exec` (`background: true`) and asks for the host with `sandbox_port_host`, in the `sandboxes` toolset: start the local server with `npx -y @b3os/mcp@0.2 --toolsets sandboxes`, or connect to the remote one at `https://beta-api.b3os.org/mcp?toolsets=sandboxes`.
|
|
52
|
+
|
|
53
|
+
With a `Sandbox` handle it is `sbx.ports.host(3000)`. The answer:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"object": "port_host",
|
|
58
|
+
"sandbox_id": "sbx_01m5t68q1b590rj801nbzsqzkk",
|
|
59
|
+
"port": 3000,
|
|
60
|
+
"host": "3000-sbx-01m5t68q1b590rj801nbzsqzkk.b3os.io",
|
|
61
|
+
"url": "https://3000-sbx-01m5t68q1b590rj801nbzsqzkk.b3os.io/?b3os_link=<token>",
|
|
62
|
+
"expires_at": "2026-11-17T19:10:00.000Z",
|
|
63
|
+
"rotated": false,
|
|
64
|
+
"cookies": { "mode": "isolated", "script": [] }
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- A host is shared by link, never public. The link works for `ttl_s` seconds (600 by default, at most 86400); its first page load sets a cookie, and that browser stays in for 24 hours. A script sends the token, the part after `b3os_link=`, in an `x-b3os-link` header. Anyone else gets [`401 app_link_required`](https://docs.beta.b3os.org/errors#app_link_required), the same page whether or not the sandbox exists.
|
|
69
|
+
- Each call returns a new link, and earlier ones keep working. `"rotate": true` first replaces the host's secret: every earlier link, and every browser one let in, stops working within 6 seconds.
|
|
70
|
+
- `cookies` sets the host's cookie rule, `isolated` by default. A sign-in library that writes its cookie from page script needs that cookie's name under `script`, for example `{"mode": "isolated", "script": ["sb-<project-ref>-auth-token"]}`. Left out, the host keeps the rule it has.
|
|
71
|
+
- The port must be declared and the sandbox running or paused. While the sandbox is paused or stopped its host answers `503`; once it resumes the host serves again within seconds, and visitors stay signed in. The host is that sandbox's and that port's, and ends with the sandbox: a fork or a restore has a new ID, so new hosts.
|
|
72
|
+
- A host with no call for 49 hours is forgotten. The next call makes it again with a new secret, so older links stop working.
|
|
73
|
+
- An organization can ask for links 60 times a minute, across all its sandboxes and wherever the calls come from: one count for the organization, over a sliding minute (a burst across the turn of a minute can get a few more). Past that the call answers [`429 rate_limited`](https://docs.beta.b3os.org/errors#rate_limited) with `Retry-After`.
|
|
74
|
+
- Hosts count toward no address limit. One client gets 3,000 requests a minute across all sandbox hosts, counted at each Cloudflare location (a dev server loads one file per module). A sandbox serves at most 256 requests at once through its hosts and addresses, 64 of them from one client.
|
|
75
|
+
- Preview URLs keep working as before, and a port can have both.
|
|
76
|
+
|
|
77
|
+
What the app sees on its host:
|
|
78
|
+
|
|
79
|
+
- `Host` is the host, the path is the request's whole path with no prefix, and there is no `X-Forwarded-Prefix`.
|
|
80
|
+
- A dev server that checks `Host` must allow it, or it answers its own "Blocked request" page. For Vite: `server.allowedHosts: ['.b3os.io']`. Inside the sandbox the host is `<port>-sbx-` followed by `$B3OS_SANDBOX_ID` without `sbx_`, then `.b3os.io`; B3OS does not put it in the environment yet.
|
|
81
|
+
- The response rules of an address apply: `Clear-Site-Data` loses `"cookies"`, B3OS adds `Strict-Transport-Security` and `Origin-Agent-Cluster` when the app sends neither, an HTML answer with no framing rule of its own may be framed only by the sandbox's own hosts, and every answer says `X-Robots-Tag: noindex`.
|
|
82
|
+
- A request the network in front of B3OS refuses before it reaches the app, such as a path scanners probe (`/.env`, `/.git/config`), answers [`403 app_request_refused`](https://docs.beta.b3os.org/errors#app_request_refused) on the host, with no `Retry-After`: sending it again does not help.
|
|
83
|
+
|
|
84
|
+
Not yet: code inside a sandbox cannot ask for a host (its API at `127.0.0.1:7700` answers `421 edge_only`), so ask with a key from outside. Visits show in your requests with source `address`, as an application's do.
|
|
85
|
+
|
|
86
|
+
| Code | Status | When |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| [`port_not_exposed`](https://docs.beta.b3os.org/errors#port_not_exposed) | 404 | The port was not declared when the sandbox was created |
|
|
89
|
+
| [`sandbox_not_found`](https://docs.beta.b3os.org/errors#sandbox_not_found) | 404 | No sandbox with this ID in your project |
|
|
90
|
+
| [`sandbox_not_running`](https://docs.beta.b3os.org/errors#sandbox_not_running) | 409 | The sandbox is stopped |
|
|
91
|
+
| [`invalid_request`](https://docs.beta.b3os.org/errors#invalid_request) | 400 | Port 49983, which is kept for E2B's envd, or a body out of range |
|
|
92
|
+
| [`app_host_blocked`](https://docs.beta.b3os.org/errors#app_host_blocked) | 403 | B3 took the sandbox's hosts offline; their visitors get `410` |
|
|
93
|
+
|
|
94
|
+
## Private ports
|
|
95
|
+
|
|
96
|
+
A port is private by default: nobody reaches it without a URL you mint for it. Ask for one when you need it:
|
|
97
|
+
|
|
98
|
+
**curl**
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
curl -s -X POST "https://beta-api.b3os.org/v1/sandboxes/$SBX/ports/3000/url" \
|
|
102
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
103
|
+
-H "Content-Type: application/json" \
|
|
104
|
+
-d '{"ttl_s": 600}'
|
|
105
|
+
```
|
|
106
|
+
**TypeScript**
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
const preview = await b3os.sandboxes.createPortUrl(sbx, 3000, { ttl_s: 600 });
|
|
110
|
+
console.log(preview.url, preview.expires_at);
|
|
111
|
+
```
|
|
112
|
+
**Python**
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
preview = b3os.sandboxes.create_port_url(sbx, 3000, {"ttl_s": 600})
|
|
116
|
+
print(preview["url"], preview["expires_at"])
|
|
117
|
+
```
|
|
118
|
+
**MCP**
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
Start the dev server in my sandbox on port 3000 in the background and give me a preview URL for it.
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The agent starts the server with `sandbox_exec` (`background: true`) and mints the URL with `sandbox_port_url`. `sandbox_port_url` is in the `sandboxes` toolset: start the local server with `npx -y @b3os/mcp@0.2 --toolsets sandboxes`, or connect to the remote one at `https://beta-api.b3os.org/mcp?toolsets=sandboxes`.
|
|
125
|
+
|
|
126
|
+
Recorded from production with `ttl_s` 60; the capture redacts the token in the URL:
|
|
127
|
+
|
|
128
|
+
**Response 200**
|
|
129
|
+
|
|
130
|
+
```json
|
|
131
|
+
{
|
|
132
|
+
"expires_at": "2026-11-06T00:21:43.000Z",
|
|
133
|
+
"object": "port_url",
|
|
134
|
+
"port": 3000,
|
|
135
|
+
"public": false,
|
|
136
|
+
"url": "https://usercontent.b3os.org/sbx/sbx-01m6q3naemvk1zxgst0992ejrr/3000/[redacted:port_token]/"
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Request**
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
curl -s -X POST 'https://beta-api.b3os.org/v1/sandboxes/sbx_01m6q3naemvk1zxgst0992ejrr/ports/3000/url' \
|
|
144
|
+
-H "Authorization: Bearer $B3OS_API_KEY" \
|
|
145
|
+
-H 'content-type: application/json' \
|
|
146
|
+
-d '{"ttl_s":60}'
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Server-Timing**
|
|
150
|
+
|
|
151
|
+
```http
|
|
152
|
+
server-timing: edge_auth;dur=0.000, edge_upstream;dur=11.000, total;dur=0.141
|
|
153
|
+
x-request-id: req_01m6q3nbnvrfxbcfv18qm2d189
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
<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/port-url`.</sub>
|
|
157
|
+
|
|
158
|
+
The token in the path is signed by the node and expires after `ttl_s` (10 minutes by default, from one minute to 24 hours). Anyone with the URL reaches the port until then, with no cookie or other credential, so share it like a password.
|
|
159
|
+
|
|
160
|
+
Render recorded this server through its preview URL while the button ran commands in the sandbox.
|
|
161
|
+
|
|
162
|
+
[Open the video](https://beta.b3os.org/gallery/recipes/sandbox-port-video/be14256a18c59ebe.mp4) · [Captions (WebVTT)](https://beta.b3os.org/gallery/recipes/sandbox-port-video/1e5d2ea791f43fa5.vtt)
|
|
163
|
+
|
|
164
|
+
<details>
|
|
165
|
+
<summary>Transcript</summary>
|
|
166
|
+
|
|
167
|
+
`0:00` This page is served from a port inside a sandbox.
|
|
168
|
+
|
|
169
|
+
`0:04` Press the button, and the server runs commands in the VM.
|
|
170
|
+
|
|
171
|
+
`0:08` The output comes back through the same preview URL.
|
|
172
|
+
|
|
173
|
+
</details>
|
|
174
|
+
|
|
175
|
+
<sub>Captured 2026-11-14 from commit `aa0a5dfa` on the host the node runs on, one run, label `live-recorded` (recorded from production). Case `recipes/sandbox-port-video`.</sub>
|
|
176
|
+
|
|
177
|
+
## Public ports
|
|
178
|
+
|
|
179
|
+
A port declared `public: true` gets a long-lived URL in the sandbox's `ports[].url`, ready as soon as the sandbox is. Its token lasts 7 days from the sandbox's creation, so the URL stays fixed; a sandbox that runs longer gets a new one.
|
|
180
|
+
|
|
181
|
+
## What your server sees
|
|
182
|
+
|
|
183
|
+
The preview forwards `GET` (WebSocket upgrades included), `HEAD`, `POST`, `PUT`, `PATCH`, `DELETE` and `OPTIONS`; other methods get `405`. Your server receives the request at the path after the token, with the query string unchanged, plus these headers:
|
|
184
|
+
|
|
185
|
+
| Header | Value |
|
|
186
|
+
|---|---|
|
|
187
|
+
| `X-Forwarded-Proto` | `https` |
|
|
188
|
+
| `X-Forwarded-Host` | `usercontent.b3os.org` |
|
|
189
|
+
| `X-Forwarded-Prefix` | `/sbx/<host_id>/<port>/<token>`, the full base path of this request |
|
|
190
|
+
|
|
191
|
+
Cookies are removed in both directions, as everywhere on `usercontent.b3os.org` (an [address](https://docs.beta.b3os.org/platform/addresses#cookies) keeps them). So are two response headers that would reach past the preview's own path on the shared origin, `Service-Worker-Allowed` and `Clear-Site-Data`. Unless your server sets `Referrer-Policy`, the preview adds `Referrer-Policy: strict-origin`, so the token in the path does not leak to other sites. A response must start within the port's `first_byte_s`, 65 seconds unless you declare more ([slow responses](#slow-responses)); a WebSocket or a streamed body can stay open up to an hour. Taking a snapshot or a fork of the sandbox resets open preview connections.
|
|
192
|
+
|
|
193
|
+
## Slow responses
|
|
194
|
+
|
|
195
|
+
A preview waits for your server to start its response, the status line and headers, for 65 seconds by default. Declare a longer wait per port with `first_byte_s`, from 5 to 95 seconds, when you create the sandbox:
|
|
196
|
+
|
|
197
|
+
```json
|
|
198
|
+
{ "template": "base", "ports": [{ "port": 8000, "public": true, "first_byte_s": 95 }] }
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
The wait is counted from when the node lets the request in. A request that waits longer answers [`504 upstream_first_byte_timeout`](https://docs.beta.b3os.org/errors#upstream_first_byte_timeout), and its detail names the limit. A response that has started can stream for up to an hour. The ceiling is 95 seconds because the proxy in front of the node gives up on a response that has not started after 100 seconds, so a longer wait would end in that proxy's error instead of this one.
|
|
202
|
+
|
|
203
|
+
Work that takes minutes, such as an agent that researches before it answers, needs one of two shapes instead:
|
|
204
|
+
|
|
205
|
+
- **Stream the answer.** Send the status and headers at once, then the body as it is ready: server-sent events, or the result in chunks.
|
|
206
|
+
- **Start, then poll.** Answer at once with an ID, run the work in the background, and let the client ask for the result.
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
# FastAPI: POST starts the work and answers with an ID at once; GET returns the result when it is ready.
|
|
210
|
+
import asyncio
|
|
211
|
+
import uuid
|
|
212
|
+
|
|
213
|
+
from fastapi import FastAPI
|
|
214
|
+
|
|
215
|
+
app = FastAPI()
|
|
216
|
+
jobs: dict[str, dict] = {}
|
|
217
|
+
running: set[asyncio.Task] = set()
|
|
218
|
+
|
|
219
|
+
async def research(query: str) -> str:
|
|
220
|
+
await asyncio.sleep(300) # minutes of work
|
|
221
|
+
return f"a report on {query}"
|
|
222
|
+
|
|
223
|
+
@app.post("/report")
|
|
224
|
+
async def start(body: dict) -> dict:
|
|
225
|
+
job = uuid.uuid4().hex
|
|
226
|
+
jobs[job] = {"status": "running"}
|
|
227
|
+
|
|
228
|
+
async def run() -> None:
|
|
229
|
+
jobs[job] = {"status": "done", "report": await research(body["query"])}
|
|
230
|
+
|
|
231
|
+
task = asyncio.create_task(run())
|
|
232
|
+
running.add(task)
|
|
233
|
+
task.add_done_callback(running.discard)
|
|
234
|
+
return {"id": job, "status": "running"}
|
|
235
|
+
|
|
236
|
+
@app.get("/report/{job}")
|
|
237
|
+
async def result(job: str) -> dict:
|
|
238
|
+
return jobs.get(job, {"status": "unknown"})
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Base paths
|
|
242
|
+
|
|
243
|
+
A preview serves your app under a path prefix, not at the root of a domain (a port's [own host](#a-ports-own-host) and an [address](https://docs.beta.b3os.org/platform/addresses) serve it at the root). Two rules keep links working:
|
|
244
|
+
|
|
245
|
+
- Emit relative URLs where you can. A URL that ends at the token redirects to the same URL plus `/`, so relative links resolve under the prefix.
|
|
246
|
+
- For absolute paths, build them from `X-Forwarded-Prefix` on each request. `B3OS_PORT_BASE_PATH` in the sandbox's environment is only the fixed start, `/sbx/<host_id>`, because the port and the token follow it and the token differs for every minted URL.
|
|
247
|
+
|
|
248
|
+
Warning:
|
|
249
|
+
Every preview URL shares the `usercontent.b3os.org` origin. A page served from one preview can send requests to any other preview URL it knows. Keep secrets out of previews. A port's [own host](#a-ports-own-host) and a deployed application's [addresses](https://docs.beta.b3os.org/platform/addresses) each have an origin of their own, with the limits of a [shared domain](https://docs.beta.b3os.org/platform/addresses#shared-domain-limits).
|
|
250
|
+
|
|
251
|
+
## When it fails
|
|
252
|
+
|
|
253
|
+
| Code | Status | When |
|
|
254
|
+
|---|---|---|
|
|
255
|
+
| [`signed_url_invalid`](https://docs.beta.b3os.org/errors#signed_url_invalid) | 403 | The token is malformed, expired, or for another sandbox or port |
|
|
256
|
+
| [`port_not_exposed`](https://docs.beta.b3os.org/errors#port_not_exposed) | 404 | The port was not declared when the sandbox was created |
|
|
257
|
+
| [`sandbox_not_running`](https://docs.beta.b3os.org/errors#sandbox_not_running) | 409 | The sandbox is paused or stopped |
|
|
258
|
+
| [`upstream_unreachable`](https://docs.beta.b3os.org/errors#upstream_unreachable) | 502 | Nothing in the sandbox accepted a connection on the port |
|
|
259
|
+
| [`upstream_first_byte_timeout`](https://docs.beta.b3os.org/errors#upstream_first_byte_timeout) | 504 | The app did not start its response within the port's `first_byte_s` (65 seconds by default) |
|
|
260
|
+
| [`guest_unreachable`](https://docs.beta.b3os.org/errors#guest_unreachable) | 502 | The agent inside the microVM did not answer |
|