@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.
Files changed (204) hide show
  1. package/README.md +171 -42
  2. package/dist/cjs/core/bytes.d.ts +30 -0
  3. package/dist/cjs/core/bytes.js +115 -0
  4. package/dist/cjs/core/bytes.js.map +1 -0
  5. package/dist/cjs/core/client.d.ts +61 -3
  6. package/dist/cjs/core/client.js +211 -33
  7. package/dist/cjs/core/client.js.map +1 -1
  8. package/dist/cjs/core/errors.d.ts +16 -4
  9. package/dist/cjs/core/errors.js +9 -6
  10. package/dist/cjs/core/errors.js.map +1 -1
  11. package/dist/cjs/core/handle.d.ts +31 -0
  12. package/dist/cjs/core/handle.js +86 -0
  13. package/dist/cjs/core/handle.js.map +1 -0
  14. package/dist/cjs/core/index.d.ts +6 -4
  15. package/dist/cjs/core/index.js +8 -1
  16. package/dist/cjs/core/index.js.map +1 -1
  17. package/dist/cjs/core/login.d.ts +24 -0
  18. package/dist/cjs/core/login.js +93 -0
  19. package/dist/cjs/core/login.js.map +1 -0
  20. package/dist/cjs/core/namespace.d.ts +1 -1
  21. package/dist/cjs/core/namespace.js +1 -1
  22. package/dist/cjs/core/op.d.ts +11 -1
  23. package/dist/cjs/core/timing.d.ts +1 -1
  24. package/dist/cjs/core/timing.js +8 -1
  25. package/dist/cjs/core/timing.js.map +1 -1
  26. package/dist/cjs/core/transport.js +1 -1
  27. package/dist/cjs/core/transport.js.map +1 -1
  28. package/dist/cjs/core/util.d.ts +15 -3
  29. package/dist/cjs/core/util.js +54 -2
  30. package/dist/cjs/core/util.js.map +1 -1
  31. package/dist/cjs/core/ws.d.ts +4 -0
  32. package/dist/cjs/core/ws.js +7 -4
  33. package/dist/cjs/core/ws.js.map +1 -1
  34. package/dist/cjs/generated/client.d.ts +2 -2
  35. package/dist/cjs/generated/client.js +2 -2
  36. package/dist/cjs/generated/errors.d.ts +1 -1
  37. package/dist/cjs/generated/errors.js +30 -0
  38. package/dist/cjs/generated/errors.js.map +1 -1
  39. package/dist/cjs/generated/jobs.js +1 -1
  40. package/dist/cjs/generated/ns/actions.d.ts +48 -6
  41. package/dist/cjs/generated/ns/actions.js +59 -6
  42. package/dist/cjs/generated/ns/actions.js.map +1 -1
  43. package/dist/cjs/generated/ns/infer.d.ts +185 -54
  44. package/dist/cjs/generated/ns/infer.js +28 -74
  45. package/dist/cjs/generated/ns/infer.js.map +1 -1
  46. package/dist/cjs/generated/ns/keys.d.ts +12 -0
  47. package/dist/cjs/generated/ns/keys.js +22 -0
  48. package/dist/cjs/generated/ns/keys.js.map +1 -1
  49. package/dist/cjs/generated/ns/render.d.ts +95 -6
  50. package/dist/cjs/generated/ns/render.js +124 -7
  51. package/dist/cjs/generated/ns/render.js.map +1 -1
  52. package/dist/cjs/generated/ns/requests.d.ts +3 -1
  53. package/dist/cjs/generated/ns/requests.js +3 -1
  54. package/dist/cjs/generated/ns/requests.js.map +1 -1
  55. package/dist/cjs/generated/ns/routines.d.ts +131 -9
  56. package/dist/cjs/generated/ns/routines.js +186 -9
  57. package/dist/cjs/generated/ns/routines.js.map +1 -1
  58. package/dist/cjs/generated/ns/sandboxes.d.ts +298 -31
  59. package/dist/cjs/generated/ns/sandboxes.js +368 -29
  60. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  61. package/dist/cjs/generated/ns/vision.d.ts +133 -14
  62. package/dist/cjs/generated/ns/vision.js +158 -12
  63. package/dist/cjs/generated/ns/vision.js.map +1 -1
  64. package/dist/cjs/generated/ns/webhooks.d.ts +8 -5
  65. package/dist/cjs/generated/ns/webhooks.js +8 -5
  66. package/dist/cjs/generated/ns/webhooks.js.map +1 -1
  67. package/dist/cjs/generated/types.d.ts +1956 -301
  68. package/dist/cjs/helpers/agents.d.ts +95 -0
  69. package/dist/cjs/helpers/agents.js +205 -0
  70. package/dist/cjs/helpers/agents.js.map +1 -0
  71. package/dist/cjs/helpers/render.d.ts +15 -0
  72. package/dist/cjs/helpers/render.js +74 -0
  73. package/dist/cjs/helpers/render.js.map +1 -0
  74. package/dist/cjs/helpers/routines.d.ts +61 -0
  75. package/dist/cjs/helpers/routines.js +234 -0
  76. package/dist/cjs/helpers/routines.js.map +1 -0
  77. package/dist/cjs/helpers/sandboxes.d.ts +237 -0
  78. package/dist/cjs/helpers/sandboxes.js +608 -0
  79. package/dist/cjs/helpers/sandboxes.js.map +1 -0
  80. package/dist/cjs/index.d.ts +4 -1
  81. package/dist/cjs/index.js +8 -5
  82. package/dist/cjs/index.js.map +1 -1
  83. package/dist/cjs/routines.d.ts +1 -0
  84. package/dist/cjs/routines.js +21 -0
  85. package/dist/cjs/routines.js.map +1 -0
  86. package/dist/cjs/webhooks.js.map +1 -1
  87. package/dist/esm/core/bytes.d.ts +30 -0
  88. package/dist/esm/core/bytes.js +111 -0
  89. package/dist/esm/core/bytes.js.map +1 -0
  90. package/dist/esm/core/client.d.ts +61 -3
  91. package/dist/esm/core/client.js +208 -31
  92. package/dist/esm/core/client.js.map +1 -1
  93. package/dist/esm/core/errors.d.ts +16 -4
  94. package/dist/esm/core/errors.js +9 -6
  95. package/dist/esm/core/errors.js.map +1 -1
  96. package/dist/esm/core/handle.d.ts +31 -0
  97. package/dist/esm/core/handle.js +82 -0
  98. package/dist/esm/core/handle.js.map +1 -0
  99. package/dist/esm/core/index.d.ts +6 -4
  100. package/dist/esm/core/index.js +4 -2
  101. package/dist/esm/core/index.js.map +1 -1
  102. package/dist/esm/core/login.d.ts +24 -0
  103. package/dist/esm/core/login.js +85 -0
  104. package/dist/esm/core/login.js.map +1 -0
  105. package/dist/esm/core/namespace.d.ts +1 -1
  106. package/dist/esm/core/namespace.js +1 -1
  107. package/dist/esm/core/op.d.ts +11 -1
  108. package/dist/esm/core/timing.d.ts +1 -1
  109. package/dist/esm/core/timing.js +8 -1
  110. package/dist/esm/core/timing.js.map +1 -1
  111. package/dist/esm/core/transport.js +1 -1
  112. package/dist/esm/core/transport.js.map +1 -1
  113. package/dist/esm/core/util.d.ts +15 -3
  114. package/dist/esm/core/util.js +48 -1
  115. package/dist/esm/core/util.js.map +1 -1
  116. package/dist/esm/core/ws.d.ts +4 -0
  117. package/dist/esm/core/ws.js +7 -4
  118. package/dist/esm/core/ws.js.map +1 -1
  119. package/dist/esm/generated/client.d.ts +2 -2
  120. package/dist/esm/generated/client.js +2 -2
  121. package/dist/esm/generated/errors.d.ts +1 -1
  122. package/dist/esm/generated/errors.js +30 -0
  123. package/dist/esm/generated/errors.js.map +1 -1
  124. package/dist/esm/generated/jobs.js +1 -1
  125. package/dist/esm/generated/ns/actions.d.ts +48 -6
  126. package/dist/esm/generated/ns/actions.js +59 -6
  127. package/dist/esm/generated/ns/actions.js.map +1 -1
  128. package/dist/esm/generated/ns/infer.d.ts +185 -54
  129. package/dist/esm/generated/ns/infer.js +28 -74
  130. package/dist/esm/generated/ns/infer.js.map +1 -1
  131. package/dist/esm/generated/ns/keys.d.ts +12 -0
  132. package/dist/esm/generated/ns/keys.js +22 -0
  133. package/dist/esm/generated/ns/keys.js.map +1 -1
  134. package/dist/esm/generated/ns/render.d.ts +95 -6
  135. package/dist/esm/generated/ns/render.js +124 -7
  136. package/dist/esm/generated/ns/render.js.map +1 -1
  137. package/dist/esm/generated/ns/requests.d.ts +3 -1
  138. package/dist/esm/generated/ns/requests.js +3 -1
  139. package/dist/esm/generated/ns/requests.js.map +1 -1
  140. package/dist/esm/generated/ns/routines.d.ts +131 -9
  141. package/dist/esm/generated/ns/routines.js +186 -9
  142. package/dist/esm/generated/ns/routines.js.map +1 -1
  143. package/dist/esm/generated/ns/sandboxes.d.ts +298 -31
  144. package/dist/esm/generated/ns/sandboxes.js +368 -29
  145. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  146. package/dist/esm/generated/ns/vision.d.ts +133 -14
  147. package/dist/esm/generated/ns/vision.js +158 -12
  148. package/dist/esm/generated/ns/vision.js.map +1 -1
  149. package/dist/esm/generated/ns/webhooks.d.ts +8 -5
  150. package/dist/esm/generated/ns/webhooks.js +8 -5
  151. package/dist/esm/generated/ns/webhooks.js.map +1 -1
  152. package/dist/esm/generated/types.d.ts +1956 -301
  153. package/dist/esm/helpers/agents.d.ts +95 -0
  154. package/dist/esm/helpers/agents.js +199 -0
  155. package/dist/esm/helpers/agents.js.map +1 -0
  156. package/dist/esm/helpers/render.d.ts +15 -0
  157. package/dist/esm/helpers/render.js +70 -0
  158. package/dist/esm/helpers/render.js.map +1 -0
  159. package/dist/esm/helpers/routines.d.ts +61 -0
  160. package/dist/esm/helpers/routines.js +226 -0
  161. package/dist/esm/helpers/routines.js.map +1 -0
  162. package/dist/esm/helpers/sandboxes.d.ts +237 -0
  163. package/dist/esm/helpers/sandboxes.js +600 -0
  164. package/dist/esm/helpers/sandboxes.js.map +1 -0
  165. package/dist/esm/index.d.ts +4 -1
  166. package/dist/esm/index.js +6 -5
  167. package/dist/esm/index.js.map +1 -1
  168. package/dist/esm/routines.d.ts +1 -0
  169. package/dist/esm/routines.js +5 -0
  170. package/dist/esm/routines.js.map +1 -0
  171. package/dist/esm/webhooks.js.map +1 -1
  172. package/package.json +18 -7
  173. package/src/core/bytes.ts +112 -0
  174. package/src/core/client.ts +253 -33
  175. package/src/core/errors.ts +27 -10
  176. package/src/core/handle.ts +97 -0
  177. package/src/core/index.ts +7 -2
  178. package/src/core/login.ts +98 -0
  179. package/src/core/namespace.ts +1 -1
  180. package/src/core/op.ts +11 -1
  181. package/src/core/timing.ts +7 -2
  182. package/src/core/transport.ts +1 -1
  183. package/src/core/util.ts +53 -3
  184. package/src/core/ws.ts +11 -4
  185. package/src/generated/client.ts +2 -2
  186. package/src/generated/errors.ts +60 -0
  187. package/src/generated/jobs.ts +1 -1
  188. package/src/generated/ns/actions.ts +69 -6
  189. package/src/generated/ns/infer.ts +229 -61
  190. package/src/generated/ns/keys.ts +23 -0
  191. package/src/generated/ns/render.ts +152 -7
  192. package/src/generated/ns/requests.ts +3 -1
  193. package/src/generated/ns/routines.ts +205 -9
  194. package/src/generated/ns/sandboxes.ts +434 -34
  195. package/src/generated/ns/vision.ts +168 -14
  196. package/src/generated/ns/webhooks.ts +8 -5
  197. package/src/generated/types.ts +2211 -422
  198. package/src/helpers/agents.ts +300 -0
  199. package/src/helpers/render.ts +91 -0
  200. package/src/helpers/routines.ts +278 -0
  201. package/src/helpers/sandboxes.ts +788 -0
  202. package/src/index.ts +29 -5
  203. package/src/routines.ts +5 -0
  204. package/src/webhooks.ts +5 -1
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.SandboxesAPI = exports.sandboxesOps = void 0;
5
5
  const namespace_ts_1 = require("../../core/namespace.js");
