@b3os/sdk 0.0.1 → 0.1.3
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 +171 -42
- package/dist/cjs/core/bytes.d.ts +30 -0
- package/dist/cjs/core/bytes.js +115 -0
- package/dist/cjs/core/bytes.js.map +1 -0
- package/dist/cjs/core/client.d.ts +61 -3
- package/dist/cjs/core/client.js +211 -33
- package/dist/cjs/core/client.js.map +1 -1
- package/dist/cjs/core/errors.d.ts +16 -4
- package/dist/cjs/core/errors.js +9 -6
- package/dist/cjs/core/errors.js.map +1 -1
- package/dist/cjs/core/handle.d.ts +31 -0
- package/dist/cjs/core/handle.js +86 -0
- package/dist/cjs/core/handle.js.map +1 -0
- package/dist/cjs/core/index.d.ts +6 -4
- package/dist/cjs/core/index.js +8 -1
- package/dist/cjs/core/index.js.map +1 -1
- package/dist/cjs/core/login.d.ts +24 -0
- package/dist/cjs/core/login.js +93 -0
- package/dist/cjs/core/login.js.map +1 -0
- package/dist/cjs/core/namespace.d.ts +1 -1
- package/dist/cjs/core/namespace.js +1 -1
- package/dist/cjs/core/op.d.ts +11 -1
- package/dist/cjs/core/timing.d.ts +1 -1
- package/dist/cjs/core/timing.js +8 -1
- package/dist/cjs/core/timing.js.map +1 -1
- package/dist/cjs/core/transport.js +1 -1
- package/dist/cjs/core/transport.js.map +1 -1
- package/dist/cjs/core/util.d.ts +15 -3
- package/dist/cjs/core/util.js +54 -2
- package/dist/cjs/core/util.js.map +1 -1
- package/dist/cjs/core/ws.d.ts +4 -0
- package/dist/cjs/core/ws.js +7 -4
- package/dist/cjs/core/ws.js.map +1 -1
- package/dist/cjs/generated/client.d.ts +2 -2
- package/dist/cjs/generated/client.js +2 -2
- package/dist/cjs/generated/errors.d.ts +1 -1
- package/dist/cjs/generated/errors.js +30 -0
- package/dist/cjs/generated/errors.js.map +1 -1
- package/dist/cjs/generated/jobs.js +1 -1
- package/dist/cjs/generated/ns/actions.d.ts +48 -6
- package/dist/cjs/generated/ns/actions.js +59 -6
- package/dist/cjs/generated/ns/actions.js.map +1 -1
- package/dist/cjs/generated/ns/infer.d.ts +185 -54
- package/dist/cjs/generated/ns/infer.js +28 -74
- package/dist/cjs/generated/ns/infer.js.map +1 -1
- package/dist/cjs/generated/ns/keys.d.ts +12 -0
- package/dist/cjs/generated/ns/keys.js +22 -0
- package/dist/cjs/generated/ns/keys.js.map +1 -1
- package/dist/cjs/generated/ns/render.d.ts +95 -6
- package/dist/cjs/generated/ns/render.js +124 -7
- package/dist/cjs/generated/ns/render.js.map +1 -1
- package/dist/cjs/generated/ns/requests.d.ts +3 -1
- package/dist/cjs/generated/ns/requests.js +3 -1
- package/dist/cjs/generated/ns/requests.js.map +1 -1
- package/dist/cjs/generated/ns/routines.d.ts +131 -9
- package/dist/cjs/generated/ns/routines.js +186 -9
- package/dist/cjs/generated/ns/routines.js.map +1 -1
- package/dist/cjs/generated/ns/sandboxes.d.ts +298 -31
- package/dist/cjs/generated/ns/sandboxes.js +368 -29
- package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
- package/dist/cjs/generated/ns/vision.d.ts +133 -14
- package/dist/cjs/generated/ns/vision.js +158 -12
- package/dist/cjs/generated/ns/vision.js.map +1 -1
- package/dist/cjs/generated/ns/webhooks.d.ts +8 -5
- package/dist/cjs/generated/ns/webhooks.js +8 -5
- package/dist/cjs/generated/ns/webhooks.js.map +1 -1
- package/dist/cjs/generated/types.d.ts +1956 -301
- package/dist/cjs/helpers/agents.d.ts +95 -0
- package/dist/cjs/helpers/agents.js +205 -0
- package/dist/cjs/helpers/agents.js.map +1 -0
- package/dist/cjs/helpers/render.d.ts +15 -0
- package/dist/cjs/helpers/render.js +74 -0
- package/dist/cjs/helpers/render.js.map +1 -0
- package/dist/cjs/helpers/routines.d.ts +61 -0
- package/dist/cjs/helpers/routines.js +234 -0
- package/dist/cjs/helpers/routines.js.map +1 -0
- package/dist/cjs/helpers/sandboxes.d.ts +237 -0
- package/dist/cjs/helpers/sandboxes.js +608 -0
- package/dist/cjs/helpers/sandboxes.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -1
- package/dist/cjs/index.js +8 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/routines.d.ts +1 -0
- package/dist/cjs/routines.js +21 -0
- package/dist/cjs/routines.js.map +1 -0
- package/dist/cjs/webhooks.js.map +1 -1
- package/dist/esm/core/bytes.d.ts +30 -0
- package/dist/esm/core/bytes.js +111 -0
- package/dist/esm/core/bytes.js.map +1 -0
- package/dist/esm/core/client.d.ts +61 -3
- package/dist/esm/core/client.js +208 -31
- package/dist/esm/core/client.js.map +1 -1
- package/dist/esm/core/errors.d.ts +16 -4
- package/dist/esm/core/errors.js +9 -6
- package/dist/esm/core/errors.js.map +1 -1
- package/dist/esm/core/handle.d.ts +31 -0
- package/dist/esm/core/handle.js +82 -0
- package/dist/esm/core/handle.js.map +1 -0
- package/dist/esm/core/index.d.ts +6 -4
- package/dist/esm/core/index.js +4 -2
- package/dist/esm/core/index.js.map +1 -1
- package/dist/esm/core/login.d.ts +24 -0
- package/dist/esm/core/login.js +85 -0
- package/dist/esm/core/login.js.map +1 -0
- package/dist/esm/core/namespace.d.ts +1 -1
- package/dist/esm/core/namespace.js +1 -1
- package/dist/esm/core/op.d.ts +11 -1
- package/dist/esm/core/timing.d.ts +1 -1
- package/dist/esm/core/timing.js +8 -1
- package/dist/esm/core/timing.js.map +1 -1
- package/dist/esm/core/transport.js +1 -1
- package/dist/esm/core/transport.js.map +1 -1
- package/dist/esm/core/util.d.ts +15 -3
- package/dist/esm/core/util.js +48 -1
- package/dist/esm/core/util.js.map +1 -1
- package/dist/esm/core/ws.d.ts +4 -0
- package/dist/esm/core/ws.js +7 -4
- package/dist/esm/core/ws.js.map +1 -1
- package/dist/esm/generated/client.d.ts +2 -2
- package/dist/esm/generated/client.js +2 -2
- package/dist/esm/generated/errors.d.ts +1 -1
- package/dist/esm/generated/errors.js +30 -0
- package/dist/esm/generated/errors.js.map +1 -1
- package/dist/esm/generated/jobs.js +1 -1
- package/dist/esm/generated/ns/actions.d.ts +48 -6
- package/dist/esm/generated/ns/actions.js +59 -6
- package/dist/esm/generated/ns/actions.js.map +1 -1
- package/dist/esm/generated/ns/infer.d.ts +185 -54
- package/dist/esm/generated/ns/infer.js +28 -74
- package/dist/esm/generated/ns/infer.js.map +1 -1
- package/dist/esm/generated/ns/keys.d.ts +12 -0
- package/dist/esm/generated/ns/keys.js +22 -0
- package/dist/esm/generated/ns/keys.js.map +1 -1
- package/dist/esm/generated/ns/render.d.ts +95 -6
- package/dist/esm/generated/ns/render.js +124 -7
- package/dist/esm/generated/ns/render.js.map +1 -1
- package/dist/esm/generated/ns/requests.d.ts +3 -1
- package/dist/esm/generated/ns/requests.js +3 -1
- package/dist/esm/generated/ns/requests.js.map +1 -1
- package/dist/esm/generated/ns/routines.d.ts +131 -9
- package/dist/esm/generated/ns/routines.js +186 -9
- package/dist/esm/generated/ns/routines.js.map +1 -1
- package/dist/esm/generated/ns/sandboxes.d.ts +298 -31
- package/dist/esm/generated/ns/sandboxes.js +368 -29
- package/dist/esm/generated/ns/sandboxes.js.map +1 -1
- package/dist/esm/generated/ns/vision.d.ts +133 -14
- package/dist/esm/generated/ns/vision.js +158 -12
- package/dist/esm/generated/ns/vision.js.map +1 -1
- package/dist/esm/generated/ns/webhooks.d.ts +8 -5
- package/dist/esm/generated/ns/webhooks.js +8 -5
- package/dist/esm/generated/ns/webhooks.js.map +1 -1
- package/dist/esm/generated/types.d.ts +1956 -301
- package/dist/esm/helpers/agents.d.ts +95 -0
- package/dist/esm/helpers/agents.js +199 -0
- package/dist/esm/helpers/agents.js.map +1 -0
- package/dist/esm/helpers/render.d.ts +15 -0
- package/dist/esm/helpers/render.js +70 -0
- package/dist/esm/helpers/render.js.map +1 -0
- package/dist/esm/helpers/routines.d.ts +61 -0
- package/dist/esm/helpers/routines.js +226 -0
- package/dist/esm/helpers/routines.js.map +1 -0
- package/dist/esm/helpers/sandboxes.d.ts +237 -0
- package/dist/esm/helpers/sandboxes.js +600 -0
- package/dist/esm/helpers/sandboxes.js.map +1 -0
- package/dist/esm/index.d.ts +4 -1
- package/dist/esm/index.js +6 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routines.d.ts +1 -0
- package/dist/esm/routines.js +5 -0
- package/dist/esm/routines.js.map +1 -0
- package/dist/esm/webhooks.js.map +1 -1
- package/package.json +18 -7
- package/src/core/bytes.ts +112 -0
- package/src/core/client.ts +253 -33
- package/src/core/errors.ts +27 -10
- package/src/core/handle.ts +97 -0
- package/src/core/index.ts +7 -2
- package/src/core/login.ts +98 -0
- package/src/core/namespace.ts +1 -1
- package/src/core/op.ts +11 -1
- package/src/core/timing.ts +7 -2
- package/src/core/transport.ts +1 -1
- package/src/core/util.ts +53 -3
- package/src/core/ws.ts +11 -4
- package/src/generated/client.ts +2 -2
- package/src/generated/errors.ts +60 -0
- package/src/generated/jobs.ts +1 -1
- package/src/generated/ns/actions.ts +69 -6
- package/src/generated/ns/infer.ts +229 -61
- package/src/generated/ns/keys.ts +23 -0
- package/src/generated/ns/render.ts +152 -7
- package/src/generated/ns/requests.ts +3 -1
- package/src/generated/ns/routines.ts +205 -9
- package/src/generated/ns/sandboxes.ts +434 -34
- package/src/generated/ns/vision.ts +168 -14
- package/src/generated/ns/webhooks.ts +8 -5
- package/src/generated/types.ts +2211 -422
- package/src/helpers/agents.ts +300 -0
- package/src/helpers/render.ts +91 -0
- package/src/helpers/routines.ts +278 -0
- package/src/helpers/sandboxes.ts +788 -0
- package/src/index.ts +29 -5
- package/src/routines.ts +5 -0
- package/src/webhooks.ts +5 -1
|
@@ -6,12 +6,35 @@ import type { Op } from "../../core/op.ts";
|
|
|
6
6
|
import type { APIPromise, ListPromise } from "../../core/promise.ts";
|
|
7
7
|
import type { EventStream } from "../../core/sse.ts";
|
|
8
8
|
import { openSocket, PtySession, ticketedUrl } from "../../core/ws.ts";
|
|
9
|
+
import {
|
|
10
|
+
type CodexExecServerOptions,
|
|
11
|
+
type Harness,
|
|
12
|
+
launchManagedAgentsSession,
|
|
13
|
+
type ManagedAgentsSessionOptions,
|
|
14
|
+
type ManagedAgentsWorkerOptions,
|
|
15
|
+
startCodexExecServer,
|
|
16
|
+
startManagedAgentsWorker,
|
|
17
|
+
} from "../../helpers/agents.ts";
|
|
18
|
+
import {
|
|
19
|
+
createSandboxSafely,
|
|
20
|
+
type ReadyOptions,
|
|
21
|
+
type ReadyProbe,
|
|
22
|
+
type ReadyResult,
|
|
23
|
+
Sandbox,
|
|
24
|
+
type SandboxClient,
|
|
25
|
+
type SandboxCreateBody,
|
|
26
|
+
type Service,
|
|
27
|
+
type ServiceOptions,
|
|
28
|
+
startService,
|
|
29
|
+
waitUntilReady,
|
|
30
|
+
} from "../../helpers/sandboxes.ts";
|
|
9
31
|
import type * as T from "../types.ts";
|
|
10
32
|
|
|
11
33
|
const listSandboxesOp: Op = {
|
|
12
34
|
id: "sandboxesListSandboxes",
|
|
13
35
|
method: "GET",
|
|
14
36
|
path: "/v1/sandboxes",
|
|
37
|
+
deepObject: ["metadata"],
|
|
15
38
|
timeoutMs: 10000,
|
|
16
39
|
scope: "sandboxes:read",
|
|
17
40
|
};
|
|
@@ -78,21 +101,42 @@ const getSandboxOp: Op = {
|
|
|
78
101
|
timeoutMs: 10000,
|
|
79
102
|
scope: "sandboxes:read",
|
|
80
103
|
};
|
|
104
|
+
const setEgressOp: Op = {
|
|
105
|
+
id: "sandboxesSetEgress",
|
|
106
|
+
method: "POST",
|
|
107
|
+
path: "/v1/sandboxes/{sandbox_id}/egress",
|
|
108
|
+
params: ["sandbox_id"],
|
|
109
|
+
body: "json",
|
|
110
|
+
timeoutMs: 10000,
|
|
111
|
+
scope: "sandboxes:write",
|
|
112
|
+
};
|
|
81
113
|
const execOp: Op = {
|
|
82
114
|
id: "sandboxesExec",
|
|
83
115
|
method: "POST",
|
|
84
116
|
path: "/v1/sandboxes/{sandbox_id}/exec",
|
|
85
117
|
params: ["sandbox_id"],
|
|
86
118
|
body: "json",
|
|
119
|
+
idem: true,
|
|
120
|
+
callerKey: true,
|
|
87
121
|
stream: "sse",
|
|
88
122
|
timeoutMs: 3600000,
|
|
89
123
|
scope: "sandboxes:run",
|
|
90
124
|
};
|
|
125
|
+
const deleteFileOp: Op = {
|
|
126
|
+
id: "sandboxesDeleteFile",
|
|
127
|
+
method: "DELETE",
|
|
128
|
+
path: "/v1/sandboxes/{sandbox_id}/files",
|
|
129
|
+
params: ["sandbox_id"],
|
|
130
|
+
flags: ["recursive"],
|
|
131
|
+
timeoutMs: 60000,
|
|
132
|
+
scope: "sandboxes:run",
|
|
133
|
+
};
|
|
91
134
|
const readFileOp: Op = {
|
|
92
135
|
id: "sandboxesReadFile",
|
|
93
136
|
method: "GET",
|
|
94
137
|
path: "/v1/sandboxes/{sandbox_id}/files",
|
|
95
138
|
params: ["sandbox_id"],
|
|
139
|
+
flags: ["list"],
|
|
96
140
|
timeoutMs: 60000,
|
|
97
141
|
scope: "sandboxes:run",
|
|
98
142
|
};
|
|
@@ -101,11 +145,38 @@ const writeFileOp: Op = {
|
|
|
101
145
|
method: "PUT",
|
|
102
146
|
path: "/v1/sandboxes/{sandbox_id}/files",
|
|
103
147
|
params: ["sandbox_id"],
|
|
148
|
+
flags: ["mkdir"],
|
|
104
149
|
body: "bytes",
|
|
105
150
|
contentType: "application/octet-stream",
|
|
106
151
|
timeoutMs: 60000,
|
|
107
152
|
scope: "sandboxes:run",
|
|
108
153
|
};
|
|
154
|
+
const makeDirectoryOp: Op = {
|
|
155
|
+
id: "sandboxesMakeDirectory",
|
|
156
|
+
method: "POST",
|
|
157
|
+
path: "/v1/sandboxes/{sandbox_id}/files/mkdir",
|
|
158
|
+
params: ["sandbox_id"],
|
|
159
|
+
body: "json",
|
|
160
|
+
timeoutMs: 30000,
|
|
161
|
+
scope: "sandboxes:run",
|
|
162
|
+
};
|
|
163
|
+
const moveFileOp: Op = {
|
|
164
|
+
id: "sandboxesMoveFile",
|
|
165
|
+
method: "POST",
|
|
166
|
+
path: "/v1/sandboxes/{sandbox_id}/files/move",
|
|
167
|
+
params: ["sandbox_id"],
|
|
168
|
+
body: "json",
|
|
169
|
+
timeoutMs: 60000,
|
|
170
|
+
scope: "sandboxes:run",
|
|
171
|
+
};
|
|
172
|
+
const statFileOp: Op = {
|
|
173
|
+
id: "sandboxesStatFile",
|
|
174
|
+
method: "GET",
|
|
175
|
+
path: "/v1/sandboxes/{sandbox_id}/files/stat",
|
|
176
|
+
params: ["sandbox_id"],
|
|
177
|
+
timeoutMs: 30000,
|
|
178
|
+
scope: "sandboxes:run",
|
|
179
|
+
};
|
|
109
180
|
const forkSandboxOp: Op = {
|
|
110
181
|
id: "sandboxesForkSandbox",
|
|
111
182
|
method: "POST",
|
|
@@ -114,7 +185,6 @@ const forkSandboxOp: Op = {
|
|
|
114
185
|
body: "json",
|
|
115
186
|
idem: true,
|
|
116
187
|
timeoutMs: 30000,
|
|
117
|
-
stretch: true,
|
|
118
188
|
scope: "sandboxes:write",
|
|
119
189
|
};
|
|
120
190
|
const streamLogsOp: Op = {
|
|
@@ -169,6 +239,15 @@ const openPtyOp: Op = {
|
|
|
169
239
|
timeoutMs: 3600000,
|
|
170
240
|
scope: "sandboxes:run",
|
|
171
241
|
};
|
|
242
|
+
const waitReadyOp: Op = {
|
|
243
|
+
id: "sandboxesWaitReady",
|
|
244
|
+
method: "POST",
|
|
245
|
+
path: "/v1/sandboxes/{sandbox_id}/ready",
|
|
246
|
+
params: ["sandbox_id"],
|
|
247
|
+
body: "json",
|
|
248
|
+
timeoutMs: 65000,
|
|
249
|
+
scope: "sandboxes:run",
|
|
250
|
+
};
|
|
172
251
|
const resumeSandboxOp: Op = {
|
|
173
252
|
id: "sandboxesResumeSandbox",
|
|
174
253
|
method: "POST",
|
|
@@ -225,9 +304,14 @@ export const sandboxesOps = {
|
|
|
225
304
|
getTemplate: getTemplateOp,
|
|
226
305
|
deleteSandbox: deleteSandboxOp,
|
|
227
306
|
getSandbox: getSandboxOp,
|
|
307
|
+
setEgress: setEgressOp,
|
|
228
308
|
exec: execOp,
|
|
309
|
+
deleteFile: deleteFileOp,
|
|
229
310
|
readFile: readFileOp,
|
|
230
311
|
writeFile: writeFileOp,
|
|
312
|
+
makeDirectory: makeDirectoryOp,
|
|
313
|
+
moveFile: moveFileOp,
|
|
314
|
+
statFile: statFileOp,
|
|
231
315
|
forkSandbox: forkSandboxOp,
|
|
232
316
|
streamLogs: streamLogsOp,
|
|
233
317
|
pauseSandbox: pauseSandboxOp,
|
|
@@ -235,6 +319,7 @@ export const sandboxesOps = {
|
|
|
235
319
|
listProcesses: listProcessesOp,
|
|
236
320
|
killProcess: killProcessOp,
|
|
237
321
|
openPty: openPtyOp,
|
|
322
|
+
waitReady: waitReadyOp,
|
|
238
323
|
resumeSandbox: resumeSandboxOp,
|
|
239
324
|
runCode: runCodeOp,
|
|
240
325
|
createSnapshot: createSnapshotOp,
|
|
@@ -249,6 +334,10 @@ export class SandboxesAPI extends Namespace {
|
|
|
249
334
|
*
|
|
250
335
|
* Lists sandboxes in this project, newest first, including stopped ones from the last 7 days.
|
|
251
336
|
*
|
|
337
|
+
* `metadata[<key>]=<value>` (up to 4 pairs) keeps only sandboxes whose `metadata` holds every pair given, with
|
|
338
|
+
* exactly that value: `GET /v1/sandboxes?metadata[customer]=acme&metadata[ticket]=ENG-1423`. A sandbox whose
|
|
339
|
+
* create lost its answer (a dropped connection) is found this way by a tag it was created with.
|
|
340
|
+
*
|
|
252
341
|
* `GET /v1/sandboxes` · scope `sandboxes:read` · served by the node
|
|
253
342
|
*/
|
|
254
343
|
listSandboxes(
|
|
@@ -271,25 +360,88 @@ export class SandboxesAPI extends Namespace {
|
|
|
271
360
|
* explicitly. `api.spend_cap_usd` may not exceed your own spend cap, and `null` means your cap applies; scopes
|
|
272
361
|
* or a cap beyond yours are refused with `403 forbidden`, `reason: scope_escalation`.
|
|
273
362
|
*
|
|
363
|
+
* Code in a sandbox reaches other sandboxes through the sandboxes API only within its own sandbox's reach,
|
|
364
|
+
* except where this paragraph says. When it creates one (its `api` grant holds `sandboxes:write`), the new
|
|
365
|
+
* sandbox's `egress` defaults to the creating sandbox's own policy, and a policy that reaches further is
|
|
366
|
+
* refused with `403 forbidden`, `reason: egress_escalation`, as is a public port unless the creating sandbox's
|
|
367
|
+
* egress is `public` (restoring a snapshot and forking are bound the same way). Every operation that sends
|
|
368
|
+
* anything into another sandbox's microVM, to its guest or its ports, answers such code only for a sandbox
|
|
369
|
+
* within its reach: one whose egress is within its own sandbox's, where a sandbox with a public port or with
|
|
370
|
+
* a preview URL that may still serve counts as `public` (the internet reaches those ports whatever its egress),
|
|
371
|
+
* otherwise `403 forbidden`, `reason: egress_escalation`; and one whose `api` grant holds no scope and no
|
|
372
|
+
* connection its own lacks, otherwise `403 forbidden`, `reason: scope_escalation`. These operations are
|
|
373
|
+
* commands (buffered, streamed or in the background) and `run_code`, file reads, listings and writes, the
|
|
374
|
+
* process list, signals, logs, terminals, readiness probes it sets, and port previews (`POST
|
|
375
|
+
* …/ports/{port}/url` and the preview route itself, which the in-VM API also serves). Reach is checked when a
|
|
376
|
+
* call starts, and what stays open is cut when the change that takes the other sandbox out of the caller's
|
|
377
|
+
* reach is made (its egress is widened, a preview is minted for it, the calling sandbox's egress is narrowed or
|
|
378
|
+
* it stops), whether or not the caller is still reading: the node then drops the call's connection into the
|
|
379
|
+
* other sandbox, so the guest kills a buffered or streamed command (its process group) and hangs up a
|
|
380
|
+
* terminal's shell, and nothing either side sends after the change arrives. Data the other sandbox sent before
|
|
381
|
+
* the cut may still reach the caller from the node's buffers; then a buffered command or code run answers `403
|
|
382
|
+
* forbidden`, `reason: egress_escalation`, a streamed command ends with an `exec.exit` event carrying that
|
|
383
|
+
* error, log streams end, file reads end with an error and file writes answer that `403`, a terminal closes
|
|
384
|
+
* with code 1008, and a preview request or WebSocket is cut. What the caller already placed in the other
|
|
385
|
+
* sandbox stays there and no later change reaches it: background processes it started keep running, a readiness
|
|
386
|
+
* probe it set keeps probing, and files it wrote (including the part of a write that arrived before a cut)
|
|
387
|
+
* stay. The sandbox objects it reads carry no preview URL (`ports[].url` is `null`) for sandboxes beyond its
|
|
388
|
+
* reach. The control plane (get, list, pause, resume, timeout, snapshot, delete, waiting on a probe already
|
|
389
|
+
* set, and narrowing another sandbox's egress) is not bound this way, and neither are its own sandbox or
|
|
390
|
+
* templates. Other products reach the network on their own terms: a grant of their scopes (`vision:*`,
|
|
391
|
+
* `actions:*`, `infer:*`, ...) lets code in the sandbox send data out through them, so give a sandbox whose
|
|
392
|
+
* egress is `deny` none of those. Egress `deny` and `allowlist` stop network exfiltration, not timing channels:
|
|
393
|
+
* sandboxes on one node share physical CPU cores, the last-level cache, memory bandwidth and the storage path,
|
|
394
|
+
* so cooperating code in any two sandboxes on a node can signal each other at a low bit rate through CPU-cache,
|
|
395
|
+
* CPU-contention or storage timing (OpenAI described such channels between microVMs:
|
|
396
|
+
* https://openai.com/index/securing-our-frontier-model-training-environment/).
|
|
397
|
+
*
|
|
274
398
|
* Inside the sandbox the environment also has `B3OS_API_URL=http://127.0.0.1:7700`, `B3OS_SANDBOX_ID`,
|
|
275
399
|
* `B3OS_PROJECT` and `B3OS_PORT_BASE_PATH=/sbx/<host_id>`. `B3OS_PORT_BASE_PATH` is only the fixed start of
|
|
276
400
|
* every port preview path on `usercontent.b3os.org`, not a full base path: the full prefix of a request,
|
|
277
401
|
* `/sbx/<host_id>/<port>/<token>`, arrives with it in `X-Forwarded-Prefix` (`sandboxesProxyPortGet`).
|
|
278
402
|
*
|
|
403
|
+
* When `api.scopes` include `infer:run` (named, or through `infer:*` or `*`), the environment also points the
|
|
404
|
+
* stock OpenAI and Anthropic SDKs at the node's models: `OPENAI_BASE_URL` and `ANTHROPIC_BASE_URL` are
|
|
405
|
+
* `http://127.0.0.1:7700/v1/infer`, `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` are the placeholder
|
|
406
|
+
* `b3os-sandbox` (the sandbox's grant authenticates the call and the key is ignored), and `B3OS_MODEL` names
|
|
407
|
+
* the node's default model (`b3os/qwen3.5-9b` in the beta). A value you set in `env` for any of them wins.
|
|
408
|
+
* Restores from a snapshot get the same, and forks keep their source's.
|
|
409
|
+
*
|
|
279
410
|
* `timing` phases: `validate_ms`, then `claim_ms` and `resume_ms` for a pre-warmed microVM from the pool, or
|
|
280
411
|
* `restore_ms` when none was parked (a restore on demand, or from a snapshot), then `bind_ms` (the identity
|
|
281
412
|
* and environment reach the guest agent), and `total_ms`.
|
|
282
413
|
*
|
|
283
414
|
* A create that has started finishes even if the client disconnects before the response: the sandbox then
|
|
284
|
-
* runs (and is billed) until its timeout or a delete
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
415
|
+
* runs (and is billed) until its timeout or a delete. Its answer is stored under the `Idempotency-Key` (the
|
|
416
|
+
* SDKs send one), so a retry with that key gets the same sandbox with `Idempotent-Replayed: true`, or `409
|
|
417
|
+
* idempotency_request_in_progress` while the create still runs. Without a key a retry is a new create:
|
|
418
|
+
* `GET /v1/sandboxes` lists the first one with the `metadata` it was created with. Fork, snapshot, pause and
|
|
419
|
+
* resume also finish after a disconnect.
|
|
420
|
+
*
|
|
421
|
+
* A sandbox keeps running when the node's daemon restarts: its microVM runs outside the daemon, which adopts
|
|
422
|
+
* it again when it starts (its processes, files and environment are untouched). Connections that go through
|
|
423
|
+
* the daemon (streamed execs, PTY sessions, log streams, port preview connections, the sandbox's outbound
|
|
424
|
+
* connections and its calls to `http://127.0.0.1:7700`) drop at the restart and can be opened again.
|
|
425
|
+
*
|
|
426
|
+
* Disk: a sandbox's disk is its own copy-on-write copy of the template's (or snapshot's) disk; it is deleted
|
|
427
|
+
* when the sandbox ends and never given to another sandbox. The disks of an organization's running and paused
|
|
428
|
+
* sandboxes on a node add up to at most `sandboxes.disk_total_max` (each sandbox counting its `disk_gib`;
|
|
429
|
+
* beta: `sandboxes.concurrent` times `sandboxes.disk_max`, 160 GiB, so at the beta limits it never refuses a
|
|
430
|
+
* create the concurrency limit allows); past it a create is refused with `422 limit_exceeded`. While the
|
|
431
|
+
* node's disk store is nearly full, creates are refused with `503 capacity_unavailable` and `Retry-After`.
|
|
432
|
+
*
|
|
433
|
+
* Returns the sandbox object (`SandboxInfo`). `create()` sends the same request and returns a `Sandbox`
|
|
434
|
+
* handle instead (`exec`, `files`, `ports`), which `await using` deletes when the scope ends.
|
|
288
435
|
*
|
|
289
436
|
* `POST /v1/sandboxes` · scope `sandboxes:write` · served by the node
|
|
290
437
|
*/
|
|
291
|
-
createSandbox(body?:
|
|
292
|
-
return
|
|
438
|
+
createSandbox(body?: SandboxCreateBody, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
439
|
+
return createSandboxSafely(
|
|
440
|
+
(b, o) => this._client._call<T.Sandbox>(createSandboxOp, { body: b }, o),
|
|
441
|
+
body,
|
|
442
|
+
options,
|
|
443
|
+
this._client.maxRetries,
|
|
444
|
+
);
|
|
293
445
|
}
|
|
294
446
|
|
|
295
447
|
/**
|
|
@@ -331,9 +483,10 @@ export class SandboxesAPI extends Namespace {
|
|
|
331
483
|
/**
|
|
332
484
|
* List templates
|
|
333
485
|
*
|
|
334
|
-
* Lists the templates sandboxes can start from (`base`, `code-interpreter`, `agent`, and
|
|
335
|
-
*
|
|
336
|
-
*
|
|
486
|
+
* Lists the templates sandboxes can start from (`base`, `code-interpreter`, `agent`, and `browser` where a node
|
|
487
|
+
* builds it, which the beta node does not yet: Chrome already running in the snapshot, a VM-isolated browser
|
|
488
|
+
* with DevTools on port 9222) with their OS, runtimes, capabilities, defaults and `size_classes` (the sizes kept
|
|
489
|
+
* pre-warmed). It does not list a template's packages.
|
|
337
490
|
*
|
|
338
491
|
* `GET /v1/sandboxes/templates` · scope `sandboxes:read` · served by the node
|
|
339
492
|
*/
|
|
@@ -374,6 +527,27 @@ export class SandboxesAPI extends Namespace {
|
|
|
374
527
|
return this._client._call<T.Sandbox>(getSandboxOp, { path: [sandboxId] }, options);
|
|
375
528
|
}
|
|
376
529
|
|
|
530
|
+
/**
|
|
531
|
+
* Change a sandbox's egress policy
|
|
532
|
+
*
|
|
533
|
+
* Replaces the sandbox's `egress` policy (mode and allow list) while it runs or is paused. New outbound
|
|
534
|
+
* connections and DNS answers follow the new policy at once, and open connections it does not allow (SOCKS5,
|
|
535
|
+
* HTTP CONNECT and transparently redirected TCP alike) are closed: under `allowlist`, a connection stays open
|
|
536
|
+
* only if the host name it was opened for is on the new list (one opened by address alone is closed); under
|
|
537
|
+
* `deny`, every connection closes. Private, loopback, tailnet and metadata addresses stay refused in every
|
|
538
|
+
* mode. A sandbox cannot change its own policy (its in-VM API gets `403 forbidden`, `reason: self`, whatever
|
|
539
|
+
* its grant); call from outside it. Code in a sandbox may only narrow another sandbox's policy, to one within
|
|
540
|
+
* both that sandbox's current policy and its own (otherwise `403 forbidden`, `reason: egress_escalation`). A
|
|
541
|
+
* change cuts the streams code in other sandboxes holds open into this sandbox, and those code in this sandbox
|
|
542
|
+
* holds into others, once their target is no longer within the caller's reach (`sandboxesCreateSandbox`); the
|
|
543
|
+
* processes and files such code placed stay.
|
|
544
|
+
*
|
|
545
|
+
* `POST /v1/sandboxes/{sandbox_id}/egress` · scope `sandboxes:write` · served by the node
|
|
546
|
+
*/
|
|
547
|
+
setEgress(sandboxId: string, body: T.EgressPolicy, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
548
|
+
return this._client._call<T.Sandbox>(setEgressOp, { path: [sandboxId], body }, options);
|
|
549
|
+
}
|
|
550
|
+
|
|
377
551
|
/**
|
|
378
552
|
* Run a command
|
|
379
553
|
*
|
|
@@ -381,11 +555,29 @@ export class SandboxesAPI extends Namespace {
|
|
|
381
555
|
* seconds) and returns its exit code and output. With `?stream=true` (or `Accept: text/event-stream`) output
|
|
382
556
|
* arrives as `exec.stdout` and `exec.stderr` events while it runs, ending with `exec.exit`; streamed commands
|
|
383
557
|
* may run up to an hour. With `background: true` the response returns at once with the process, whose output
|
|
384
|
-
* you read from `GET /v1/sandboxes/{sandbox_id}/logs`.
|
|
558
|
+
* you read from `GET /v1/sandboxes/{sandbox_id}/logs`. From inside another sandbox, a command is cut if this
|
|
559
|
+
* sandbox leaves the caller's reach while it runs (`sandboxesCreateSandbox`). The node then drops the command's
|
|
560
|
+
* connection to the guest, whether or not the caller is reading a streamed command's events, and the guest
|
|
561
|
+
* kills the command's process group (a process the command moved into a group of its own keeps running, as a
|
|
562
|
+
* background process does). A buffered command answers `403 forbidden`, `reason: egress_escalation`; a streamed
|
|
563
|
+
* one delivers the events queued before the cut and then ends with an `exec.exit` event whose `error` has
|
|
564
|
+
* `code: forbidden` and `reason: egress_escalation` and whose `duration_ms` runs to the cut.
|
|
385
565
|
*
|
|
386
566
|
* `cmd` as a string runs through `/bin/sh -c`; as an array it is executed directly. Output is UTF-8 (invalid
|
|
387
567
|
* bytes become U+FFFD) and each stream is capped at 1 MiB in a buffered response.
|
|
388
568
|
*
|
|
569
|
+
* With `Idempotency-Key`, a command runs at most once per key. A retry with the same key and body within 24
|
|
570
|
+
* hours gets the first answer again (`Idempotent-Replayed: true`), and a retry while it still runs gets `409
|
|
571
|
+
* idempotency_request_in_progress`. Once the command was handed to the sandbox, its key is kept: when the
|
|
572
|
+
* node cannot tell whether it ran (`502 guest_unreachable` after the hand-off) or its answer was a stream,
|
|
573
|
+
* which is never stored, a retry gets `409 idempotency_outcome_unknown` and the command does not run again.
|
|
574
|
+
* A keyed buffered answer is kept for replay in the node's memory only (command output is never written to
|
|
575
|
+
* disk), so after a node restart a retry gets `409 idempotency_response_evicted`, saying how the command
|
|
576
|
+
* ended, instead. Its output is cut to fit the replay store (at most 256 KiB of JSON on the beta node), the
|
|
577
|
+
* longer stream first, with `stdout_truncated` or `stderr_truncated` set; read more of a large output from a
|
|
578
|
+
* file the command writes. The SDKs send no key unless you pass one, and never resend a command after an
|
|
579
|
+
* answer that does not show it did no work (a node error, an error page, a dropped connection).
|
|
580
|
+
*
|
|
389
581
|
* `POST /v1/sandboxes/{sandbox_id}/exec` · scope `sandboxes:run` · served by the node
|
|
390
582
|
*/
|
|
391
583
|
exec(
|
|
@@ -409,22 +601,44 @@ export class SandboxesAPI extends Namespace {
|
|
|
409
601
|
return this._client._call<T.ExecResult | T.SandboxProcess>(execOp, { path: [sandboxId], body }, options);
|
|
410
602
|
}
|
|
411
603
|
|
|
604
|
+
/**
|
|
605
|
+
* Delete a file or directory
|
|
606
|
+
*
|
|
607
|
+
* Deletes the file, symlink or empty directory at `path`; with `recursive=1`, a directory and everything in
|
|
608
|
+
* it. A symlink is deleted itself, never its target, and a recursive delete removes the symlinks it finds
|
|
609
|
+
* without following them. A path that is `/` or ends in `.` or `..` is refused, as `rm` refuses it. A
|
|
610
|
+
* recursive delete of a large tree goes on inside the sandbox to its end even when the answer times out.
|
|
611
|
+
* Sandboxes whose template image predates this operation answer `409 guest_outdated`; `rm` through
|
|
612
|
+
* `sandboxesExec` works there.
|
|
613
|
+
*
|
|
614
|
+
* `DELETE /v1/sandboxes/{sandbox_id}/files` · scope `sandboxes:run` · served by the node
|
|
615
|
+
*/
|
|
616
|
+
deleteFile(
|
|
617
|
+
sandboxId: string,
|
|
618
|
+
params: T.SandboxesDeleteFileParams,
|
|
619
|
+
options?: RequestOptions,
|
|
620
|
+
): APIPromise<T.FileDeleted> {
|
|
621
|
+
return this._client._call<T.FileDeleted>(deleteFileOp, { path: [sandboxId], query: params }, options);
|
|
622
|
+
}
|
|
623
|
+
|
|
412
624
|
/**
|
|
413
625
|
* Read a file or list a directory
|
|
414
626
|
*
|
|
415
627
|
* Returns the file at `path` as bytes. With `list=1` returns the directory's entries (or the single entry
|
|
416
|
-
* when `path` is a file) as JSON instead. Transfers are capped at 64 MiB.
|
|
628
|
+
* when `path` is a file) as JSON instead. Transfers are capped at 64 MiB. From inside another sandbox, a read
|
|
629
|
+
* that is still streaming when this sandbox leaves the caller's reach ends with an error
|
|
630
|
+
* (`sandboxesCreateSandbox`).
|
|
417
631
|
*
|
|
418
632
|
* `GET /v1/sandboxes/{sandbox_id}/files` · scope `sandboxes:run` · served by the node
|
|
419
633
|
*/
|
|
420
634
|
readFile(
|
|
421
635
|
sandboxId: string,
|
|
422
|
-
params: T.SandboxesReadFileParams & { list: 1 },
|
|
636
|
+
params: T.SandboxesReadFileParams & { list: true | 1 },
|
|
423
637
|
options?: RequestOptions,
|
|
424
638
|
): APIPromise<T.FileEntryList>;
|
|
425
639
|
readFile(
|
|
426
640
|
sandboxId: string,
|
|
427
|
-
params: T.SandboxesReadFileParams & { list?: 0 },
|
|
641
|
+
params: T.SandboxesReadFileParams & { list?: false | 0 },
|
|
428
642
|
options?: RequestOptions,
|
|
429
643
|
): APIPromise<Uint8Array>;
|
|
430
644
|
readFile(
|
|
@@ -432,7 +646,7 @@ export class SandboxesAPI extends Namespace {
|
|
|
432
646
|
params: T.SandboxesReadFileParams,
|
|
433
647
|
options?: RequestOptions,
|
|
434
648
|
): APIPromise<Uint8Array | T.FileEntryList> {
|
|
435
|
-
return params.list === 1
|
|
649
|
+
return params.list === true || params.list === 1
|
|
436
650
|
? this._client._call<T.FileEntryList>(
|
|
437
651
|
readFileOp,
|
|
438
652
|
{ path: [sandboxId], query: params },
|
|
@@ -453,7 +667,10 @@ export class SandboxesAPI extends Namespace {
|
|
|
453
667
|
* Write a file
|
|
454
668
|
*
|
|
455
669
|
* Writes the request body to `path`, replacing any existing file, creating parent directories with `mkdir=1`.
|
|
456
|
-
* Returns the file's entry. Up to 64 MiB per request.
|
|
670
|
+
* Returns the file's entry. Up to 64 MiB per request. The file is written as the body arrives, so a write that
|
|
671
|
+
* fails part-way leaves the part that arrived. From inside another sandbox, a write still streaming when this
|
|
672
|
+
* sandbox leaves the caller's reach is cut: nothing sent after that is written, and the answer is `403
|
|
673
|
+
* forbidden`, `reason: egress_escalation` (`sandboxesCreateSandbox`).
|
|
457
674
|
*
|
|
458
675
|
* `PUT /v1/sandboxes/{sandbox_id}/files` · scope `sandboxes:run` · served by the node
|
|
459
676
|
*/
|
|
@@ -466,20 +683,64 @@ export class SandboxesAPI extends Namespace {
|
|
|
466
683
|
return this._client._call<T.FileEntry>(writeFileOp, { path: [sandboxId], query: params, body: data }, options);
|
|
467
684
|
}
|
|
468
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Create a directory
|
|
688
|
+
*
|
|
689
|
+
* Creates the directory at `path` with `mode`, and any missing parents, like `mkdir -p`; each new directory
|
|
690
|
+
* is owned like the one it is made in. Answers `201` with the entry when it created the directory and `200`
|
|
691
|
+
* when a directory (or a symlink to one) was already there; a file at `path` is `409 file_exists`. Sandboxes
|
|
692
|
+
* whose template image predates this operation answer `409 guest_outdated`.
|
|
693
|
+
*
|
|
694
|
+
* `POST /v1/sandboxes/{sandbox_id}/files/mkdir` · scope `sandboxes:run` · served by the node
|
|
695
|
+
*/
|
|
696
|
+
makeDirectory(sandboxId: string, body: T.MakeDirectoryRequest, options?: RequestOptions): APIPromise<T.FileEntry> {
|
|
697
|
+
return this._client._call<T.FileEntry>(makeDirectoryOp, { path: [sandboxId], body }, options);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* Move or rename a file or directory
|
|
702
|
+
*
|
|
703
|
+
* Moves `from` to `to` and returns the entry at `to`. An existing `to` is kept and the move refused with
|
|
704
|
+
* `409 file_exists` unless `overwrite` is true; a directory replaces only an empty directory. The directory
|
|
705
|
+
* `to` goes in must exist. Across filesystems inside the sandbox (from `/tmp` to `/workspace`, say) a
|
|
706
|
+
* regular file is copied and its source removed; a directory is refused there. Sandboxes whose template
|
|
707
|
+
* image predates this operation answer `409 guest_outdated`.
|
|
708
|
+
*
|
|
709
|
+
* `POST /v1/sandboxes/{sandbox_id}/files/move` · scope `sandboxes:run` · served by the node
|
|
710
|
+
*/
|
|
711
|
+
moveFile(sandboxId: string, body: T.MoveFileRequest, options?: RequestOptions): APIPromise<T.FileEntry> {
|
|
712
|
+
return this._client._call<T.FileEntry>(moveFileOp, { path: [sandboxId], body }, options);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Describe a file or directory
|
|
717
|
+
*
|
|
718
|
+
* Returns the entry at `path` without reading it: a directory's own entry (where `list=1` on
|
|
719
|
+
* `sandboxesReadFile` lists what is in it), and a symlink as a symlink with its `target`. Sandboxes whose
|
|
720
|
+
* template image predates this operation answer `409 guest_outdated`.
|
|
721
|
+
*
|
|
722
|
+
* `GET /v1/sandboxes/{sandbox_id}/files/stat` · scope `sandboxes:run` · served by the node
|
|
723
|
+
*/
|
|
724
|
+
statFile(sandboxId: string, params: T.SandboxesStatFileParams, options?: RequestOptions): APIPromise<T.FileEntry> {
|
|
725
|
+
return this._client._call<T.FileEntry>(statFileOp, { path: [sandboxId], query: params }, options);
|
|
726
|
+
}
|
|
727
|
+
|
|
469
728
|
/**
|
|
470
729
|
* Fork a sandbox
|
|
471
730
|
*
|
|
472
731
|
* Creates `count` new running sandboxes that share the source's memory and disk copy-on-write, each with a fresh
|
|
473
|
-
* identity (its own id, entropy, machine ID and clock; the source's environment, secrets, files
|
|
474
|
-
* processes carry over
|
|
475
|
-
*
|
|
476
|
-
* forkable
|
|
477
|
-
*
|
|
478
|
-
*
|
|
732
|
+
* identity (its own id, kernel entropy, machine ID, hostname and clock; the source's environment, secrets, files
|
|
733
|
+
* and running processes carry over, the processes with their in-memory random state, except that the `browser`
|
|
734
|
+
* template's Chrome is reset unless `clone_reset` is `none`, see below). The source must have been created with
|
|
735
|
+
* `forkable: true` (forkable sandboxes are restored for themselves rather than claimed from a pool, and track
|
|
736
|
+
* the pages they change); forks are forkable too. The source pauses while its changed memory is written
|
|
737
|
+
* (`pause`, `base`, `snapshot`, `export` phases in `Server-Timing`), then runs on; like a snapshot this resets
|
|
738
|
+
* its open connections to the outside.
|
|
739
|
+
* Each fork counts against your sandbox concurrency and, with the source's `disk_gib`, against
|
|
740
|
+
* `sandboxes.disk_total_max` (`422 limit_exceeded`). While the node's snapshot or disk store is nearly full,
|
|
741
|
+
* forks are refused with `503 capacity_unavailable`.
|
|
479
742
|
*
|
|
480
743
|
* `POST /v1/sandboxes/{sandbox_id}/fork` · scope `sandboxes:write` · served by the node
|
|
481
|
-
*
|
|
482
|
-
* Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
|
|
483
744
|
*/
|
|
484
745
|
forkSandbox(sandboxId: string, body?: T.ForkRequest, options?: RequestOptions): APIPromise<T.SandboxList> {
|
|
485
746
|
return this._client._call<T.SandboxList>(forkSandboxOp, { path: [sandboxId], body }, options);
|
|
@@ -491,6 +752,8 @@ export class SandboxesAPI extends Namespace {
|
|
|
491
752
|
* Server-sent events with the output of background processes: `log.stdout` and `log.stderr` per chunk and
|
|
492
753
|
* `process.exited` when one ends. Starts with up to 1 MiB of buffered output per process, then follows new
|
|
493
754
|
* output until the sandbox stops (or immediately ends with `follow=false`). Filter to one process with `pid`.
|
|
755
|
+
* From inside another sandbox (or on a ticket minted there), the stream ends if this sandbox leaves the
|
|
756
|
+
* caller's reach (`sandboxesCreateSandbox`).
|
|
494
757
|
* Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`
|
|
495
758
|
* (`?ticket=`, for `EventSource`).
|
|
496
759
|
*
|
|
@@ -510,9 +773,17 @@ export class SandboxesAPI extends Namespace {
|
|
|
510
773
|
/**
|
|
511
774
|
* Pause a sandbox
|
|
512
775
|
*
|
|
513
|
-
* Freezes the sandbox's vCPUs and keeps its memory and disk on the node. A paused sandbox bills
|
|
514
|
-
*
|
|
515
|
-
*
|
|
776
|
+
* Freezes the sandbox's vCPUs and keeps its memory and disk on the node. A paused sandbox bills nothing:
|
|
777
|
+
* `sandboxes.vcpu_ms` counts CPU used and `sandboxes.gib_ms` counts memory only while the sandbox runs. It
|
|
778
|
+
* still counts toward `sandboxes.concurrent` and still expires at `expires_at`. Resume continues exactly
|
|
779
|
+
* where it stopped; connections that were open across the pause (the guest's outbound TCP, port preview
|
|
780
|
+
* WebSockets, PTY sessions) keep working. Pausing a paused sandbox returns it unchanged.
|
|
781
|
+
*
|
|
782
|
+
* A workflow that holds a sandbox across a long wait (a routine's `wait` or `sleep` step) pauses it and
|
|
783
|
+
* resumes it before its next exec, so the wait bills no sandbox time.
|
|
784
|
+
*
|
|
785
|
+
* `timing` phases: `admit` (from the request head to the VMM call: middleware, lookup, the sandbox's operation
|
|
786
|
+
* lock and the memory meter), `pause` (the VMM freezing the vCPUs) and `record` (the new status recorded).
|
|
516
787
|
*
|
|
517
788
|
* `POST /v1/sandboxes/{sandbox_id}/pause` · scope `sandboxes:write` · served by the node
|
|
518
789
|
*/
|
|
@@ -529,7 +800,18 @@ export class SandboxesAPI extends Namespace {
|
|
|
529
800
|
* then, with no cookie or other credential. For a public port the response is the sandbox's long-lived URL
|
|
530
801
|
* (`ports[].url`) and `ttl_s` is ignored. The port must be declared in `ports` when the sandbox is created. The
|
|
531
802
|
* app sees the URL's base path in `X-Forwarded-Prefix` on every request (token format and forwarding:
|
|
532
|
-
* `sandboxesProxyPortGet`).
|
|
803
|
+
* `sandboxesProxyPortGet`). Code in a sandbox gets a URL only for its own sandbox and sandboxes within its reach
|
|
804
|
+
* (otherwise `403 forbidden`, `reason: egress_escalation` or `scope_escalation`; `sandboxesCreateSandbox`): a
|
|
805
|
+
* preview carries requests to the port, so it would reach as far as that sandbox. Anyone with the URL reaches
|
|
806
|
+
* the port, so from the first mint until the token's expiry plus an hour the sandbox counts as `public` egress
|
|
807
|
+
* to code in other sandboxes; every request let in on the token has ended by then (at most an hour after it was
|
|
808
|
+
* let in, its request body included, and never past the token's expiry plus an hour: `sandboxesProxyPortGet`).
|
|
809
|
+
* A mint therefore takes the sandbox out of the reach of code in sandboxes whose egress is not `public` and
|
|
810
|
+
* cuts the streams such code holds open into it, and such code gets no further URL for it. Such code may mint
|
|
811
|
+
* the first URL while the sandbox is within its reach, but it can use that URL only through the usercontent
|
|
812
|
+
* origin, which its egress must let it reach (the in-VM preview route refuses it). An `allowlist` that names
|
|
813
|
+
* the usercontent origin reaches every preview URL its code learns, of any sandbox, so in practice it counts as
|
|
814
|
+
* `public`.
|
|
533
815
|
*
|
|
534
816
|
* `POST /v1/sandboxes/{sandbox_id}/ports/{port}/url` · scope `sandboxes:run` · served by the node
|
|
535
817
|
*/
|
|
@@ -575,7 +857,21 @@ export class SandboxesAPI extends Namespace {
|
|
|
575
857
|
* Opens a WebSocket attached to a new pseudo-terminal running the user's login shell (or `cmd`). Binary frames
|
|
576
858
|
* carry terminal bytes in both directions. Text frames carry JSON control messages: send
|
|
577
859
|
* `{"type": "resize", "cols": 120, "rows": 40}`; the server sends `{"type": "exit", "code": 0}` before it closes.
|
|
578
|
-
* Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`.
|
|
860
|
+
* Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`. From
|
|
861
|
+
* inside another sandbox (or on a ticket minted there), the terminal closes with code 1008, reason
|
|
862
|
+
* `egress_escalation`, if this sandbox leaves the caller's reach (`sandboxesCreateSandbox`); input sent after
|
|
863
|
+
* that is not delivered, and the shell is hung up.
|
|
864
|
+
*
|
|
865
|
+
* With `session=new` the terminal can outlive its socket: the server's first frame is
|
|
866
|
+
* `{"type": "session", "id": "pts_...", "resumed": false}`. If the socket closes while the shell is still
|
|
867
|
+
* running (a page reload, a dropped network), the shell keeps running for 5 minutes and its last 128 KiB of
|
|
868
|
+
* output are kept. `session=<id>` on the same sandbox attaches to it again: the first frame says
|
|
869
|
+
* `"resumed": true`, a binary frame replays the kept output from its first whole line, and the terminal takes
|
|
870
|
+
* the new `cols` and `rows`. A second socket on a session takes it over, and the first closes with code 4001,
|
|
871
|
+
* reason `attached_elsewhere`. An id that is unknown, expired or another sandbox's opens a new terminal
|
|
872
|
+
* (`"resumed": false`, a new id). Send `{"type": "end"}` to hang a kept terminal up at once instead of leaving
|
|
873
|
+
* it to expire. Without `session` the shell is hung up when the socket closes. From inside another sandbox
|
|
874
|
+
* `session` is ignored.
|
|
579
875
|
*
|
|
580
876
|
* `GET /v1/sandboxes/{sandbox_id}/pty` · scope `sandboxes:run` · served by the node
|
|
581
877
|
*/
|
|
@@ -595,6 +891,32 @@ export class SandboxesAPI extends Namespace {
|
|
|
595
891
|
return new PtySession(await openSocket(url, protocols, options.signal));
|
|
596
892
|
}
|
|
597
893
|
|
|
894
|
+
/**
|
|
895
|
+
* Wait until a sandbox is ready
|
|
896
|
+
*
|
|
897
|
+
* Waits up to `wait_ms` for the sandbox's readiness probe (`readiness` on create) to pass, and answers with
|
|
898
|
+
* its state: `ready` (with `time_to_ready_ms`, from the create's start to the first passing try), `failed`
|
|
899
|
+
* (it did not pass within its `timeout_s`), or `pending` when `wait_ms` ran out first (call again). With
|
|
900
|
+
* `port` or `cmd` in the body the call sets that probe first, replacing the sandbox's earlier one, so a
|
|
901
|
+
* client can start a server with an exec and then wait for its port in one more call. The SDKs'
|
|
902
|
+
* `waitUntilReady` (`wait_until_ready`) is a different wait: the client runs its probes through exec, and it
|
|
903
|
+
* also takes HTTP-status and log-line probes. A sandbox with no probe, and none in the body, is `400`.
|
|
904
|
+
* Probes run inside the
|
|
905
|
+
* sandbox (a connection to `127.0.0.1:<port>`, or the command) and bill like any other use of it. From inside
|
|
906
|
+
* another sandbox, setting a probe needs this sandbox to be within the caller's reach
|
|
907
|
+
* (`sandboxesCreateSandbox`; otherwise `403 forbidden`, `reason: egress_escalation` or `scope_escalation`);
|
|
908
|
+
* waiting on the probe already set does not. A probe set that way keeps probing if this sandbox later leaves
|
|
909
|
+
* the caller's reach.
|
|
910
|
+
*
|
|
911
|
+
* The node runs the probe: the sandbox's `readiness`, or `port` or `cmd` in the body. `waitUntilReady()`
|
|
912
|
+
* probes from this client instead and also takes HTTP-status and log-line probes.
|
|
913
|
+
*
|
|
914
|
+
* `POST /v1/sandboxes/{sandbox_id}/ready` · scope `sandboxes:run` · served by the node
|
|
915
|
+
*/
|
|
916
|
+
waitReady(sandboxId: string, body?: T.ReadinessWaitRequest, options?: RequestOptions): APIPromise<T.ReadinessResult> {
|
|
917
|
+
return this._client._call<T.ReadinessResult>(waitReadyOp, { path: [sandboxId], body }, options);
|
|
918
|
+
}
|
|
919
|
+
|
|
598
920
|
/**
|
|
599
921
|
* Resume a sandbox
|
|
600
922
|
*
|
|
@@ -602,6 +924,9 @@ export class SandboxesAPI extends Namespace {
|
|
|
602
924
|
* running sandbox returns it unchanged. A resumed sandbox is billed again (`sandboxes.gib_ms`), so a resume is
|
|
603
925
|
* admitted like a create (credits, spend cap).
|
|
604
926
|
*
|
|
927
|
+
* `timing` phases: `admit`, `resume` (the VMM running the vCPUs again) and `record`, as for pause. A resume
|
|
928
|
+
* costs more the longer the sandbox stayed paused (the measured numbers are on the benchmarks page).
|
|
929
|
+
*
|
|
605
930
|
* `POST /v1/sandboxes/{sandbox_id}/resume` · scope `sandboxes:write` · served by the node
|
|
606
931
|
*/
|
|
607
932
|
resumeSandbox(sandboxId: string, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
@@ -613,7 +938,8 @@ export class SandboxesAPI extends Namespace {
|
|
|
613
938
|
*
|
|
614
939
|
* Runs code in the sandbox's Jupyter kernel and returns its rich results (text, images, HTML, JSON), output
|
|
615
940
|
* and any error. State persists between calls, like cells in a notebook. Needs a sandbox created from the
|
|
616
|
-
* `code-interpreter` template.
|
|
941
|
+
* `code-interpreter` template. From inside another sandbox, a run is cut if this sandbox leaves the caller's
|
|
942
|
+
* reach before it answers (`403 forbidden`, `reason: egress_escalation`; `sandboxesCreateSandbox`).
|
|
617
943
|
*
|
|
618
944
|
* `POST /v1/sandboxes/{sandbox_id}/run_code` · scope `sandboxes:run` · served by the node
|
|
619
945
|
*/
|
|
@@ -625,10 +951,17 @@ export class SandboxesAPI extends Namespace {
|
|
|
625
951
|
* Snapshot a sandbox
|
|
626
952
|
*
|
|
627
953
|
* Saves the sandbox's memory and disk as a snapshot you can create new sandboxes from. The sandbox keeps
|
|
628
|
-
* running (it pauses for the copy).
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
954
|
+
* running (it pauses for the copy). The call answers, and the snapshot is listed `ready`, only once its files
|
|
955
|
+
* are written to the node's disk (`sync` in `timing`); the sandbox runs again before that. Each sandbox
|
|
956
|
+
* restored from a snapshot gets fresh kernel entropy, a new machine ID and hostname and the current time, but
|
|
957
|
+
* the processes it brings back keep their memory, yours and the template's (Chrome, in the `browser`
|
|
958
|
+
* template): a random generator such a process held at the snapshot (a browser's or Node.js's `Math.random`,
|
|
959
|
+
* a TLS library's) starts in the same state in every one of them unless B3OS resets it. B3OS reseeds the code
|
|
960
|
+
* kernel's Python `random` module and NumPy global generator, and resets the `browser` template's Chrome by
|
|
961
|
+
* default (`clone_reset` on the create) where the node's image of that template has the reset. Start your own
|
|
962
|
+
* such processes after the restore or restart them. Writing the snapshot resets the sandbox's open connections
|
|
963
|
+
* to the outside (open PTY sessions, streaming execs and log streams, port preview connections, outbound TCP
|
|
964
|
+
* connections); new ones work as soon as the call returns.
|
|
632
965
|
*
|
|
633
966
|
* Snapshots are kept 7 days. An organization keeps at most `sandboxes.snapshots_max` snapshots (beta: 20)
|
|
634
967
|
* per node, counting at most `sandboxes.snapshot_storage_max` (beta: 40 GiB). Each snapshot counts its
|
|
@@ -668,4 +1001,71 @@ export class SandboxesAPI extends Namespace {
|
|
|
668
1001
|
setTimeout(sandboxId: string, body: T.TimeoutRequest, options?: RequestOptions): APIPromise<T.Sandbox> {
|
|
669
1002
|
return this._client._call<T.Sandbox>(setTimeoutOp, { path: [sandboxId], body }, options);
|
|
670
1003
|
}
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Creates a sandbox (`POST /v1/sandboxes`, the same request as `createSandbox`) and returns its
|
|
1007
|
+
* {@link Sandbox} handle: `exec`, `files`, `ports`, `snapshot`, `fork` and the lifecycle calls.
|
|
1008
|
+
* `await using sbx = await b3os.sandboxes.create()` deletes it when the scope ends unless `sbx.detach()`.
|
|
1009
|
+
* `createSandbox` sends the same request and returns only the object (`SandboxInfo`).
|
|
1010
|
+
*/
|
|
1011
|
+
create(body?: SandboxCreateBody, options?: RequestOptions): Promise<Sandbox> {
|
|
1012
|
+
// The handle's ports.screenshot and ports.scrape use the client's render and vision namespaces.
|
|
1013
|
+
const root = this._client as unknown as Partial<SandboxClient>;
|
|
1014
|
+
const client: SandboxClient = {
|
|
1015
|
+
sandboxes: this,
|
|
1016
|
+
get render() {
|
|
1017
|
+
return root.render;
|
|
1018
|
+
},
|
|
1019
|
+
get vision() {
|
|
1020
|
+
return root.vision;
|
|
1021
|
+
},
|
|
1022
|
+
};
|
|
1023
|
+
return Sandbox.create(client, body, options);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Waits until a sandbox is ready: a TCP port accepts connections (`{ port }`), an HTTP GET answers
|
|
1028
|
+
* (`{ http }`), a command exits 0 (`{ exec }`) or a background process prints a line (`{ log, pid }`). The
|
|
1029
|
+
* first probe runs at once, later ones back off from 25 to 250 ms; `timeoutMs` (default 60 s) bounds the
|
|
1030
|
+
* wait, and `pid` fails it at once when that process exits. Resolves with the client-side time to ready.
|
|
1031
|
+
* This client runs the probes through `exec`, and nothing is set on the sandbox; `waitReady` asks the node
|
|
1032
|
+
* to probe instead (a port or a command, kept as the sandbox's readiness probe).
|
|
1033
|
+
*/
|
|
1034
|
+
waitUntilReady(sandboxId: string, probe: ReadyProbe, options?: ReadyOptions): Promise<ReadyResult> {
|
|
1035
|
+
return waitUntilReady(this, sandboxId, probe, options);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Starts a background process (a dev server, a worker) and, with `ready`, waits until it is up; the process is
|
|
1040
|
+
* stopped again when it exits or misses the deadline first. `previewPort` also mints its preview URL.
|
|
1041
|
+
*/
|
|
1042
|
+
startService(sandboxId: string, options: ServiceOptions): Promise<Service> {
|
|
1043
|
+
return startService(this, sandboxId, options);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
/**
|
|
1047
|
+
* Claude Managed Agents, self-hosted environment: an always-on `ant beta:worker poll` in a sandbox. A new one
|
|
1048
|
+
* (from the `agent` template) gets the environment key as a sandbox secret and egress limited to the Anthropic
|
|
1049
|
+
* API; an existing one (`sandboxId`) keeps its own secrets and egress (see HarnessSandboxOptions).
|
|
1050
|
+
*/
|
|
1051
|
+
startManagedAgentsWorker(options: ManagedAgentsWorkerOptions): Promise<Harness> {
|
|
1052
|
+
return startManagedAgentsWorker(this, options);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Claude Managed Agents, one sandbox per session: runs `ant beta:worker run` for a work item your WorkPoller
|
|
1057
|
+
* claimed (restore a prepared `snapshot` to boot the harness per session; `on_timeout: "pause"` freezes it
|
|
1058
|
+
* between turns).
|
|
1059
|
+
*/
|
|
1060
|
+
launchManagedAgentsSession(options: ManagedAgentsSessionOptions): Promise<Harness> {
|
|
1061
|
+
return launchManagedAgentsSession(this, options);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* A Codex exec-server registered as a remote environment (`codex exec-server --remote`), from inside a sandbox:
|
|
1066
|
+
* one outbound connection, no inbound port.
|
|
1067
|
+
*/
|
|
1068
|
+
startCodexExecServer(options: CodexExecServerOptions): Promise<Harness> {
|
|
1069
|
+
return startCodexExecServer(this, options);
|
|
1070
|
+
}
|
|
671
1071
|
}
|