@b3os/sdk 0.2.1 → 0.2.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 (146) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/core/util.d.ts +1 -1
  3. package/dist/cjs/core/util.js +1 -1
  4. package/dist/cjs/generated/client.d.ts +18 -0
  5. package/dist/cjs/generated/client.js +34 -0
  6. package/dist/cjs/generated/client.js.map +1 -1
  7. package/dist/cjs/generated/errors.d.ts +1 -1
  8. package/dist/cjs/generated/errors.js +120 -0
  9. package/dist/cjs/generated/errors.js.map +1 -1
  10. package/dist/cjs/generated/ids.d.ts +89 -0
  11. package/dist/cjs/generated/ids.js +22 -0
  12. package/dist/cjs/generated/ids.js.map +1 -1
  13. package/dist/cjs/generated/jobs.js +4 -0
  14. package/dist/cjs/generated/jobs.js.map +1 -1
  15. package/dist/cjs/generated/ns/actions.d.ts +267 -33
  16. package/dist/cjs/generated/ns/actions.js +375 -33
  17. package/dist/cjs/generated/ns/actions.js.map +1 -1
  18. package/dist/cjs/generated/ns/agents.d.ts +656 -0
  19. package/dist/cjs/generated/ns/agents.js +989 -0
  20. package/dist/cjs/generated/ns/agents.js.map +1 -0
  21. package/dist/cjs/generated/ns/images.d.ts +162 -0
  22. package/dist/cjs/generated/ns/images.js +246 -0
  23. package/dist/cjs/generated/ns/images.js.map +1 -0
  24. package/dist/cjs/generated/ns/infer.d.ts +71 -3
  25. package/dist/cjs/generated/ns/infer.js +98 -3
  26. package/dist/cjs/generated/ns/infer.js.map +1 -1
  27. package/dist/cjs/generated/ns/keys.d.ts +3 -1
  28. package/dist/cjs/generated/ns/keys.js +3 -1
  29. package/dist/cjs/generated/ns/keys.js.map +1 -1
  30. package/dist/cjs/generated/ns/listeners.d.ts +163 -0
  31. package/dist/cjs/generated/ns/listeners.js +268 -0
  32. package/dist/cjs/generated/ns/listeners.js.map +1 -0
  33. package/dist/cjs/generated/ns/orgs.d.ts +10 -0
  34. package/dist/cjs/generated/ns/orgs.js +26 -1
  35. package/dist/cjs/generated/ns/orgs.js.map +1 -1
  36. package/dist/cjs/generated/ns/projects.d.ts +32 -0
  37. package/dist/cjs/generated/ns/projects.js +66 -0
  38. package/dist/cjs/generated/ns/projects.js.map +1 -1
  39. package/dist/cjs/generated/ns/render.d.ts +192 -21
  40. package/dist/cjs/generated/ns/render.js +267 -24
  41. package/dist/cjs/generated/ns/render.js.map +1 -1
  42. package/dist/cjs/generated/ns/requests.d.ts +3 -1
  43. package/dist/cjs/generated/ns/requests.js +3 -1
  44. package/dist/cjs/generated/ns/requests.js.map +1 -1
  45. package/dist/cjs/generated/ns/routines.d.ts +22 -4
  46. package/dist/cjs/generated/ns/routines.js +22 -4
  47. package/dist/cjs/generated/ns/routines.js.map +1 -1
  48. package/dist/cjs/generated/ns/sandboxes.d.ts +431 -7
  49. package/dist/cjs/generated/ns/sandboxes.js +633 -6
  50. package/dist/cjs/generated/ns/sandboxes.js.map +1 -1
  51. package/dist/cjs/generated/ns/usage.d.ts +1 -1
  52. package/dist/cjs/generated/ns/usage.js +1 -1
  53. package/dist/cjs/generated/ns/vision.d.ts +113 -17
  54. package/dist/cjs/generated/ns/vision.js +152 -21
  55. package/dist/cjs/generated/ns/vision.js.map +1 -1
  56. package/dist/cjs/generated/ns/workspaces.d.ts +225 -0
  57. package/dist/cjs/generated/ns/workspaces.js +410 -0
  58. package/dist/cjs/generated/ns/workspaces.js.map +1 -0
  59. package/dist/cjs/generated/types.d.ts +5259 -605
  60. package/dist/cjs/helpers/sandboxes.d.ts +20 -1
  61. package/dist/cjs/helpers/sandboxes.js +13 -1
  62. package/dist/cjs/helpers/sandboxes.js.map +1 -1
  63. package/dist/esm/core/util.d.ts +1 -1
  64. package/dist/esm/core/util.js +1 -1
  65. package/dist/esm/generated/client.d.ts +18 -0
  66. package/dist/esm/generated/client.js +34 -0
  67. package/dist/esm/generated/client.js.map +1 -1
  68. package/dist/esm/generated/errors.d.ts +1 -1
  69. package/dist/esm/generated/errors.js +120 -0
  70. package/dist/esm/generated/errors.js.map +1 -1
  71. package/dist/esm/generated/ids.d.ts +89 -0
  72. package/dist/esm/generated/ids.js +22 -0
  73. package/dist/esm/generated/ids.js.map +1 -1
  74. package/dist/esm/generated/jobs.js +4 -0
  75. package/dist/esm/generated/jobs.js.map +1 -1
  76. package/dist/esm/generated/ns/actions.d.ts +267 -33
  77. package/dist/esm/generated/ns/actions.js +375 -33
  78. package/dist/esm/generated/ns/actions.js.map +1 -1
  79. package/dist/esm/generated/ns/agents.d.ts +656 -0
  80. package/dist/esm/generated/ns/agents.js +985 -0
  81. package/dist/esm/generated/ns/agents.js.map +1 -0
  82. package/dist/esm/generated/ns/images.d.ts +162 -0
  83. package/dist/esm/generated/ns/images.js +242 -0
  84. package/dist/esm/generated/ns/images.js.map +1 -0
  85. package/dist/esm/generated/ns/infer.d.ts +71 -3
  86. package/dist/esm/generated/ns/infer.js +98 -3
  87. package/dist/esm/generated/ns/infer.js.map +1 -1
  88. package/dist/esm/generated/ns/keys.d.ts +3 -1
  89. package/dist/esm/generated/ns/keys.js +3 -1
  90. package/dist/esm/generated/ns/keys.js.map +1 -1
  91. package/dist/esm/generated/ns/listeners.d.ts +163 -0
  92. package/dist/esm/generated/ns/listeners.js +264 -0
  93. package/dist/esm/generated/ns/listeners.js.map +1 -0
  94. package/dist/esm/generated/ns/orgs.d.ts +10 -0
  95. package/dist/esm/generated/ns/orgs.js +26 -1
  96. package/dist/esm/generated/ns/orgs.js.map +1 -1
  97. package/dist/esm/generated/ns/projects.d.ts +32 -0
  98. package/dist/esm/generated/ns/projects.js +66 -0
  99. package/dist/esm/generated/ns/projects.js.map +1 -1
  100. package/dist/esm/generated/ns/render.d.ts +192 -21
  101. package/dist/esm/generated/ns/render.js +267 -24
  102. package/dist/esm/generated/ns/render.js.map +1 -1
  103. package/dist/esm/generated/ns/requests.d.ts +3 -1
  104. package/dist/esm/generated/ns/requests.js +3 -1
  105. package/dist/esm/generated/ns/requests.js.map +1 -1
  106. package/dist/esm/generated/ns/routines.d.ts +22 -4
  107. package/dist/esm/generated/ns/routines.js +22 -4
  108. package/dist/esm/generated/ns/routines.js.map +1 -1
  109. package/dist/esm/generated/ns/sandboxes.d.ts +431 -7
  110. package/dist/esm/generated/ns/sandboxes.js +633 -6
  111. package/dist/esm/generated/ns/sandboxes.js.map +1 -1
  112. package/dist/esm/generated/ns/usage.d.ts +1 -1
  113. package/dist/esm/generated/ns/usage.js +1 -1
  114. package/dist/esm/generated/ns/vision.d.ts +113 -17
  115. package/dist/esm/generated/ns/vision.js +152 -21
  116. package/dist/esm/generated/ns/vision.js.map +1 -1
  117. package/dist/esm/generated/ns/workspaces.d.ts +225 -0
  118. package/dist/esm/generated/ns/workspaces.js +406 -0
  119. package/dist/esm/generated/ns/workspaces.js.map +1 -0
  120. package/dist/esm/generated/types.d.ts +5259 -605
  121. package/dist/esm/helpers/sandboxes.d.ts +20 -1
  122. package/dist/esm/helpers/sandboxes.js +13 -1
  123. package/dist/esm/helpers/sandboxes.js.map +1 -1
  124. package/package.json +1 -1
  125. package/src/core/util.ts +1 -1
  126. package/src/generated/client.ts +38 -0
  127. package/src/generated/errors.ts +240 -0
  128. package/src/generated/ids.ts +22 -0
  129. package/src/generated/jobs.ts +4 -0
  130. package/src/generated/ns/actions.ts +403 -33
  131. package/src/generated/ns/agents.ts +1102 -0
  132. package/src/generated/ns/images.ts +256 -0
  133. package/src/generated/ns/infer.ts +100 -3
  134. package/src/generated/ns/keys.ts +3 -1
  135. package/src/generated/ns/listeners.ts +300 -0
  136. package/src/generated/ns/orgs.ts +27 -1
  137. package/src/generated/ns/projects.ts +74 -0
  138. package/src/generated/ns/render.ts +277 -24
  139. package/src/generated/ns/requests.ts +3 -1
  140. package/src/generated/ns/routines.ts +22 -4
  141. package/src/generated/ns/sandboxes.ts +694 -7
  142. package/src/generated/ns/usage.ts +1 -1
  143. package/src/generated/ns/vision.ts +159 -21
  144. package/src/generated/ns/workspaces.ts +448 -0
  145. package/src/generated/types.ts +5684 -601
  146. package/src/helpers/sandboxes.ts +31 -2