6
6
  const ws_ts_1 = require("../../core/ws.js");
7
+ const agents_ts_1 = require("../../helpers/agents.js");
8
+ const sandboxes_ts_1 = require("../../helpers/sandboxes.js");
7
9
  const listSandboxesOp = {
8
10
  id: "sandboxesListSandboxes",
9
11
  method: "GET",
10
12
  path: "/v1/sandboxes",
13
+ deepObject: ["metadata"],
11
14
  timeoutMs: 10000,
12
15
  scope: "sandboxes:read",
13
16
  };
@@ -74,21 +77,42 @@ const getSandboxOp = {
74
77
  timeoutMs: 10000,
75
78
  scope: "sandboxes:read",
76
79
  };
80
+ const setEgressOp = {
81
+ id: "sandboxesSetEgress",
82
+ method: "POST",
83
+ path: "/v1/sandboxes/{sandbox_id}/egress",
84
+ params: ["sandbox_id"],
85
+ body: "json",
86
+ timeoutMs: 10000,
87
+ scope: "sandboxes:write",
88
+ };
77
89
  const execOp = {
78
90
  id: "sandboxesExec",
79
91
  method: "POST",
80
92
  path: "/v1/sandboxes/{sandbox_id}/exec",
81
93
  params: ["sandbox_id"],
82
94
  body: "json",
95
+ idem: true,
96
+ callerKey: true,
83
97
  stream: "sse",
84
98
  timeoutMs: 3600000,
85
99
  scope: "sandboxes:run",
86
100
  };
101
+ const deleteFileOp = {
102
+ id: "sandboxesDeleteFile",
103
+ method: "DELETE",
104
+ path: "/v1/sandboxes/{sandbox_id}/files",
105
+ params: ["sandbox_id"],
106
+ flags: ["recursive"],
107
+ timeoutMs: 60000,
108
+ scope: "sandboxes:run",
109
+ };
87
110
  const readFileOp = {
88
111
  id: "sandboxesReadFile",
89
112
  method: "GET",
90
113
  path: "/v1/sandboxes/{sandbox_id}/files",
91
114
  params: ["sandbox_id"],
115
+ flags: ["list"],
92
116
  timeoutMs: 60000,
93
117
  scope: "sandboxes:run",
94
118
  };
@@ -97,11 +121,38 @@ const writeFileOp = {
97
121
  method: "PUT",
98
122
  path: "/v1/sandboxes/{sandbox_id}/files",
99
123
  params: ["sandbox_id"],
124
+ flags: ["mkdir"],
100
125
  body: "bytes",
101
126
  contentType: "application/octet-stream",
102
127
  timeoutMs: 60000,
103
128
  scope: "sandboxes:run",
104
129
  };
130
+ const makeDirectoryOp = {
131
+ id: "sandboxesMakeDirectory",
132
+ method: "POST",
133
+ path: "/v1/sandboxes/{sandbox_id}/files/mkdir",
134
+ params: ["sandbox_id"],
135
+ body: "json",
136
+ timeoutMs: 30000,
137
+ scope: "sandboxes:run",
138
+ };
139
+ const moveFileOp = {
140
+ id: "sandboxesMoveFile",
141
+ method: "POST",
142
+ path: "/v1/sandboxes/{sandbox_id}/files/move",
143
+ params: ["sandbox_id"],
144
+ body: "json",
145
+ timeoutMs: 60000,
146
+ scope: "sandboxes:run",
147
+ };
148
+ const statFileOp = {
149
+ id: "sandboxesStatFile",
150
+ method: "GET",
151
+ path: "/v1/sandboxes/{sandbox_id}/files/stat",
152
+ params: ["sandbox_id"],
153
+ timeoutMs: 30000,
154
+ scope: "sandboxes:run",
155
+ };
105
156
  const forkSandboxOp = {
106
157
  id: "sandboxesForkSandbox",
107
158
  method: "POST",
@@ -110,7 +161,6 @@ const forkSandboxOp = {
110
161
  body: "json",
111
162
  idem: true,
112
163
  timeoutMs: 30000,
113
- stretch: true,
114
164
  scope: "sandboxes:write",
115
165
  };
116
166
  const streamLogsOp = {
@@ -165,6 +215,15 @@ const openPtyOp = {
165
215
  timeoutMs: 3600000,
166
216
  scope: "sandboxes:run",
167
217
  };
218
+ const waitReadyOp = {
219
+ id: "sandboxesWaitReady",
220
+ method: "POST",
221
+ path: "/v1/sandboxes/{sandbox_id}/ready",
222
+ params: ["sandbox_id"],
223
+ body: "json",
224
+ timeoutMs: 65000,
225
+ scope: "sandboxes:run",
226
+ };
168
227
  const resumeSandboxOp = {
169
228
  id: "sandboxesResumeSandbox",
170
229
  method: "POST",
@@ -220,9 +279,14 @@ exports.sandboxesOps = {
220
279
  getTemplate: getTemplateOp,
221
280
  deleteSandbox: deleteSandboxOp,
222
281
  getSandbox: getSandboxOp,
282
+ setEgress: setEgressOp,
223
283
  exec: execOp,
284
+ deleteFile: deleteFileOp,
224
285
  readFile: readFileOp,
225
286
  writeFile: writeFileOp,
287
+ makeDirectory: makeDirectoryOp,
288
+ moveFile: moveFileOp,
289
+ statFile: statFileOp,
226
290
  forkSandbox: forkSandboxOp,
227
291
  streamLogs: streamLogsOp,
228
292
  pauseSandbox: pauseSandboxOp,
@@ -230,6 +294,7 @@ exports.sandboxesOps = {
230
294
  listProcesses: listProcessesOp,
231
295
  killProcess: killProcessOp,
232
296
  openPty: openPtyOp,
297
+ waitReady: waitReadyOp,
233
298
  resumeSandbox: resumeSandboxOp,
234
299
  runCode: runCodeOp,
235
300
  createSnapshot: createSnapshotOp,
@@ -243,6 +308,10 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
243
308
  *
244
309
  * Lists sandboxes in this project, newest first, including stopped ones from the last 7 days.
245
310
  *
311
+ * `metadata[<key>]=<value>` (up to 4 pairs) keeps only sandboxes whose `metadata` holds every pair given, with
312
+ * exactly that value: `GET /v1/sandboxes?metadata[customer]=acme&metadata[ticket]=ENG-1423`. A sandbox whose
313
+ * create lost its answer (a dropped connection) is found this way by a tag it was created with.
314
+ *
246
315
  * `GET /v1/sandboxes` · scope `sandboxes:read` · served by the node
247
316
  */
248
317
  listSandboxes(params, options) {
@@ -261,25 +330,83 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
261
330
  * explicitly. `api.spend_cap_usd` may not exceed your own spend cap, and `null` means your cap applies; scopes
262
331
  * or a cap beyond yours are refused with `403 forbidden`, `reason: scope_escalation`.
263
332
  *
333
+ * Code in a sandbox reaches other sandboxes through the sandboxes API only within its own sandbox's reach,
334
+ * except where this paragraph says. When it creates one (its `api` grant holds `sandboxes:write`), the new
335
+ * sandbox's `egress` defaults to the creating sandbox's own policy, and a policy that reaches further is
336
+ * refused with `403 forbidden`, `reason: egress_escalation`, as is a public port unless the creating sandbox's
337
+ * egress is `public` (restoring a snapshot and forking are bound the same way). Every operation that sends
338
+ * anything into another sandbox's microVM, to its guest or its ports, answers such code only for a sandbox
339
+ * within its reach: one whose egress is within its own sandbox's, where a sandbox with a public port or with
340
+ * a preview URL that may still serve counts as `public` (the internet reaches those ports whatever its egress),
341
+ * otherwise `403 forbidden`, `reason: egress_escalation`; and one whose `api` grant holds no scope and no
342
+ * connection its own lacks, otherwise `403 forbidden`, `reason: scope_escalation`. These operations are
343
+ * commands (buffered, streamed or in the background) and `run_code`, file reads, listings and writes, the
344
+ * process list, signals, logs, terminals, readiness probes it sets, and port previews (`POST
345
+ * …/ports/{port}/url` and the preview route itself, which the in-VM API also serves). Reach is checked when a
346
+ * call starts, and what stays open is cut when the change that takes the other sandbox out of the caller's
347
+ * reach is made (its egress is widened, a preview is minted for it, the calling sandbox's egress is narrowed or
348
+ * it stops), whether or not the caller is still reading: the node then drops the call's connection into the
349
+ * other sandbox, so the guest kills a buffered or streamed command (its process group) and hangs up a
350
+ * terminal's shell, and nothing either side sends after the change arrives. Data the other sandbox sent before
351
+ * the cut may still reach the caller from the node's buffers; then a buffered command or code run answers `403
352
+ * forbidden`, `reason: egress_escalation`, a streamed command ends with an `exec.exit` event carrying that
353
+ * error, log streams end, file reads end with an error and file writes answer that `403`, a terminal closes
354
+ * with code 1008, and a preview request or WebSocket is cut. What the caller already placed in the other
355
+ * sandbox stays there and no later change reaches it: background processes it started keep running, a readiness
356
+ * probe it set keeps probing, and files it wrote (including the part of a write that arrived before a cut)
357
+ * stay. The sandbox objects it reads carry no preview URL (`ports[].url` is `null`) for sandboxes beyond its
358
+ * reach. The control plane (get, list, pause, resume, timeout, snapshot, delete, waiting on a probe already
359
+ * set, and narrowing another sandbox's egress) is not bound this way, and neither are its own sandbox or
360
+ * templates. Other products reach the network on their own terms: a grant of their scopes (`vision:*`,
361
+ * `actions:*`, `infer:*`, ...) lets code in the sandbox send data out through them, so give a sandbox whose
362
+ * egress is `deny` none of those. Egress `deny` and `allowlist` stop network exfiltration, not timing channels:
363
+ * sandboxes on one node share physical CPU cores, the last-level cache, memory bandwidth and the storage path,
364
+ * so cooperating code in any two sandboxes on a node can signal each other at a low bit rate through CPU-cache,
365
+ * CPU-contention or storage timing (OpenAI described such channels between microVMs:
366
+ * https://openai.com/index/securing-our-frontier-model-training-environment/).
367
+ *
264
368
  * Inside the sandbox the environment also has `B3OS_API_URL=http://127.0.0.1:7700`, `B3OS_SANDBOX_ID`,
265
369
  * `B3OS_PROJECT` and `B3OS_PORT_BASE_PATH=/sbx/<host_id>`. `B3OS_PORT_BASE_PATH` is only the fixed start of
266
370
  * every port preview path on `usercontent.b3os.org`, not a full base path: the full prefix of a request,
267
371
  * `/sbx/<host_id>/<port>/<token>`, arrives with it in `X-Forwarded-Prefix` (`sandboxesProxyPortGet`).
268
372
  *
373
+ * When `api.scopes` include `infer:run` (named, or through `infer:*` or `*`), the environment also points the
374
+ * stock OpenAI and Anthropic SDKs at the node's models: `OPENAI_BASE_URL` and `ANTHROPIC_BASE_URL` are
375
+ * `http://127.0.0.1:7700/v1/infer`, `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` are the placeholder
376
+ * `b3os-sandbox` (the sandbox's grant authenticates the call and the key is ignored), and `B3OS_MODEL` names
377
+ * the node's default model (`b3os/qwen3.5-9b` in the beta). A value you set in `env` for any of them wins.
378
+ * Restores from a snapshot get the same, and forks keep their source's.
379
+ *
269
380
  * `timing` phases: `validate_ms`, then `claim_ms` and `resume_ms` for a pre-warmed microVM from the pool, or
270
381
  * `restore_ms` when none was parked (a restore on demand, or from a snapshot), then `bind_ms` (the identity
271
382
  * and environment reach the guest agent), and `total_ms`.
272
383
  *
273
384
  * A create that has started finishes even if the client disconnects before the response: the sandbox then
274
- * runs (and is billed) until its timeout or a delete, and `GET /v1/sandboxes` lists it with the `metadata`
275
- * it was created with. After a disconnect, look for it there before you retry: a retry is a new create, also
276
- * with the same `Idempotency-Key`, because the key is released when the client goes away before the
277
- * response. Fork, snapshot, pause and resume also finish after a disconnect.
385
+ * runs (and is billed) until its timeout or a delete. Its answer is stored under the `Idempotency-Key` (the
386
+ * SDKs send one), so a retry with that key gets the same sandbox with `Idempotent-Replayed: true`, or `409
387
+ * idempotency_request_in_progress` while the create still runs. Without a key a retry is a new create:
388
+ * `GET /v1/sandboxes` lists the first one with the `metadata` it was created with. Fork, snapshot, pause and
389
+ * resume also finish after a disconnect.
390
+ *
391
+ * A sandbox keeps running when the node's daemon restarts: its microVM runs outside the daemon, which adopts
392
+ * it again when it starts (its processes, files and environment are untouched). Connections that go through
393
+ * the daemon (streamed execs, PTY sessions, log streams, port preview connections, the sandbox's outbound
394
+ * connections and its calls to `http://127.0.0.1:7700`) drop at the restart and can be opened again.
395
+ *
396
+ * Disk: a sandbox's disk is its own copy-on-write copy of the template's (or snapshot's) disk; it is deleted
397
+ * when the sandbox ends and never given to another sandbox. The disks of an organization's running and paused
398
+ * sandboxes on a node add up to at most `sandboxes.disk_total_max` (each sandbox counting its `disk_gib`;
399
+ * beta: `sandboxes.concurrent` times `sandboxes.disk_max`, 160 GiB, so at the beta limits it never refuses a
400
+ * create the concurrency limit allows); past it a create is refused with `422 limit_exceeded`. While the
401
+ * node's disk store is nearly full, creates are refused with `503 capacity_unavailable` and `Retry-After`.
402
+ *
403
+ * Returns the sandbox object (`SandboxInfo`). `create()` sends the same request and returns a `Sandbox`
404
+ * handle instead (`exec`, `files`, `ports`), which `await using` deletes when the scope ends.
278
405
  *
279
406
  * `POST /v1/sandboxes` · scope `sandboxes:write` · served by the node
280
407
  */
281
408
  createSandbox(body, options) {
282
- return this._client._call(createSandboxOp, { body }, options);
409
+ return (0, sandboxes_ts_1.createSandboxSafely)((b, o) => this._client._call(createSandboxOp, { body: b }, o), body, options, this._client.maxRetries);
283
410
  }
284
411
  /**
285
412
  * List snapshots
@@ -314,9 +441,10 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
314
441
  /**
315
442
  * List templates
316
443
  *
317
- * Lists the templates sandboxes can start from (`base`, `code-interpreter`, `agent`, and on nodes that build it
318
- * `browser`: Chrome already running in the snapshot, a VM-isolated browser with DevTools on port 9222) with their
319
- * contents and defaults.
444
+ * Lists the templates sandboxes can start from (`base`, `code-interpreter`, `agent`, and `browser` where a node
445
+ * builds it, which the beta node does not yet: Chrome already running in the snapshot, a VM-isolated browser
446
+ * with DevTools on port 9222) with their OS, runtimes, capabilities, defaults and `size_classes` (the sizes kept
447
+ * pre-warmed). It does not list a template's packages.
320
448
  *
321
449
  * `GET /v1/sandboxes/templates` · scope `sandboxes:read` · served by the node
322
450
  */
@@ -353,6 +481,26 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
353
481
  getSandbox(sandboxId, options) {
354
482
  return this._client._call(getSandboxOp, { path: [sandboxId] }, options);
355
483
  }
484
+ /**
485
+ * Change a sandbox's egress policy
486
+ *
487
+ * Replaces the sandbox's `egress` policy (mode and allow list) while it runs or is paused. New outbound
488
+ * connections and DNS answers follow the new policy at once, and open connections it does not allow (SOCKS5,
489
+ * HTTP CONNECT and transparently redirected TCP alike) are closed: under `allowlist`, a connection stays open
490
+ * only if the host name it was opened for is on the new list (one opened by address alone is closed); under
491
+ * `deny`, every connection closes. Private, loopback, tailnet and metadata addresses stay refused in every
492
+ * mode. A sandbox cannot change its own policy (its in-VM API gets `403 forbidden`, `reason: self`, whatever
493
+ * its grant); call from outside it. Code in a sandbox may only narrow another sandbox's policy, to one within
494
+ * both that sandbox's current policy and its own (otherwise `403 forbidden`, `reason: egress_escalation`). A
495
+ * change cuts the streams code in other sandboxes holds open into this sandbox, and those code in this sandbox
496
+ * holds into others, once their target is no longer within the caller's reach (`sandboxesCreateSandbox`); the
497
+ * processes and files such code placed stay.
498
+ *
499
+ * `POST /v1/sandboxes/{sandbox_id}/egress` · scope `sandboxes:write` · served by the node
500
+ */
501
+ setEgress(sandboxId, body, options) {
502
+ return this._client._call(setEgressOp, { path: [sandboxId], body }, options);
503
+ }
356
504
  exec(sandboxId, body, options = {}) {
357
505
  if (options.stream) {
358
506
  return this._client._postStream(execOp, { path: [sandboxId], body }, options, {
@@ -362,8 +510,23 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
362
510
  }
363
511
  return this._client._call(execOp, { path: [sandboxId], body }, options);
364
512
  }
513
+ /**
514
+ * Delete a file or directory
515
+ *
516
+ * Deletes the file, symlink or empty directory at `path`; with `recursive=1`, a directory and everything in
517
+ * it. A symlink is deleted itself, never its target, and a recursive delete removes the symlinks it finds
518
+ * without following them. A path that is `/` or ends in `.` or `..` is refused, as `rm` refuses it. A
519
+ * recursive delete of a large tree goes on inside the sandbox to its end even when the answer times out.
520
+ * Sandboxes whose template image predates this operation answer `409 guest_outdated`; `rm` through
521
+ * `sandboxesExec` works there.
522
+ *
523
+ * `DELETE /v1/sandboxes/{sandbox_id}/files` · scope `sandboxes:run` · served by the node
524
+ */
525
+ deleteFile(sandboxId, params, options) {
526
+ return this._client._call(deleteFileOp, { path: [sandboxId], query: params }, options);
527
+ }
365
528
  readFile(sandboxId, params, options) {
366
- return params.list === 1
529
+ return params.list === true || params.list === 1
367
530
  ? this._client._call(readFileOp, { path: [sandboxId], query: params }, options, "application/json", "json")
368
531
  : this._client._call(readFileOp, { path: [sandboxId], query: params }, options, "application/octet-stream", "bytes");
369
532
  }
@@ -371,27 +534,71 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
371
534
  * Write a file
372
535
  *
373
536
  * Writes the request body to `path`, replacing any existing file, creating parent directories with `mkdir=1`.
374
- * Returns the file's entry. Up to 64 MiB per request.
537
+ * Returns the file's entry. Up to 64 MiB per request. The file is written as the body arrives, so a write that
538
+ * fails part-way leaves the part that arrived. From inside another sandbox, a write still streaming when this
539
+ * sandbox leaves the caller's reach is cut: nothing sent after that is written, and the answer is `403
540
+ * forbidden`, `reason: egress_escalation` (`sandboxesCreateSandbox`).
375
541
  *
376
542
  * `PUT /v1/sandboxes/{sandbox_id}/files` · scope `sandboxes:run` · served by the node
377
543
  */
378
544
  writeFile(sandboxId, params, data, options) {
379
545
  return this._client._call(writeFileOp, { path: [sandboxId], query: params, body: data }, options);
380
546
  }
547
+ /**
548
+ * Create a directory
549
+ *
550
+ * Creates the directory at `path` with `mode`, and any missing parents, like `mkdir -p`; each new directory
551
+ * is owned like the one it is made in. Answers `201` with the entry when it created the directory and `200`
552
+ * when a directory (or a symlink to one) was already there; a file at `path` is `409 file_exists`. Sandboxes
553
+ * whose template image predates this operation answer `409 guest_outdated`.
554
+ *
555
+ * `POST /v1/sandboxes/{sandbox_id}/files/mkdir` · scope `sandboxes:run` · served by the node
556
+ */
557
+ makeDirectory(sandboxId, body, options) {
558
+ return this._client._call(makeDirectoryOp, { path: [sandboxId], body }, options);
559
+ }
560
+ /**
561
+ * Move or rename a file or directory
562
+ *
563
+ * Moves `from` to `to` and returns the entry at `to`. An existing `to` is kept and the move refused with
564
+ * `409 file_exists` unless `overwrite` is true; a directory replaces only an empty directory. The directory
565
+ * `to` goes in must exist. Across filesystems inside the sandbox (from `/tmp` to `/workspace`, say) a
566
+ * regular file is copied and its source removed; a directory is refused there. Sandboxes whose template
567
+ * image predates this operation answer `409 guest_outdated`.
568
+ *
569
+ * `POST /v1/sandboxes/{sandbox_id}/files/move` · scope `sandboxes:run` · served by the node
570
+ */
571
+ moveFile(sandboxId, body, options) {
572
+ return this._client._call(moveFileOp, { path: [sandboxId], body }, options);
573
+ }
574
+ /**
575
+ * Describe a file or directory
576
+ *
577
+ * Returns the entry at `path` without reading it: a directory's own entry (where `list=1` on
578
+ * `sandboxesReadFile` lists what is in it), and a symlink as a symlink with its `target`. Sandboxes whose
579
+ * template image predates this operation answer `409 guest_outdated`.
580
+ *
581
+ * `GET /v1/sandboxes/{sandbox_id}/files/stat` · scope `sandboxes:run` · served by the node
582
+ */
583
+ statFile(sandboxId, params, options) {
584
+ return this._client._call(statFileOp, { path: [sandboxId], query: params }, options);
585
+ }
381
586
  /**
382
587
  * Fork a sandbox
383
588
  *
384
589
  * Creates `count` new running sandboxes that share the source's memory and disk copy-on-write, each with a fresh
385
- * identity (its own id, entropy, machine ID and clock; the source's environment, secrets, files and running
386
- * processes carry over). The source must have been created with `forkable: true` (forkable sandboxes are
387
- * restored for themselves rather than claimed from a pool, and track the pages they change); forks are
388
- * forkable too. The source pauses while its changed memory is written (`pause`, `base`, `snapshot`, `export`
389
- * phases in `Server-Timing`), then runs on; like a snapshot this resets its open connections to the outside.
390
- * Each fork counts against your sandbox concurrency.
590
+ * identity (its own id, kernel entropy, machine ID, hostname and clock; the source's environment, secrets, files
591
+ * and running processes carry over, the processes with their in-memory random state, except that the `browser`
592
+ * template's Chrome is reset unless `clone_reset` is `none`, see below). The source must have been created with
593
+ * `forkable: true` (forkable sandboxes are restored for themselves rather than claimed from a pool, and track
594
+ * the pages they change); forks are forkable too. The source pauses while its changed memory is written
595
+ * (`pause`, `base`, `snapshot`, `export` phases in `Server-Timing`), then runs on; like a snapshot this resets
596
+ * its open connections to the outside.
597
+ * Each fork counts against your sandbox concurrency and, with the source's `disk_gib`, against
598
+ * `sandboxes.disk_total_max` (`422 limit_exceeded`). While the node's snapshot or disk store is nearly full,
599
+ * forks are refused with `503 capacity_unavailable`.
391
600
  *
392
601
  * `POST /v1/sandboxes/{sandbox_id}/fork` · scope `sandboxes:write` · served by the node
393
- *
394
- * Stretch: in the contract, but may answer `501 not_implemented` on this deployment.
395
602
  */
396
603
  forkSandbox(sandboxId, body, options) {
397
604
  return this._client._call(forkSandboxOp, { path: [sandboxId], body }, options);
@@ -402,6 +609,8 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
402
609
  * Server-sent events with the output of background processes: `log.stdout` and `log.stderr` per chunk and
403
610
  * `process.exited` when one ends. Starts with up to 1 MiB of buffered output per process, then follows new
404
611
  * output until the sandbox stops (or immediately ends with `follow=false`). Filter to one process with `pid`.
612
+ * From inside another sandbox (or on a ticket minted there), the stream ends if this sandbox leaves the
613
+ * caller's reach (`sandboxesCreateSandbox`).
405
614
  * Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`
406
615
  * (`?ticket=`, for `EventSource`).
407
616
  *
@@ -416,9 +625,17 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
416
625
  /**
417
626
  * Pause a sandbox
418
627
  *
419
- * Freezes the sandbox's vCPUs and keeps its memory and disk on the node. A paused sandbox bills no CPU time
420
- * and still counts allocated memory; it still expires at `expires_at`. Resume continues exactly where it
421
- * stopped. Pausing a paused sandbox returns it unchanged.
628
+ * Freezes the sandbox's vCPUs and keeps its memory and disk on the node. A paused sandbox bills nothing:
629
+ * `sandboxes.vcpu_ms` counts CPU used and `sandboxes.gib_ms` counts memory only while the sandbox runs. It
630
+ * still counts toward `sandboxes.concurrent` and still expires at `expires_at`. Resume continues exactly
631
+ * where it stopped; connections that were open across the pause (the guest's outbound TCP, port preview
632
+ * WebSockets, PTY sessions) keep working. Pausing a paused sandbox returns it unchanged.
633
+ *
634
+ * A workflow that holds a sandbox across a long wait (a routine's `wait` or `sleep` step) pauses it and
635
+ * resumes it before its next exec, so the wait bills no sandbox time.
636
+ *
637
+ * `timing` phases: `admit` (from the request head to the VMM call: middleware, lookup, the sandbox's operation
638
+ * lock and the memory meter), `pause` (the VMM freezing the vCPUs) and `record` (the new status recorded).
422
639
  *
423
640
  * `POST /v1/sandboxes/{sandbox_id}/pause` · scope `sandboxes:write` · served by the node
424
641
  */
@@ -434,7 +651,18 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
434
651
  * then, with no cookie or other credential. For a public port the response is the sandbox's long-lived URL
435
652
  * (`ports[].url`) and `ttl_s` is ignored. The port must be declared in `ports` when the sandbox is created. The
436
653
  * app sees the URL's base path in `X-Forwarded-Prefix` on every request (token format and forwarding:
437
- * `sandboxesProxyPortGet`).
654
+ * `sandboxesProxyPortGet`). Code in a sandbox gets a URL only for its own sandbox and sandboxes within its reach
655
+ * (otherwise `403 forbidden`, `reason: egress_escalation` or `scope_escalation`; `sandboxesCreateSandbox`): a
656
+ * preview carries requests to the port, so it would reach as far as that sandbox. Anyone with the URL reaches
657
+ * the port, so from the first mint until the token's expiry plus an hour the sandbox counts as `public` egress
658
+ * to code in other sandboxes; every request let in on the token has ended by then (at most an hour after it was
659
+ * let in, its request body included, and never past the token's expiry plus an hour: `sandboxesProxyPortGet`).
660
+ * A mint therefore takes the sandbox out of the reach of code in sandboxes whose egress is not `public` and
661
+ * cuts the streams such code holds open into it, and such code gets no further URL for it. Such code may mint
662
+ * the first URL while the sandbox is within its reach, but it can use that URL only through the usercontent
663
+ * origin, which its egress must let it reach (the in-VM preview route refuses it). An `allowlist` that names
664
+ * the usercontent origin reaches every preview URL its code learns, of any sandbox, so in practice it counts as
665
+ * `public`.
438
666
  *
439
667
  * `POST /v1/sandboxes/{sandbox_id}/ports/{port}/url` · scope `sandboxes:run` · served by the node
440
668
  */
@@ -467,7 +695,21 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
467
695
  * Opens a WebSocket attached to a new pseudo-terminal running the user's login shell (or `cmd`). Binary frames
468
696
  * carry terminal bytes in both directions. Text frames carry JSON control messages: send
469
697
  * `{"type": "resize", "cols": 120, "rows": 40}`; the server sends `{"type": "exit", "code": 0}` before it closes.
470
- * Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`.
698
+ * Authenticate with the `Authorization` header or a ticket from `POST /v1/sandboxes/{sandbox_id}/ticket`. From
699
+ * inside another sandbox (or on a ticket minted there), the terminal closes with code 1008, reason
700
+ * `egress_escalation`, if this sandbox leaves the caller's reach (`sandboxesCreateSandbox`); input sent after
701
+ * that is not delivered, and the shell is hung up.
702
+ *
703
+ * With `session=new` the terminal can outlive its socket: the server's first frame is
704
+ * `{"type": "session", "id": "pts_...", "resumed": false}`. If the socket closes while the shell is still
705
+ * running (a page reload, a dropped network), the shell keeps running for 5 minutes and its last 128 KiB of
706
+ * output are kept. `session=<id>` on the same sandbox attaches to it again: the first frame says
707
+ * `"resumed": true`, a binary frame replays the kept output from its first whole line, and the terminal takes
708
+ * the new `cols` and `rows`. A second socket on a session takes it over, and the first closes with code 4001,
709
+ * reason `attached_elsewhere`. An id that is unknown, expired or another sandbox's opens a new terminal
710
+ * (`"resumed": false`, a new id). Send `{"type": "end"}` to hang a kept terminal up at once instead of leaving
711
+ * it to expire. Without `session` the shell is hung up when the socket closes. From inside another sandbox
712
+ * `session` is ignored.
471
713
  *
472
714
  * `GET /v1/sandboxes/{sandbox_id}/pty` · scope `sandboxes:run` · served by the node
473
715
  */
@@ -475,6 +717,31 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
475
717
  const { url, protocols } = await (0, ws_ts_1.ticketedUrl)(this._client, openPtyOp, createTicketOp, { path: [sandboxId], query: params }, options, false);
476
718
  return new ws_ts_1.PtySession(await (0, ws_ts_1.openSocket)(url, protocols, options.signal));
477
719
  }
720
+ /**
721
+ * Wait until a sandbox is ready
722
+ *
723
+ * Waits up to `wait_ms` for the sandbox's readiness probe (`readiness` on create) to pass, and answers with
724
+ * its state: `ready` (with `time_to_ready_ms`, from the create's start to the first passing try), `failed`
725
+ * (it did not pass within its `timeout_s`), or `pending` when `wait_ms` ran out first (call again). With
726
+ * `port` or `cmd` in the body the call sets that probe first, replacing the sandbox's earlier one, so a
727
+ * client can start a server with an exec and then wait for its port in one more call. The SDKs'
728
+ * `waitUntilReady` (`wait_until_ready`) is a different wait: the client runs its probes through exec, and it
729
+ * also takes HTTP-status and log-line probes. A sandbox with no probe, and none in the body, is `400`.
730
+ * Probes run inside the
731
+ * sandbox (a connection to `127.0.0.1:<port>`, or the command) and bill like any other use of it. From inside
732
+ * another sandbox, setting a probe needs this sandbox to be within the caller's reach
733
+ * (`sandboxesCreateSandbox`; otherwise `403 forbidden`, `reason: egress_escalation` or `scope_escalation`);
734
+ * waiting on the probe already set does not. A probe set that way keeps probing if this sandbox later leaves
735
+ * the caller's reach.
736
+ *
737
+ * The node runs the probe: the sandbox's `readiness`, or `port` or `cmd` in the body. `waitUntilReady()`
738
+ * probes from this client instead and also takes HTTP-status and log-line probes.
739
+ *
740
+ * `POST /v1/sandboxes/{sandbox_id}/ready` · scope `sandboxes:run` · served by the node
741
+ */
742
+ waitReady(sandboxId, body, options) {
743
+ return this._client._call(waitReadyOp, { path: [sandboxId], body }, options);
744
+ }
478
745
  /**
479
746
  * Resume a sandbox
480
747
  *
@@ -482,6 +749,9 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
482
749
  * running sandbox returns it unchanged. A resumed sandbox is billed again (`sandboxes.gib_ms`), so a resume is
483
750
  * admitted like a create (credits, spend cap).
484
751
  *
752
+ * `timing` phases: `admit`, `resume` (the VMM running the vCPUs again) and `record`, as for pause. A resume
753
+ * costs more the longer the sandbox stayed paused (the measured numbers are on the benchmarks page).
754
+ *
485
755
  * `POST /v1/sandboxes/{sandbox_id}/resume` · scope `sandboxes:write` · served by the node
486
756
  */
487
757
  resumeSandbox(sandboxId, options) {
@@ -492,7 +762,8 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
492
762
  *
493
763
  * Runs code in the sandbox's Jupyter kernel and returns its rich results (text, images, HTML, JSON), output
494
764
  * and any error. State persists between calls, like cells in a notebook. Needs a sandbox created from the
495
- * `code-interpreter` template.
765
+ * `code-interpreter` template. From inside another sandbox, a run is cut if this sandbox leaves the caller's
766
+ * reach before it answers (`403 forbidden`, `reason: egress_escalation`; `sandboxesCreateSandbox`).
496
767
  *
497
768
  * `POST /v1/sandboxes/{sandbox_id}/run_code` · scope `sandboxes:run` · served by the node
498
769
  */
@@ -503,10 +774,17 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
503
774
  * Snapshot a sandbox
504
775
  *
505
776
  * Saves the sandbox's memory and disk as a snapshot you can create new sandboxes from. The sandbox keeps
506
- * running (it pauses for the copy). New sandboxes restored from a snapshot get a fresh identity, so two of them
507
- * never share random state. Writing the snapshot resets the sandbox's open connections to the outside (open
508
- * PTY sessions, streaming execs and log streams, port preview connections, outbound TCP connections); new
509
- * ones work as soon as the call returns.
777
+ * running (it pauses for the copy). The call answers, and the snapshot is listed `ready`, only once its files
778
+ * are written to the node's disk (`sync` in `timing`); the sandbox runs again before that. Each sandbox
779
+ * restored from a snapshot gets fresh kernel entropy, a new machine ID and hostname and the current time, but
780
+ * the processes it brings back keep their memory, yours and the template's (Chrome, in the `browser`
781
+ * template): a random generator such a process held at the snapshot (a browser's or Node.js's `Math.random`,
782
+ * a TLS library's) starts in the same state in every one of them unless B3OS resets it. B3OS reseeds the code
783
+ * kernel's Python `random` module and NumPy global generator, and resets the `browser` template's Chrome by
784
+ * default (`clone_reset` on the create) where the node's image of that template has the reset. Start your own
785
+ * such processes after the restore or restart them. Writing the snapshot resets the sandbox's open connections
786
+ * to the outside (open PTY sessions, streaming execs and log streams, port preview connections, outbound TCP
787
+ * connections); new ones work as soon as the call returns.
510
788
  *
511
789
  * Snapshots are kept 7 days. An organization keeps at most `sandboxes.snapshots_max` snapshots (beta: 20)
512
790
  * per node, counting at most `sandboxes.snapshot_storage_max` (beta: 40 GiB). Each snapshot counts its
@@ -544,6 +822,67 @@ class SandboxesAPI extends namespace_ts_1.Namespace {
544
822
  setTimeout(sandboxId, body, options) {
545
823
  return this._client._call(setTimeoutOp, { path: [sandboxId], body }, options);
546
824
  }
825
+ /**
826
+ * Creates a sandbox (`POST /v1/sandboxes`, the same request as `createSandbox`) and returns its
827
+ * {@link Sandbox} handle: `exec`, `files`, `ports`, `snapshot`, `fork` and the lifecycle calls.
828
+ * `await using sbx = await b3os.sandboxes.create()` deletes it when the scope ends unless `sbx.detach()`.
829
+ * `createSandbox` sends the same request and returns only the object (`SandboxInfo`).
830
+ */
831
+ create(body, options) {
832
+ // The handle's ports.screenshot and ports.scrape use the client's render and vision namespaces.
833
+ const root = this._client;
834
+ const client = {
835
+ sandboxes: this,
836
+ get render() {
837
+ return root.render;
838
+ },
839
+ get vision() {
840
+ return root.vision;
841
+ },
842
+ };
843
+ return sandboxes_ts_1.Sandbox.create(client, body, options);
844
+ }
845
+ /**
846
+ * Waits until a sandbox is ready: a TCP port accepts connections (`{ port }`), an HTTP GET answers
847
+ * (`{ http }`), a command exits 0 (`{ exec }`) or a background process prints a line (`{ log, pid }`). The
848
+ * first probe runs at once, later ones back off from 25 to 250 ms; `timeoutMs` (default 60 s) bounds the
849
+ * wait, and `pid` fails it at once when that process exits. Resolves with the client-side time to ready.
850
+ * This client runs the probes through `exec`, and nothing is set on the sandbox; `waitReady` asks the node
851
+ * to probe instead (a port or a command, kept as the sandbox's readiness probe).
852
+ */
853
+ waitUntilReady(sandboxId, probe, options) {
854
+ return (0, sandboxes_ts_1.waitUntilReady)(this, sandboxId, probe, options);
855
+ }
856
+ /**
857
+ * Starts a background process (a dev server, a worker) and, with `ready`, waits until it is up; the process is
858
+ * stopped again when it exits or misses the deadline first. `previewPort` also mints its preview URL.
859
+ */
860
+ startService(sandboxId, options) {
861
+ return (0, sandboxes_ts_1.startService)(this, sandboxId, options);
862
+ }
863
+ /**
864
+ * Claude Managed Agents, self-hosted environment: an always-on `ant beta:worker poll` in a sandbox. A new one
865
+ * (from the `agent` template) gets the environment key as a sandbox secret and egress limited to the Anthropic
866
+ * API; an existing one (`sandboxId`) keeps its own secrets and egress (see HarnessSandboxOptions).
867
+ */
868
+ startManagedAgentsWorker(options) {
869
+ return (0, agents_ts_1.startManagedAgentsWorker)(this, options);
870
+ }
871
+ /**
872
+ * Claude Managed Agents, one sandbox per session: runs `ant beta:worker run` for a work item your WorkPoller
873
+ * claimed (restore a prepared `snapshot` to boot the harness per session; `on_timeout: "pause"` freezes it
874
+ * between turns).
875
+ */
876
+ launchManagedAgentsSession(options) {
877
+ return (0, agents_ts_1.launchManagedAgentsSession)(this, options);
878
+ }
879
+ /**
880
+ * A Codex exec-server registered as a remote environment (`codex exec-server --remote`), from inside a sandbox:
881
+ * one outbound connection, no inbound port.
882
+ */
883
+ startCodexExecServer(options) {
884
+ return (0, agents_ts_1.startCodexExecServer)(this, options);
885
+ }
547
886
  }
548
887
  exports.SandboxesAPI = SandboxesAPI;
549
888
  //# sourceMappingURL=sandboxes.js.map