@@ -1,9 +1,10 @@
1
1
  // Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
2
2
 
3
3
  import type { BinaryInput, RequestOptions, StreamOptions } from "../../core/client.ts";
4
+ import { isTerminalJobEvent } from "../../core/jobs.ts";
4
5
  import { Namespace } from "../../core/namespace.ts";
5
6
  import type { Op } from "../../core/op.ts";
6
- import type { APIPromise, ListPromise } from "../../core/promise.ts";
7
+ import type { APIPromise, JobPromise, ListPromise } from "../../core/promise.ts";
7
8
  import type { EventStream } from "../../core/sse.ts";
8
9
  import { openSocket, PtySession, ticketedUrl } from "../../core/ws.ts";
9
10
  import {
@@ -47,6 +48,13 @@ const createSandboxOp: Op = {
47
48
  timeoutMs: 30000,
48
49
  scope: "sandboxes:write",
49
50
  };
51
+ const getCapacityOp: Op = {
52
+ id: "sandboxesGetCapacity",
53
+ method: "GET",
54
+ path: "/v1/sandboxes/capacity",
55
+ timeoutMs: 10000,
56
+ scope: "sandboxes:read",
57
+ };
50
58
  const listSnapshotsOp: Op = {
51
59
  id: "sandboxesListSnapshots",
52
60
  method: "GET",
@@ -70,6 +78,46 @@ const getSnapshotOp: Op = {
70
78
  timeoutMs: 10000,
71
79
  scope: "sandboxes:read",
72
80
  };
81
+ const listSwarmsOp: Op = {
82
+ id: "sandboxesListSwarms",
83
+ method: "GET",
84
+ path: "/v1/sandboxes/swarms",
85
+ timeoutMs: 10000,
86
+ scope: "sandboxes:read",
87
+ };
88
+ const getSwarmOp: Op = {
89
+ id: "sandboxesGetSwarm",
90
+ method: "GET",
91
+ path: "/v1/sandboxes/swarms/{swarm_id}",
92
+ params: ["swarm_id"],
93
+ timeoutMs: 65000,
94
+ scope: "sandboxes:read",
95
+ };
96
+ const cancelSwarmOp: Op = {
97
+ id: "sandboxesCancelSwarm",
98
+ method: "POST",
99
+ path: "/v1/sandboxes/swarms/{swarm_id}/cancel",
100
+ params: ["swarm_id"],
101
+ timeoutMs: 10000,
102
+ scope: "sandboxes:write",
103
+ };
104
+ const listSwarmChildrenOp: Op = {
105
+ id: "sandboxesListSwarmChildren",
106
+ method: "GET",
107
+ path: "/v1/sandboxes/swarms/{swarm_id}/children",
108
+ params: ["swarm_id"],
109
+ timeoutMs: 10000,
110
+ scope: "sandboxes:read",
111
+ };
112
+ const swarmEventsOp: Op = {
113
+ id: "sandboxesSwarmEvents",
114
+ method: "GET",
115
+ path: "/v1/sandboxes/swarms/{swarm_id}/events",
116
+ params: ["swarm_id"],
117
+ stream: "sse",
118
+ timeoutMs: 3600000,
119
+ scope: "sandboxes:read",
120
+ };
73
121
  const listTemplatesOp: Op = {
74
122
  id: "sandboxesListTemplates",
75
123
  method: "GET",
@@ -77,6 +125,14 @@ const listTemplatesOp: Op = {
77
125
  timeoutMs: 10000,
78
126
  scope: "sandboxes:read",
79
127
  };
128
+ const createTemplateOp: Op = {
129
+ id: "sandboxesCreateTemplate",
130
+ method: "POST",
131
+ path: "/v1/sandboxes/templates",
132
+ body: "json",
133
+ timeoutMs: 30000,
134
+ scope: "sandboxes:write",
135
+ };
80
136
  const getTemplateOp: Op = {
81
137
  id: "sandboxesGetTemplate",
82
138
  method: "GET",
@@ -85,6 +141,63 @@ const getTemplateOp: Op = {
85
141
  timeoutMs: 10000,
86
142
  scope: "sandboxes:read",
87
143
  };
144
+ const listVolumesOp: Op = {
145
+ id: "sandboxesListVolumes",
146
+ method: "GET",
147
+ path: "/v1/sandboxes/volumes",
148
+ timeoutMs: 10000,
149
+ scope: "sandboxes:read",
150
+ };
151
+ const createVolumeOp: Op = {
152
+ id: "sandboxesCreateVolume",
153
+ method: "POST",
154
+ path: "/v1/sandboxes/volumes",
155
+ body: "json",
156
+ timeoutMs: 30000,
157
+ scope: "sandboxes:write",
158
+ };
159
+ const deleteVolumeOp: Op = {
160
+ id: "sandboxesDeleteVolume",
161
+ method: "DELETE",
162
+ path: "/v1/sandboxes/volumes/{volume_id}",
163
+ params: ["volume_id"],
164
+ timeoutMs: 10000,
165
+ scope: "sandboxes:write",
166
+ };
167
+ const getVolumeOp: Op = {
168
+ id: "sandboxesGetVolume",
169
+ method: "GET",
170
+ path: "/v1/sandboxes/volumes/{volume_id}",
171
+ params: ["volume_id"],
172
+ timeoutMs: 10000,
173
+ scope: "sandboxes:read",
174
+ };
175
+ const updateVolumeOp: Op = {
176
+ id: "sandboxesUpdateVolume",
177
+ method: "PATCH",
178
+ path: "/v1/sandboxes/volumes/{volume_id}",
179
+ params: ["volume_id"],
180
+ body: "json",
181
+ timeoutMs: 30000,
182
+ scope: "sandboxes:write",
183
+ };
184
+ const purgeVolumeOp: Op = {
185
+ id: "sandboxesPurgeVolume",
186
+ method: "POST",
187
+ path: "/v1/sandboxes/volumes/{volume_id}/purge",
188
+ params: ["volume_id"],
189
+ body: "json",
190
+ timeoutMs: 30000,
191
+ scope: "sandboxes:write",
192
+ };
193
+ const restoreVolumeOp: Op = {
194
+ id: "sandboxesRestoreVolume",
195
+ method: "POST",
196
+ path: "/v1/sandboxes/volumes/{volume_id}/restore",
197
+ params: ["volume_id"],
198
+ timeoutMs: 10000,
199
+ scope: "sandboxes:write",
200
+ };
88
201
  const deleteSandboxOp: Op = {
89
202
  id: "sandboxesDeleteSandbox",
90
203
  method: "DELETE",
@@ -101,6 +214,31 @@ const getSandboxOp: Op = {
101
214
  timeoutMs: 10000,
102
215
  scope: "sandboxes:read",
103
216
  };
217
+ const getComputerOp: Op = {
218
+ id: "sandboxesGetComputer",
219
+ method: "GET",
220
+ path: "/v1/sandboxes/{sandbox_id}/computer",
221
+ params: ["sandbox_id"],
222
+ timeoutMs: 15000,
223
+ scope: "sandboxes:read",
224
+ };
225
+ const computerActOp: Op = {
226
+ id: "sandboxesComputerAct",
227
+ method: "POST",
228
+ path: "/v1/sandboxes/{sandbox_id}/computer/actions",
229
+ params: ["sandbox_id"],
230
+ body: "json",
231
+ timeoutMs: 65000,
232
+ scope: "sandboxes:run",
233
+ };
234
+ const computerScreenshotOp: Op = {
235
+ id: "sandboxesComputerScreenshot",
236
+ method: "GET",
237
+ path: "/v1/sandboxes/{sandbox_id}/computer/screenshot",
238
+ params: ["sandbox_id"],
239
+ timeoutMs: 15000,
240
+ scope: "sandboxes:read",
241
+ };
104
242
  const setEgressOp: Op = {
105
243
  id: "sandboxesSetEgress",
106
244
  method: "POST",
@@ -187,6 +325,23 @@ const forkSandboxOp: Op = {
187
325
  timeoutMs: 30000,
188
326
  scope: "sandboxes:write",
189
327
  };
328
+ const releaseLeaseOp: Op = {
329
+ id: "sandboxesReleaseLease",
330
+ method: "DELETE",
331
+ path: "/v1/sandboxes/{sandbox_id}/lease",
332
+ params: ["sandbox_id"],
333
+ timeoutMs: 10000,
334
+ scope: "sandboxes:write",
335
+ };
336
+ const holdLeaseOp: Op = {
337
+ id: "sandboxesHoldLease",
338
+ method: "PUT",
339
+ path: "/v1/sandboxes/{sandbox_id}/lease",
340
+ params: ["sandbox_id"],
341
+ body: "json",
342
+ timeoutMs: 10000,
343
+ scope: "sandboxes:write",
344
+ };
190
345
  const streamLogsOp: Op = {
191
346
  id: "sandboxesStreamLogs",
192
347
  method: "GET",
@@ -204,6 +359,16 @@ const pauseSandboxOp: Op = {
204
359
  timeoutMs: 10000,
205
360
  scope: "sandboxes:write",
206
361
  };
362
+ const createPortHostOp: Op = {
363
+ id: "platformCreatePortHost",
364
+ method: "POST",
365
+ path: "/v1/sandboxes/{sandbox_id}/ports/{port}/host",
366
+ params: ["sandbox_id", "port"],
367
+ body: "json",
368
+ edge: true,
369
+ timeoutMs: 15000,
370
+ scope: "sandboxes:run",
371
+ };
207
372
  const createPortUrlOp: Op = {
208
373
  id: "sandboxesCreatePortUrl",
209
374
  method: "POST",
@@ -308,18 +473,47 @@ const setTimeoutOp: Op = {
308
473
  timeoutMs: 10000,
309
474
  scope: "sandboxes:write",
310
475
  };
476
+ const createSwarmOp: Op = {
477
+ id: "sandboxesCreateSwarm",
478
+ method: "POST",
479
+ path: "/v1/sandboxes/swarms",
480
+ body: "json",
481
+ idem: true,
482
+ stream: "sse",
483
+ timeoutMs: 3600000,
484
+ scope: "sandboxes:write",
485
+ job: { get: getSwarmOp, events: swarmEventsOp, cancel: cancelSwarmOp },
486
+ };
311
487
 
312
488
  /** Descriptors of every sandboxes operation, keyed by method name (for tooling and custom clients). */
313
489
  export const sandboxesOps = {
314
490
  listSandboxes: listSandboxesOp,
315
491
  createSandbox: createSandboxOp,
492
+ getCapacity: getCapacityOp,
316
493
  listSnapshots: listSnapshotsOp,
317
494
  deleteSnapshot: deleteSnapshotOp,
318
495
  getSnapshot: getSnapshotOp,
496
+ listSwarms: listSwarmsOp,
497
+ createSwarm: createSwarmOp,
498
+ getSwarm: getSwarmOp,
499
+ cancelSwarm: cancelSwarmOp,
500
+ listSwarmChildren: listSwarmChildrenOp,
501
+ swarmEvents: swarmEventsOp,
319
502
  listTemplates: listTemplatesOp,
503
+ createTemplate: createTemplateOp,
320
504
  getTemplate: getTemplateOp,
505
+ listVolumes: listVolumesOp,
506
+ createVolume: createVolumeOp,
507
+ deleteVolume: deleteVolumeOp,
508
+ getVolume: getVolumeOp,
509
+ updateVolume: updateVolumeOp,
510
+ purgeVolume: purgeVolumeOp,
511
+ restoreVolume: restoreVolumeOp,
321
512
  deleteSandbox: deleteSandboxOp,
322
513
  getSandbox: getSandboxOp,
514
+ getComputer: getComputerOp,
515
+ computerAct: computerActOp,
516
+ computerScreenshot: computerScreenshotOp,
323
517
  setEgress: setEgressOp,
324
518
  exec: execOp,
325
519
  deleteFile: deleteFileOp,
@@ -329,8 +523,11 @@ export const sandboxesOps = {
329
523
  moveFile: moveFileOp,
330
524
  statFile: statFileOp,
331
525
  forkSandbox: forkSandboxOp,
526
+ releaseLease: releaseLeaseOp,
527
+ holdLease: holdLeaseOp,
332
528
  streamLogs: streamLogsOp,
333
529
  pauseSandbox: pauseSandboxOp,
530
+ createPortHost: createPortHostOp,
334
531
  createPortUrl: createPortUrlOp,
335
532
  listProcesses: listProcessesOp,
336
533
  killProcess: killProcessOp,
@@ -355,6 +552,8 @@ export class SandboxesAPI extends Namespace {
355
552
  * `metadata[<key>]=<value>` (up to 4 pairs) keeps only sandboxes whose `metadata` holds every pair given, with
356
553
  * exactly that value: `GET /v1/sandboxes?metadata[customer]=acme&metadata[ticket]=ENG-1423`. A sandbox whose
357
554
  * create lost its answer (a dropped connection) is found this way by a tag it was created with.
555
+ * `owner=project&created_by_key=<key_id>` lists the services a key deployed, and `root=<sandbox_id>` the
556
+ * sandboxes one of them started.
358
557
  *
359
558
  * `GET /v1/sandboxes` · scope `sandboxes:read` · served by the node
360
559
  */
@@ -441,6 +640,14 @@ export class SandboxesAPI extends Namespace {
441
640
  * the daemon (streamed execs, PTY sessions, log streams, port preview connections, the sandbox's outbound
442
641
  * connections and its calls to `http://127.0.0.1:7700`) drop at the restart and can be opened again.
443
642
  *
643
+ * From an image (`image: "img_…"`, `POST /v1/images`): the sandbox restores the image's warm snapshot and
644
+ * has the image's size; a `vcpu` or `memory_mib` other than it answers `400 invalid_request`. `image` needs the
645
+ * `images.import` flag on for your organization (`404 feature_not_enabled` otherwise), answers `404
646
+ * image_not_found` for an image of another project and `409 image_not_ready` (with `current_status`) until the
647
+ * image is `ready`. `template: "tpl_…"` with the image's template ID works the same way without the flag (the
648
+ * template exists only once an import has run). Give `image` alone: with `template` or `snapshot` it answers
649
+ * `400 invalid_request`.
650
+ *
444
651
  * Disk: a sandbox's disk is its own copy-on-write copy of the template's (or snapshot's) disk; it is deleted
445
652
  * when the sandbox ends and never given to another sandbox. The disks of an organization's running and paused
446
653
  * sandboxes on a node add up to at most `sandboxes.disk_total_max` (each sandbox counting its `disk_gib`;
@@ -448,6 +655,12 @@ export class SandboxesAPI extends Namespace {
448
655
  * create the concurrency limit allows); past it a create is refused with `422 limit_exceeded`. While the
449
656
  * node's disk store is nearly full, creates are refused with `503 capacity_unavailable` and `Retry-After`.
450
657
  *
658
+ * Desktops: a sandbox of a template with the `computer` capability (`desktop`) also counts against
659
+ * `sandboxes.desktops_concurrent`, its running and paused sandboxes of such templates (forks included); past it
660
+ * a create or fork is refused with `429 concurrency_limited` and `Retry-After`, as past `sandboxes.concurrent`.
661
+ * Its environment has `DISPLAY=:1` (the desktop's X server) unless `env` sets `DISPLAY`, so commands reach the
662
+ * screen. `GET /v1/sandboxes/capacity` says how many more would be created now.
663
+ *
451
664
  * Returns the sandbox object (`SandboxInfo`). `create()` sends the same request and returns a `Sandbox`
452
665
  * handle instead (`exec`, `files`, `ports`), which `await using` deletes when the scope ends.
453
666
  *
@@ -462,6 +675,36 @@ export class SandboxesAPI extends Namespace {
462
675
  );
463
676
  }
464
677
 
678
+ /**
679
+ * Check room for more sandboxes
680
+ *
681
+ * How many more sandboxes of one template and size your organization could create on this node now, and
682
+ * which limit refuses the next one. Call it before a wave of creates instead of meeting `429` or `503`
683
+ * answers. The default shape is the `desktop` template at its default size; name another with `template`,
684
+ * `vcpu` and `memory_mib`.
685
+ *
686
+ * `room` is the least of three counts. `org` is `sandboxes.concurrent`: your running and paused sandboxes
687
+ * (and creates in flight) against the limit; paused sandboxes count, so delete the ones you are done with
688
+ * rather than leave them paused. `desktops` is `sandboxes.desktops_concurrent`, the running and paused
689
+ * sandboxes of templates with the `computer` capability; it counts toward `room` only when the template has
690
+ * that capability. `node` is this node: `parked` is how many sandboxes of the shape wait warm in its pool
691
+ * (a create claims one without a restore), and `room` is how many sandboxes of the shape the memory left
692
+ * under the node's microVM memory limit holds, each counting its `memory_mib` plus the node's per-microVM
693
+ * overhead, or `0` while the node's disk store is too full for new sandboxes. `node.room` is `null` when the
694
+ * node cannot read that limit, and then it does not count toward `room`.
695
+ *
696
+ * `binding` names the limit that refuses the next create (`org_concurrency`, `desktops` or `node`) when
697
+ * `room` is `0`, with `retry_after_s`, and is `null` while a create would pass. The answer is a reading, not
698
+ * a reservation: another create can take the room first. `sandboxes.disk_total_max` is left out (its beta
699
+ * default never refuses a create the concurrency limit allows). Behind the `sandboxes.desktop` feature flag:
700
+ * until it is on for your organization the operation answers `404 feature_not_enabled`.
701
+ *
702
+ * `GET /v1/sandboxes/capacity` · scope `sandboxes:read` · served by the node
703
+ */
704
+ getCapacity(params?: T.SandboxesGetCapacityParams, options?: RequestOptions): APIPromise<T.SandboxCapacity> {
705
+ return this._client._call<T.SandboxCapacity>(getCapacityOp, { query: params }, options);
706
+ }
707
+
465
708
  /**
466
709
  * List snapshots
467
710
  *
@@ -498,13 +741,131 @@ export class SandboxesAPI extends Namespace {
498
741
  return this._client._call<T.Snapshot>(getSnapshotOp, { path: [snapshotId] }, options);
499
742
  }
500
743
 
744
+ /**
745
+ * List swarms
746
+ *
747
+ * Lists swarms in this project, newest first, without their children (`GET /v1/sandboxes/swarms/{swarm_id}`
748
+ * returns them). Swarms are kept for 7 days after they finish.
749
+ *
750
+ * `GET /v1/sandboxes/swarms` · scope `sandboxes:read` · served by the node
751
+ */
752
+ listSwarms(params?: T.SandboxesListSwarmsParams, options?: RequestOptions): ListPromise<T.SwarmList, T.Swarm> {
753
+ return this._client._list<T.SwarmList, T.Swarm>(listSwarmsOp, { query: params }, options);
754
+ }
755
+
756
+ /**
757
+ * Start a swarm
758
+ *
759
+ * Forks one checkpoint into children, runs a command in each child, and gathers every child's exit code,
760
+ * output and timing. The checkpoint is a forkable sandbox (`from.sandbox`, running or paused) or a snapshot
761
+ * (`from.snapshot`). Each child is a new sandbox with a fresh identity, as a fork's or a restore's is: it keeps
762
+ * the checkpoint's environment, secrets, files, egress, ports and grant, and gets its own ID.
763
+ *
764
+ * Give the children one by one in `children` (at most `sandboxes.swarm_children_max`; a child's index is its
765
+ * position), or give `count` children that all run `defaults`. Each child's command runs as
766
+ * `POST /v1/sandboxes/{sandbox_id}/exec` would run it streamed, with `B3OS_SWARM_ID` and `B3OS_SWARM_INDEX`
767
+ * added to its environment, so one command can shard work by index. `env` is stored with the swarm's record
768
+ * for as long as it is kept: pass secrets as the checkpoint's `secrets`, never in `env`.
769
+ *
770
+ * A child whose sandbox would expire before its command's `timeout_ms` has passed gets a longer lifetime, the
771
+ * command's timeout plus 30 seconds, up to `sandboxes.timeout_max`.
772
+ *
773
+ * A child's non-zero exit is a result, not a failure of the swarm. The swarm `succeeded` once every child's
774
+ * command ended (exited, timed out, or could not run) or `stop_when` was met; it `failed` only when no child
775
+ * could start (the fork or restore failed) or the node restarted while it ran. With
776
+ * `stop_when: first_success`, the first child to exit 0 is `result.winner` and the other children's commands
777
+ * are killed (`canceled`). Each stream of output keeps its first `output_max_bytes` bytes, in the record and
778
+ * in the events.
779
+ *
780
+ * After its command ends a child is deleted, unless `keep` keeps it: `succeeded` keeps the children that
781
+ * exited 0, `all` keeps every child. A kept child is an ordinary sandbox that runs to its own `expires_at`,
782
+ * counts against `sandboxes.concurrent` and is billed until you delete it.
783
+ *
784
+ * All children are reserved at once, nothing started unless every one fits: past `sandboxes.concurrent` the
785
+ * answer is `429 concurrency_limited` with `Retry-After`, past `sandboxes.disk_total_max` `422 limit_exceeded`.
786
+ * An organization runs at most `sandboxes.swarms_running` swarms at a time (`422 limit_exceeded`). A sandbox checkpoint must have been created with `forkable: true` (`409 fork_unavailable`) and
787
+ * hold no volume (`409 volume_attached`). Creating a swarm needs `sandboxes:write` and also `sandboxes:run`.
788
+ * Swarms are listed for 7 days after they finish. Behind the `sandboxes.swarms` feature flag: until it is on
789
+ * for your organization every swarm operation answers `404 feature_not_enabled`.
790
+ *
791
+ * `POST /v1/sandboxes/swarms` · scope `sandboxes:write` · served by the node
792
+ */
793
+ createSwarm(body: T.SwarmCreateRequest, options?: RequestOptions): JobPromise<T.Swarm, T.SwarmEvent> {
794
+ return this._client._job<T.Swarm, T.SwarmEvent>(createSwarmOp, { body }, options);
795
+ }
796
+
797
+ /**
798
+ * Get a swarm
799
+ *
800
+ * Returns the swarm with its status, progress, result, timing and every child with its exit code, output and
801
+ * timing. While it runs, children that have not ended show `queued` or `running`. `?wait=` holds the answer
802
+ * until the swarm ends or the wait runs out.
803
+ *
804
+ * `GET /v1/sandboxes/swarms/{swarm_id}` · scope `sandboxes:read` · served by the node
805
+ */
806
+ getSwarm(swarmId: string, params?: T.SandboxesGetSwarmParams, options?: RequestOptions): APIPromise<T.Swarm> {
807
+ return this._client._call<T.Swarm>(getSwarmOp, { path: [swarmId], query: params }, options);
808
+ }
809
+
810
+ /**
811
+ * Cancel a swarm
812
+ *
813
+ * Stops the swarm: commands still running are killed and those children end `canceled`; each child is then
814
+ * deleted unless the swarm's `keep` keeps it (`all` keeps every child, `succeeded` the ones that exited 0).
815
+ * Returns the swarm with status `canceled`.
816
+ *
817
+ * `POST /v1/sandboxes/swarms/{swarm_id}/cancel` · scope `sandboxes:write` · served by the node
818
+ */
819
+ cancelSwarm(swarmId: string, options?: RequestOptions): APIPromise<T.Swarm> {
820
+ return this._client._call<T.Swarm>(cancelSwarmOp, { path: [swarmId] }, options);
821
+ }
822
+
823
+ /**
824
+ * List a swarm's children
825
+ *
826
+ * Lists the swarm's children by index, with each child's exit code, output and timing. Available while the swarm runs.
827
+ *
828
+ * `GET /v1/sandboxes/swarms/{swarm_id}/children` · scope `sandboxes:read` · served by the node
829
+ */
830
+ listSwarmChildren(
831
+ swarmId: string,
832
+ params?: T.SandboxesListSwarmChildrenParams,
833
+ options?: RequestOptions,
834
+ ): ListPromise<T.SwarmChildList, T.SwarmChild> {
835
+ return this._client._list<T.SwarmChildList, T.SwarmChild>(
836
+ listSwarmChildrenOp,
837
+ { path: [swarmId], query: params },
838
+ options,
839
+ );
840
+ }
841
+
842
+ /**
843
+ * Stream a swarm's events
844
+ *
845
+ * Server-sent events for the swarm: lifecycle events, `swarm.forked` with each child's sandbox ID, then
846
+ * `child.started`, `child.exited` or `child.failed` per child, and `child.stdout` and `child.stderr` when the
847
+ * swarm was created with `stream_output: true`. Ends after the terminal event. Reconnect with `Last-Event-ID`
848
+ * to resume. Events are kept with the swarm, so the stream reads the same, with the same `seq`, after the node
849
+ * restarts.
850
+ *
851
+ * `GET /v1/sandboxes/swarms/{swarm_id}/events` · scope `sandboxes:read` · served by the node
852
+ */
853
+ swarmEvents(swarmId: string, options?: StreamOptions): EventStream<T.SwarmEvent> {
854
+ return this._client._stream<T.SwarmEvent>(swarmEventsOp, { path: [swarmId] }, options, {
855
+ terminal: isTerminalJobEvent,
856
+ reconnectOnEnd: true,
857
+ });
858
+ }
859
+
501
860
  /**
502
861
  * List templates
503
862
  *
504
863
  * Lists the templates sandboxes can start from (`base`, `code-interpreter`, `agent`, and `browser` where a node
505
864
  * builds it, which the beta node does not yet: Chrome already running in the snapshot, a VM-isolated browser
506
865
  * with DevTools on port 9222) with their OS, runtimes, capabilities, defaults and `size_classes` (the sizes kept
507
- * pre-warmed). It does not list a template's packages.
866
+ * pre-warmed). It does not list a template's packages. The node's templates have `owner: node`; your project's
867
+ * imported images add their templates with `owner: project` and `image` set (`POST /v1/images`). Other
868
+ * projects' image templates are never listed, and getting one answers `404 template_not_found`.
508
869
  *
509
870
  * `GET /v1/sandboxes/templates` · scope `sandboxes:read` · served by the node
510
871
  */
@@ -512,10 +873,41 @@ export class SandboxesAPI extends Namespace {
512
873
  return this._client._call<T.TemplateList>(listTemplatesOp, {}, options);
513
874
  }
514
875
 
876
+ /**
877
+ * Create a template
878
+ *
879
+ * Makes a template for this project's sandboxes from a public OCI image (`image`, a reference) or from a
880
+ * Dockerfile build (`build`), with an optional `name` the project's creates start from:
881
+ * `POST /v1/sandboxes {"template": "py:3.11"}`. It takes the request `POST /v1/images` takes (with `image` in
882
+ * place of `ref`), and the template is that image's: one object, listed and deleted with `/v1/images`. The
883
+ * answer is the template's view: its `tpl_` ID (fixed from the start), `name`, `status` (the image's), `image`
884
+ * (the `img_` ID), `rootfs_sha256` once the image is flattened, and `key`. `202` for a new image, `200` for
885
+ * the project's image of the same request. Watch it with `GET /v1/images/{image_id}?wait=30` until `ready`;
886
+ * a create by name before then answers `409 image_not_ready`.
887
+ *
888
+ * A name is unique among the project's images (`409 image_name_taken`) and never a node template's
889
+ * (`422 image_name_reserved`). Another project's name answers `404 template_not_found`, as a template that
890
+ * does not exist. Behind the `images.build` flag (and `images.import`): until it is on for your organization
891
+ * the answer is `404 feature_not_enabled`. `503 product_unavailable` on a node without the images product.
892
+ *
893
+ * A private image names a registry connection in `auth`, as `POST /v1/images` does (`ImageRegistryAuth`): a
894
+ * vault connection of this project of type `basic` whose `hosts` list the registry and its token service.
895
+ * Using it also needs `vault:run` (`403` without it). Another project's connection, or one this credential may
896
+ * not use, answers `404 connection_not_found`; one that is not a registry connection for the image's registry,
897
+ * `422 image_auth_invalid`; a credential the registry refuses, `422 image_refused` with `reason: credentials`.
898
+ * The node reads the secret once, keeps it in memory for that one import and sends it only to the registry's
899
+ * token service: it is never logged, recorded or put in an error. A build takes no `auth`.
900
+ *
901
+ * `POST /v1/sandboxes/templates` · scope `sandboxes:write` · served by the node
902
+ */
903
+ createTemplate(body: T.TemplateCreateRequest, options?: RequestOptions): APIPromise<T.TemplateCreated> {
904
+ return this._client._call<T.TemplateCreated>(createTemplateOp, { body }, options);
905
+ }
906
+
515
907
  /**
516
908
  * Get a template
517
909
  *
518
- * Returns one template by name (`base`) or ID (`tpl_…`).
910
+ * Returns one template by name (`base`) or ID (`tpl_…`): a node template, or one of your project's image templates, by its ID or its image's `name`. Another project's image template answers `404 template_not_found`.
519
911
  *
520
912
  * `GET /v1/sandboxes/templates/{template}` · scope `sandboxes:read` · served by the node
521
913
  */
@@ -523,6 +915,94 @@ export class SandboxesAPI extends Namespace {
523
915
  return this._client._call<T.Template>(getTemplateOp, { path: [template] }, options);
524
916
  }
525
917
 
918
+ /**
919
+ * List volumes
920
+ *
921
+ * Lists the project's volumes on this node, newest first. Deleted volumes are listed only with `status=deleted`.
922
+ *
923
+ * `GET /v1/sandboxes/volumes` · scope `sandboxes:read` · served by the node
924
+ */
925
+ listVolumes(params?: T.SandboxesListVolumesParams, options?: RequestOptions): ListPromise<T.VolumeList, T.Volume> {
926
+ return this._client._list<T.VolumeList, T.Volume>(listVolumesOp, { query: params }, options);
927
+ }
928
+
929
+ /**
930
+ * Create a volume
931
+ *
932
+ * Creates an ext4 volume of `size_gib` on this node: data that outlives the sandboxes that mount it. Mount it
933
+ * in a sandbox with `volumes` on `POST /v1/sandboxes`; it is held by one running or paused sandbox at a time.
934
+ * Its blocks are allocated at once and reserved on the node's disk, so a full node disk cannot fail a write to
935
+ * it. Bills `sandboxes.volume_gib_h` (its size times the hours it exists, mounted or not) until it is deleted.
936
+ *
937
+ * In this beta a volume is one copy on the node's one drive: there is no backup, and it is not encrypted at
938
+ * rest, like every sandbox disk. Have the code that writes to it fsync what matters: what an app wrote and did
939
+ * not flush when its sandbox's microVM stopped without warning is lost.
940
+ *
941
+ * `POST /v1/sandboxes/volumes` · scope `sandboxes:write` · served by the node
942
+ */
943
+ createVolume(body: T.VolumeCreateRequest, options?: RequestOptions): APIPromise<T.Volume> {
944
+ return this._client._call<T.Volume>(createVolumeOp, { body }, options);
945
+ }
946
+
947
+ /**
948
+ * Delete a volume
949
+ *
950
+ * Marks the volume deleted: it is no longer listed or mounted, stops billing, and is purged (its data gone) at
951
+ * `purge_at`, 7 days later, unless you restore it first. Refused while a sandbox holds it (`409
952
+ * volume_attached`). Nothing else deletes a volume.
953
+ *
954
+ * `DELETE /v1/sandboxes/volumes/{volume_id}` · scope `sandboxes:write` · served by the node
955
+ */
956
+ deleteVolume(volumeId: string, options?: RequestOptions): APIPromise<T.Volume> {
957
+ return this._client._call<T.Volume>(deleteVolumeOp, { path: [volumeId] }, options);
958
+ }
959
+
960
+ /**
961
+ * Get a volume
962
+ *
963
+ * Returns a volume, deleted ones in their grace included.
964
+ *
965
+ * `GET /v1/sandboxes/volumes/{volume_id}` · scope `sandboxes:read` · served by the node
966
+ */
967
+ getVolume(volumeId: string, options?: RequestOptions): APIPromise<T.Volume> {
968
+ return this._client._call<T.Volume>(getVolumeOp, { path: [volumeId] }, options);
969
+ }
970
+
971
+ /**
972
+ * Grow a volume or change its metadata
973
+ *
974
+ * Replaces `metadata`, and grows the volume to `size_gib`. A volume grows only, and only while no sandbox
975
+ * holds it (`409 volume_attached`): its file system grows to the new size the next time a sandbox mounts it.
976
+ *
977
+ * `PATCH /v1/sandboxes/volumes/{volume_id}` · scope `sandboxes:write` · served by the node
978
+ */
979
+ updateVolume(volumeId: string, body?: T.VolumeUpdateRequest, options?: RequestOptions): APIPromise<T.Volume> {
980
+ return this._client._call<T.Volume>(updateVolumeOp, { path: [volumeId], body }, options);
981
+ }
982
+
983
+ /**
984
+ * Purge a volume now
985
+ *
986
+ * Removes the volume and its data now, deleted or not, without waiting for `purge_at`. `confirm` must be the
987
+ * volume's name. Refused while a sandbox holds it (`409 volume_attached`). This cannot be undone.
988
+ *
989
+ * `POST /v1/sandboxes/volumes/{volume_id}/purge` · scope `sandboxes:write` · served by the node
990
+ */
991
+ purgeVolume(volumeId: string, body: T.VolumePurgeRequest, options?: RequestOptions): APIPromise<T.Deleted> {
992
+ return this._client._call<T.Deleted>(purgeVolumeOp, { path: [volumeId], body }, options);
993
+ }
994
+
995
+ /**
996
+ * Restore a deleted volume
997
+ *
998
+ * A deleted volume whose `purge_at` has not passed is `available` again, with its data. A volume that is not deleted is returned as it is.
999
+ *
1000
+ * `POST /v1/sandboxes/volumes/{volume_id}/restore` · scope `sandboxes:write` · served by the node
1001
+ */
1002
+ restoreVolume(volumeId: string, options?: RequestOptions): APIPromise<T.Volume> {
1003
+ return this._client._call<T.Volume>(restoreVolumeOp, { path: [volumeId] }, options);
1004
+ }
1005
+
526
1006
  /**
527
1007
  * Delete a sandbox
528
1008
  *
@@ -545,6 +1025,96 @@ export class SandboxesAPI extends Namespace {
545
1025
  return this._client._call<T.Sandbox>(getSandboxOp, { path: [sandboxId] }, options);
546
1026
  }
547
1027
 
1028
+ /**
1029
+ * Read a desktop's screen size and pointer
1030
+ *
1031
+ * The screen size and the pointer position of a sandbox made from a template with the `computer`
1032
+ * capability (`desktop`), and who controls its input. `controller` is always `agent` for now. A sandbox of
1033
+ * another template answers `409 computer_unavailable`.
1034
+ *
1035
+ * A paused sandbox is resumed first when your key also has `sandboxes:write` (the scope of
1036
+ * `POST /v1/sandboxes/{sandbox_id}/resume`); without it the answer is `409 sandbox_not_running`. A paused
1037
+ * sandbox past its `expires_at` is not resumed: extend it with `POST /v1/sandboxes/{sandbox_id}/timeout` first.
1038
+ * `503 desktop_unavailable` means the desktop's screen and input server in the sandbox did not answer; it is
1039
+ * restarted within a few seconds of stopping. Behind the `sandboxes.desktop` feature flag: until it is on for
1040
+ * your organization the operation answers `404 feature_not_enabled`.
1041
+ *
1042
+ * `GET /v1/sandboxes/{sandbox_id}/computer` · scope `sandboxes:read` · served by the node
1043
+ */
1044
+ getComputer(sandboxId: string, options?: RequestOptions): APIPromise<T.Computer> {
1045
+ return this._client._call<T.Computer>(getComputerOp, { path: [sandboxId] }, options);
1046
+ }
1047
+
1048
+ /**
1049
+ * Send mouse and keyboard actions to a desktop
1050
+ *
1051
+ * Runs 1 to 32 mouse and keyboard actions in order on a sandbox made from a template with the `computer`
1052
+ * capability (`desktop`), then optionally waits for the screen to settle and takes a screenshot, all in one
1053
+ * call. Action names follow Anthropic's computer-use actions, so a harness maps them one to one. Coordinates
1054
+ * are screen pixels from the top left (`GET /v1/sandboxes/{sandbox_id}/computer` gives the screen size); an
1055
+ * action without `x` and `y` acts at the pointer. `type` types up to 8,192 bytes of UTF-8 text (newline and
1056
+ * tab included, other control characters refused); `key` presses a chord of xdotool key names
1057
+ * (`ctrl+shift+t`, `Return`, `alt+F4`); `key_down` and `key_up` hold and release one key; `wait` waits; the
1058
+ * waits of one call add up to at most 30,000 ms.
1059
+ *
1060
+ * The whole batch is checked before any input is sent: a bad action answers `400 invalid_request` naming it
1061
+ * (`actions[2]`), and nothing ran. Then each action gets a result in `results`, in order: `delivery` says
1062
+ * whether its input reached the X server (`delivered_unverified`: sent and synced; what the application did
1063
+ * with it is not checked) and `retry` whether sending it again is safe (`unsafe` once a click, text or a key
1064
+ * landed). An action that fails stops the batch; the actions after it are `not_delivered` with `retry:
1065
+ * safe`. Held buttons and keys are released when a batch fails part way.
1066
+ *
1067
+ * `screenshot` adds a screenshot after the actions (`{format, quality}`, the same as the screenshot
1068
+ * operation's query; `null` or left out: none). `settle` waits before the screenshot until the screen has
1069
+ * not changed for `quiet_ms` (80 by default), at most `max_ms` (1,000 by default); `settled_by` says which
1070
+ * ended the wait. `cursor` is where the pointer ended, `null` when the desktop's X server went away during
1071
+ * the batch (then `screenshot` is `null` too). A failed screenshot after the actions also leaves `screenshot`
1072
+ * `null` with the results intact.
1073
+ *
1074
+ * A paused sandbox is resumed first when your key also has `sandboxes:write`, as for
1075
+ * `GET /v1/sandboxes/{sandbox_id}/computer`; without it the answer is `409 sandbox_not_running`. A sandbox of
1076
+ * another template answers `409 computer_unavailable`. A `503` or `504` after the batch was sent to the
1077
+ * sandbox says so in its detail: some actions may have run, so take a screenshot before you send them again.
1078
+ * The node logs each action's name, its coordinates and the batch's timing, never typed text (its length
1079
+ * only), keys or screenshots. Behind the `sandboxes.desktop` feature flag: until it is on for your
1080
+ * organization the operation answers `404 feature_not_enabled`.
1081
+ *
1082
+ * `POST /v1/sandboxes/{sandbox_id}/computer/actions` · scope `sandboxes:run` · served by the node
1083
+ */
1084
+ computerAct(
1085
+ sandboxId: string,
1086
+ body: T.ComputerActRequest,
1087
+ options?: RequestOptions,
1088
+ ): APIPromise<T.ComputerActResult> {
1089
+ return this._client._call<T.ComputerActResult>(computerActOp, { path: [sandboxId], body }, options);
1090
+ }
1091
+
1092
+ /**
1093
+ * Take a screenshot of a desktop
1094
+ *
1095
+ * Captures the whole screen of a sandbox made from a template with the `computer` capability (`desktop`).
1096
+ * With `Accept: image/png` or `image/jpeg` (or `image/*`, `*\/*`, or no `Accept`) the answer is the image
1097
+ * bytes; with `Accept: application/json` it is `{format, width, height, data_base64}`, the shape of a vision
1098
+ * screenshot. `format` is `jpeg` (at `quality`, 80 by default) unless the query or `Accept` asks for `png`;
1099
+ * `quality` applies to JPEG only. `Server-Timing` has `capture` and `encode` (the time inside the sandbox),
1100
+ * `desk` (the round trip to it) and `resume` when a paused sandbox was resumed first.
1101
+ *
1102
+ * A paused sandbox is resumed first when your key also has `sandboxes:write`, as for
1103
+ * `GET /v1/sandboxes/{sandbox_id}/computer`; without it the answer is `409 sandbox_not_running`. A sandbox of
1104
+ * another template answers `409 computer_unavailable`. Screenshots are never logged or stored by the node.
1105
+ * Behind the `sandboxes.desktop` feature flag: until it is on for your organization the operation answers
1106
+ * `404 feature_not_enabled`.
1107
+ *
1108
+ * `GET /v1/sandboxes/{sandbox_id}/computer/screenshot` · scope `sandboxes:read` · served by the node
1109
+ */
1110
+ computerScreenshot(
1111
+ sandboxId: string,
1112
+ params?: T.SandboxesComputerScreenshotParams,
1113
+ options?: RequestOptions,
1114
+ ): APIPromise<T.ScreenshotData> {
1115
+ return this._client._call<T.ScreenshotData>(computerScreenshotOp, { path: [sandboxId], query: params }, options);
1116
+ }
1117
+
548
1118
  /**
549
1119
  * Change a sandbox's egress policy
550
1120
  *
@@ -581,6 +1151,24 @@ export class SandboxesAPI extends Namespace {
581
1151
  * one delivers the events queued before the cut and then ends with an `exec.exit` event whose `error` has
582
1152
  * `code: forbidden` and `reason: egress_escalation` and whose `duration_ms` runs to the cut.
583
1153
  *
1154
+ * With `background: true` and `restart`, the node supervises the process and starts the same command again in
1155
+ * the same sandbox when it exits: `on-failure` after an exit with a non-zero code or by a signal, `always` after
1156
+ * any exit. The first restart is at once; each further one in a row waits 1, 2, 4, 8, 16, 32 and then 60 s. A
1157
+ * run of at least 60 s resets the wait. Five exits within 300 s put the process in `crash_loop`: the node goes
1158
+ * on starting it, at most 60 s apart, for as long as the sandbox runs (a dependency that comes back heals it),
1159
+ * and a run of 60 s ends `crash_loop`. When the node restarts the process it first kills what is left of its process
1160
+ * group, for an exit it saw within 60 s of last seeing the process alive and while the pid is still that
1161
+ * process's (after a restart of the node itself it leaves the group alone and only starts the command again). A
1162
+ * signal sent from inside the sandbox (`kill -9`, `pkill`) counts as an exit and is restarted; a signal sent
1163
+ * with `POST …/processes/{pid}/kill` stops the supervision unless it asks to restart. The sandbox's
1164
+ * `supervised` list shows each supervised process: its current `pid`, `state`, `restarts` and `last_exit`.
1165
+ * A sandbox supervises at most 8 processes; a ninth `restart` is `400 invalid_request`, as is `restart`
1166
+ * without `background` or with `stdin`. The command, `cwd`, `env` and `user` are kept with the sandbox's
1167
+ * record on the node's disk for its restarts: pass secrets with the create's `secrets`, not on the command
1168
+ * line or in `env`. A fork, or a sandbox restored from a snapshot, supervises nothing: the processes it took
1169
+ * over run on unsupervised. Restarts pause while the node's own service restarts; a process that exited
1170
+ * then is started again once it is back.
1171
+ *
584
1172
  * `cmd` as a string runs through `/bin/sh -c`; as an array it is executed directly. Output is UTF-8 (invalid
585
1173
  * bytes become U+FFFD) and each stream is capped at 1 MiB in a buffered response.
586
1174
  *
@@ -753,7 +1341,8 @@ export class SandboxesAPI extends Namespace {
753
1341
  * `forkable: true` (forkable sandboxes are restored for themselves rather than claimed from a pool, and track
754
1342
  * the pages they change); forks are forkable too. The source pauses while its changed memory is written
755
1343
  * (`pause`, `base`, `snapshot`, `export` phases in `Server-Timing`), then runs on; like a snapshot this resets
756
- * its open connections to the outside.
1344
+ * its open connections to the outside. A paused source is resumed for the fork and paused again (`resume`
1345
+ * and `repause` phases), so a checkpoint can wait paused, billing neither meter, between forks.
757
1346
  * Each fork counts against your sandbox concurrency and, with the source's `disk_gib`, against
758
1347
  * `sandboxes.disk_total_max` (`422 limit_exceeded`). While the node's snapshot or disk store is nearly full,
759
1348
  * forks are refused with `503 capacity_unavailable`.
@@ -764,6 +1353,62 @@ export class SandboxesAPI extends Namespace {
764
1353
  return this._client._call<T.SandboxList>(forkSandboxOp, { path: [sandboxId], body }, options);
765
1354
  }
766
1355
 
1356
+ /**
1357
+ * Release a sandbox's lease
1358
+ *
1359
+ * Ends the sandbox's lease (`end_reason: released`). The sandbox keeps running until its current `expires_at`,
1360
+ * which you can still move with `POST /v1/sandboxes/{sandbox_id}/timeout`. Releasing a sandbox that holds no
1361
+ * lease, or one that has stopped, changes nothing and answers the sandbox. A sandbox's own credential cannot
1362
+ * release a lease (`403 forbidden`, `reason: sandbox`).
1363
+ *
1364
+ * `DELETE /v1/sandboxes/{sandbox_id}/lease` · scope `sandboxes:write` · served by the node
1365
+ */
1366
+ releaseLease(sandboxId: string, options?: RequestOptions): APIPromise<T.Sandbox> {
1367
+ return this._client._call<T.Sandbox>(releaseLeaseOp, { path: [sandboxId] }, options);
1368
+ }
1369
+
1370
+ /**
1371
+ * Keep a sandbox running under a lease
1372
+ *
1373
+ * Holds a lease on the sandbox under `key`, a name of your choosing (the deploy engine uses
1374
+ * `b3os:<app>/<service>`). While the lease is held and the sandbox runs, the node keeps it running past its
1375
+ * `timeout_s` and past `sandboxes.timeout_max`: whenever less than half of `sandboxes.lease_term` (900 s) is
1376
+ * left before `expires_at`, the node moves `expires_at` to `lease_term` from now. Nothing outside the node has
1377
+ * to renew it.
1378
+ *
1379
+ * One live sandbox in a project holds a key at a time. Holding a key on this sandbox takes it from the sandbox
1380
+ * that held it: that lease ends (`end_reason: replaced`) and that sandbox's `expires_at` moves to at most
1381
+ * `lease_term` from now, so it stops by then unless something extends it. A sandbox holds one lease; a call
1382
+ * with another key changes the key it holds. A call with the key it already holds changes nothing.
1383
+ *
1384
+ * `expect_holder` makes the call conditional on what you read: the sandbox you saw holding `key`, or `null` when
1385
+ * you saw none. The node takes the key only while that is still so; otherwise it answers `409
1386
+ * lease_holder_changed` with the sandbox that holds it now (`holder`), and changes nothing. A caller that read an
1387
+ * older state (a check that read the generation before a deploy handed the key to a newer one) then never takes
1388
+ * the key back from the sandbox that got it since. Without `expect_holder` the call takes the key from whichever
1389
+ * sandbox holds it.
1390
+ *
1391
+ * The lease ends when you release it (`DELETE …/lease`, `end_reason: released`; the sandbox then runs out its
1392
+ * current `expires_at`) and when the sandbox stops for any reason (`end_reason` is its `stop_reason`:
1393
+ * `deleted`, `timeout`, `failed`, `budget`, `revoked`). A paused sandbox is not renewed: it ends at
1394
+ * `expires_at` like any paused sandbox. An organization holds at most `sandboxes.leases_max` (5) leases on a
1395
+ * node; one more is `422 limit_exceeded`, and lowering the limit ends none already held. A sandbox's own
1396
+ * credential (the one its in-VM API holds) cannot hold or release a lease (`403 forbidden`, `reason: sandbox`),
1397
+ * so code can never keep its own sandbox, or another, running with it. A real API key you put into a sandbox (in
1398
+ * its `env` or `secrets`) is not the sandbox's own credential: code holding it can hold a lease as any caller
1399
+ * can, within `sandboxes.leases_max` and the organization's credits and spend caps.
1400
+ *
1401
+ * A leased sandbox is billed like any running one (`sandboxes.vcpu_ms`, `sandboxes.gib_ms`), so the call is
1402
+ * admitted like a create (credits, spend cap). The node checks a running sandbox's budget every 10 s and stops
1403
+ * a leased one, ending its lease, as it stops any other (`stop_reason: budget` or `revoked`; a project's service
1404
+ * never stops for its key's revoke or expiry, so not `revoked`).
1405
+ *
1406
+ * `PUT /v1/sandboxes/{sandbox_id}/lease` · scope `sandboxes:write` · served by the node
1407
+ */
1408
+ holdLease(sandboxId: string, body: T.LeaseRequest, options?: RequestOptions): APIPromise<T.Sandbox> {
1409
+ return this._client._call<T.Sandbox>(holdLeaseOp, { path: [sandboxId], body }, options);
1410
+ }
1411
+
767
1412
  /**
768
1413
  * Stream process logs
769
1414
  *
@@ -809,6 +1454,44 @@ export class SandboxesAPI extends Namespace {
809
1454
  return this._client._call<T.Sandbox>(pauseSandboxOp, { path: [sandboxId] }, options);
810
1455
  }
811
1456
 
1457
+ /**
1458
+ * Give a sandbox port its own host
1459
+ *
1460
+ * Gives `port` of the sandbox its own host, `https://<port>-sbx-<id>.b3os.io` (`<id>` is the sandbox ID without
1461
+ * `sbx_`), and returns a link to it. The app is served at `/` and keeps its cookies, as an application's
1462
+ * address does: it gets the request's whole path with no prefix, `Host` is the host, and the cookies it sets
1463
+ * stay on this host (`cookies`, `isolated` by default: the same rules as app addresses). Use it for apps that
1464
+ * need the root path or sign-in cookies. `POST /v1/sandboxes/{sandbox_id}/ports/{port}/url` keeps working as
1465
+ * before.
1466
+ *
1467
+ * Shared by link only, never public. The link (`url`) works for `ttl_s` seconds (10 minutes by default, at
1468
+ * most 24 hours); its first page load sets a cookie that keeps that browser in for 24 hours, and a program can
1469
+ * send the link's `b3os_link` value in `x-b3os-link` instead. Anyone else gets a 401 page, the same whether or
1470
+ * not the sandbox or the host exists. Each call returns a new link and leaves earlier ones working; `rotate:
1471
+ * true` first replaces the host's secret, so every earlier link and cookie of this host stops working within 6
1472
+ * seconds. `cookies` sets the host's cookie rule; left out, the host keeps the one it has.
1473
+ *
1474
+ * The port must be in the sandbox's `ports` and the sandbox running or paused (404 `port_not_exposed`, 409
1475
+ * `sandbox_not_running`, and 404 `sandbox_not_found` for a sandbox of another project). While the sandbox is
1476
+ * paused or stopped its host answers 503. The host is that sandbox's and port's for good and ends with the
1477
+ * sandbox; a fork or a restore has a new ID, so new hosts. A host with no call for 49 hours is forgotten: the
1478
+ * next call makes it again with a new secret. A dev server must accept the host (for Vite,
1479
+ * `server.allowedHosts: ['.b3os.io']`). Not yet available to code inside a sandbox (its API answers 421
1480
+ * `edge_only`). Port 49983 is kept for E2B's envd and gets no host (400). Hosts count toward no address limit.
1481
+ * B3 can block a sandbox's hosts (403 `app_host_blocked`). An organization may call this 60 times a minute
1482
+ * (429 `rate_limited` with `Retry-After` past that).
1483
+ *
1484
+ * `POST /v1/sandboxes/{sandbox_id}/ports/{port}/host` · scope `sandboxes:run` · served by beta-api.b3os.org
1485
+ */
1486
+ createPortHost(
1487
+ sandboxId: string,
1488
+ port: number,
1489
+ body?: T.PortHostRequest,
1490
+ options?: RequestOptions,
1491
+ ): APIPromise<T.PortHost> {
1492
+ return this._client._call<T.PortHost>(createPortHostOp, { path: [sandboxId, port], body }, options);
1493
+ }
1494
+
812
1495
  /**
813
1496
  * Get a URL for a port
814
1497
  *
@@ -856,7 +1539,10 @@ export class SandboxesAPI extends Namespace {
856
1539
  /**
857
1540
  * Signal a background process
858
1541
  *
859
- * Sends a signal (default `TERM`) to a background process and its process group, and returns the process.
1542
+ * Sends a signal (default `TERM`) to a background process and its process group, and returns the process. On a
1543
+ * process the node supervises (an exec with `restart`), the call first ends the supervision (`state: stopped`
1544
+ * in the sandbox's `supervised`), so the process stays down; with `restart: true` it stays supervised and the
1545
+ * node starts it again once it exits, counted as a restart.
860
1546
  *
861
1547
  * `POST /v1/sandboxes/{sandbox_id}/processes/{pid}/kill` · scope `sandboxes:run` · served by the node
862
1548
  */
@@ -942,8 +1628,9 @@ export class SandboxesAPI extends Namespace {
942
1628
  * searches and calls to other sandboxes), newest first, from the node's request log. These are the records
943
1629
  * `GET /v1/requests?sandbox_id=` lists, for a caller that may read the sandbox: it needs only `sandboxes:read`,
944
1630
  * not `platform:read`, and never returns another sandbox's records. It takes the same paging and the
945
- * `product`, `operation_id`, `status`, `trace_id` and `since` filters; any other query parameter is
946
- * `400 invalid_request`. Requests made to the sandbox's public ports are not listed. A sandbox stopped more
1631
+ * `product`, `operation_id`, `status`, `trace_id`, `since` and `pack` filters; any other query parameter is
1632
+ * `400 invalid_request`. `pack=io.b3os/wikipedia` lists the sandbox's calls of that pack's actions, through
1633
+ * `POST /v1/actions/call` or as tools over MCP (each record's `action`). Requests made to the sandbox's public ports are not listed. A sandbox stopped more
947
1634
  * than 7 days ago is not found.
948
1635
  *
949
1636
  * `GET /v1/sandboxes/{sandbox_id}/requests` · scope `sandboxes:read` · served by the node