@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,4 +1,5 @@
1
1
  // Generated by packages/sdk/scripts/generate.mjs from packages/spec/dist. Do not edit; run `pnpm generate`.
2
+ import { isTerminalJobEvent } from "../../core/jobs.js";
2
3
  import { Namespace } from "../../core/namespace.js";
3
4
  import { openSocket, PtySession, ticketedUrl } from "../../core/ws.js";
4
5
  import { launchManagedAgentsSession, startCodexExecServer, startManagedAgentsWorker, } from "../../helpers/agents.js";
@@ -20,6 +21,13 @@ const createSandboxOp = {
20
21
  timeoutMs: 30000,
21
22
  scope: "sandboxes:write",
22
23
  };
24
+ const getCapacityOp = {
25
+ id: "sandboxesGetCapacity",
26
+ method: "GET",
27
+ path: "/v1/sandboxes/capacity",
28
+ timeoutMs: 10000,
29
+ scope: "sandboxes:read",
30
+ };
23
31
  const listSnapshotsOp = {
24
32
  id: "sandboxesListSnapshots",
25
33
  method: "GET",
@@ -43,6 +51,46 @@ const getSnapshotOp = {
43
51
  timeoutMs: 10000,
44
52
  scope: "sandboxes:read",
45
53
  };
54
+ const listSwarmsOp = {
55
+ id: "sandboxesListSwarms",
56
+ method: "GET",
57
+ path: "/v1/sandboxes/swarms",
58
+ timeoutMs: 10000,
59
+ scope: "sandboxes:read",
60
+ };
61
+ const getSwarmOp = {
62
+ id: "sandboxesGetSwarm",
63
+ method: "GET",
64
+ path: "/v1/sandboxes/swarms/{swarm_id}",
65
+ params: ["swarm_id"],
66
+ timeoutMs: 65000,
67
+ scope: "sandboxes:read",
68
+ };
69
+ const cancelSwarmOp = {
70
+ id: "sandboxesCancelSwarm",
71
+ method: "POST",
72
+ path: "/v1/sandboxes/swarms/{swarm_id}/cancel",
73
+ params: ["swarm_id"],
74
+ timeoutMs: 10000,
75
+ scope: "sandboxes:write",
76
+ };
77
+ const listSwarmChildrenOp = {
78
+ id: "sandboxesListSwarmChildren",
79
+ method: "GET",
80
+ path: "/v1/sandboxes/swarms/{swarm_id}/children",
81
+ params: ["swarm_id"],
82
+ timeoutMs: 10000,
83
+ scope: "sandboxes:read",
84
+ };
85
+ const swarmEventsOp = {
86
+ id: "sandboxesSwarmEvents",
87
+ method: "GET",
88
+ path: "/v1/sandboxes/swarms/{swarm_id}/events",
89
+ params: ["swarm_id"],
90
+ stream: "sse",
91
+ timeoutMs: 3600000,
92
+ scope: "sandboxes:read",
93
+ };
46
94
  const listTemplatesOp = {
47
95
  id: "sandboxesListTemplates",
48
96
  method: "GET",
@@ -50,6 +98,14 @@ const listTemplatesOp = {
50
98
  timeoutMs: 10000,
51
99
  scope: "sandboxes:read",
52
100
  };
101
+ const createTemplateOp = {
102
+ id: "sandboxesCreateTemplate",
103
+ method: "POST",
104
+ path: "/v1/sandboxes/templates",
105
+ body: "json",
106
+ timeoutMs: 30000,
107
+ scope: "sandboxes:write",
108
+ };
53
109
  const getTemplateOp = {
54
110
  id: "sandboxesGetTemplate",
55
111
  method: "GET",
@@ -58,6 +114,63 @@ const getTemplateOp = {
58
114
  timeoutMs: 10000,
59
115
  scope: "sandboxes:read",
60
116
  };
117
+ const listVolumesOp = {
118
+ id: "sandboxesListVolumes",
119
+ method: "GET",
120
+ path: "/v1/sandboxes/volumes",
121
+ timeoutMs: 10000,
122
+ scope: "sandboxes:read",
123
+ };
124
+ const createVolumeOp = {
125
+ id: "sandboxesCreateVolume",
126
+ method: "POST",
127
+ path: "/v1/sandboxes/volumes",
128
+ body: "json",
129
+ timeoutMs: 30000,
130
+ scope: "sandboxes:write",
131
+ };
132
+ const deleteVolumeOp = {
133
+ id: "sandboxesDeleteVolume",
134
+ method: "DELETE",
135
+ path: "/v1/sandboxes/volumes/{volume_id}",
136
+ params: ["volume_id"],
137
+ timeoutMs: 10000,
138
+ scope: "sandboxes:write",
139
+ };
140
+ const getVolumeOp = {
141
+ id: "sandboxesGetVolume",
142
+ method: "GET",
143
+ path: "/v1/sandboxes/volumes/{volume_id}",
144
+ params: ["volume_id"],
145
+ timeoutMs: 10000,
146
+ scope: "sandboxes:read",
147
+ };
148
+ const updateVolumeOp = {
149
+ id: "sandboxesUpdateVolume",
150
+ method: "PATCH",
151
+ path: "/v1/sandboxes/volumes/{volume_id}",
152
+ params: ["volume_id"],
153
+ body: "json",
154
+ timeoutMs: 30000,
155
+ scope: "sandboxes:write",
156
+ };
157
+ const purgeVolumeOp = {
158
+ id: "sandboxesPurgeVolume",
159
+ method: "POST",
160
+ path: "/v1/sandboxes/volumes/{volume_id}/purge",
161
+ params: ["volume_id"],
162
+ body: "json",
163
+ timeoutMs: 30000,
164
+ scope: "sandboxes:write",
165
+ };
166
+ const restoreVolumeOp = {
167
+ id: "sandboxesRestoreVolume",
168
+ method: "POST",
169
+ path: "/v1/sandboxes/volumes/{volume_id}/restore",
170
+ params: ["volume_id"],
171
+ timeoutMs: 10000,
172
+ scope: "sandboxes:write",
173
+ };
61
174
  const deleteSandboxOp = {
62
175
  id: "sandboxesDeleteSandbox",
63
176
  method: "DELETE",
@@ -74,6 +187,31 @@ const getSandboxOp = {
74
187
  timeoutMs: 10000,
75
188
  scope: "sandboxes:read",
76
189
  };
190
+ const getComputerOp = {
191
+ id: "sandboxesGetComputer",
192
+ method: "GET",
193
+ path: "/v1/sandboxes/{sandbox_id}/computer",
194
+ params: ["sandbox_id"],
195
+ timeoutMs: 15000,
196
+ scope: "sandboxes:read",
197
+ };
198
+ const computerActOp = {
199
+ id: "sandboxesComputerAct",
200
+ method: "POST",
201
+ path: "/v1/sandboxes/{sandbox_id}/computer/actions",
202
+ params: ["sandbox_id"],
203
+ body: "json",
204
+ timeoutMs: 65000,
205
+ scope: "sandboxes:run",
206
+ };
207
+ const computerScreenshotOp = {
208
+ id: "sandboxesComputerScreenshot",
209
+ method: "GET",
210
+ path: "/v1/sandboxes/{sandbox_id}/computer/screenshot",
211
+ params: ["sandbox_id"],
212
+ timeoutMs: 15000,
213
+ scope: "sandboxes:read",
214
+ };
77
215
  const setEgressOp = {
78
216
  id: "sandboxesSetEgress",
79
217
  method: "POST",
@@ -160,6 +298,23 @@ const forkSandboxOp = {
160
298
  timeoutMs: 30000,
161
299
  scope: "sandboxes:write",
162
300
  };
301
+ const releaseLeaseOp = {
302
+ id: "sandboxesReleaseLease",
303
+ method: "DELETE",
304
+ path: "/v1/sandboxes/{sandbox_id}/lease",
305
+ params: ["sandbox_id"],
306
+ timeoutMs: 10000,
307
+ scope: "sandboxes:write",
308
+ };
309
+ const holdLeaseOp = {
310
+ id: "sandboxesHoldLease",
311
+ method: "PUT",
312
+ path: "/v1/sandboxes/{sandbox_id}/lease",
313
+ params: ["sandbox_id"],
314
+ body: "json",
315
+ timeoutMs: 10000,
316
+ scope: "sandboxes:write",
317
+ };
163
318
  const streamLogsOp = {
164
319
  id: "sandboxesStreamLogs",
165
320
  method: "GET",
@@ -177,6 +332,16 @@ const pauseSandboxOp = {
177
332
  timeoutMs: 10000,
178
333
  scope: "sandboxes:write",
179
334
  };
335
+ const createPortHostOp = {
336
+ id: "platformCreatePortHost",
337
+ method: "POST",
338
+ path: "/v1/sandboxes/{sandbox_id}/ports/{port}/host",
339
+ params: ["sandbox_id", "port"],
340
+ body: "json",
341
+ edge: true,
342
+ timeoutMs: 15000,
343
+ scope: "sandboxes:run",
344
+ };
180
345
  const createPortUrlOp = {
181
346
  id: "sandboxesCreatePortUrl",
182
347
  method: "POST",
@@ -281,17 +446,46 @@ const setTimeoutOp = {
281
446
  timeoutMs: 10000,
282
447
  scope: "sandboxes:write",
283
448
  };
449
+ const createSwarmOp = {
450
+ id: "sandboxesCreateSwarm",
451
+ method: "POST",
452
+ path: "/v1/sandboxes/swarms",
453
+ body: "json",
454
+ idem: true,
455
+ stream: "sse",
456
+ timeoutMs: 3600000,
457
+ scope: "sandboxes:write",
458
+ job: { get: getSwarmOp, events: swarmEventsOp, cancel: cancelSwarmOp },
459
+ };
284
460
  /** Descriptors of every sandboxes operation, keyed by method name (for tooling and custom clients). */
285
461
  export const sandboxesOps = {
286
462
  listSandboxes: listSandboxesOp,
287
463
  createSandbox: createSandboxOp,
464
+ getCapacity: getCapacityOp,
288
465
  listSnapshots: listSnapshotsOp,
289
466
  deleteSnapshot: deleteSnapshotOp,
290
467
  getSnapshot: getSnapshotOp,
468
+ listSwarms: listSwarmsOp,
469
+ createSwarm: createSwarmOp,
470
+ getSwarm: getSwarmOp,
471
+ cancelSwarm: cancelSwarmOp,
472
+ listSwarmChildren: listSwarmChildrenOp,
473
+ swarmEvents: swarmEventsOp,
291
474
  listTemplates: listTemplatesOp,
475
+ createTemplate: createTemplateOp,
292
476
  getTemplate: getTemplateOp,
477
+ listVolumes: listVolumesOp,
478
+ createVolume: createVolumeOp,
479
+ deleteVolume: deleteVolumeOp,
480
+ getVolume: getVolumeOp,
481
+ updateVolume: updateVolumeOp,
482
+ purgeVolume: purgeVolumeOp,
483
+ restoreVolume: restoreVolumeOp,
293
484
  deleteSandbox: deleteSandboxOp,
294
485
  getSandbox: getSandboxOp,
486
+ getComputer: getComputerOp,
487
+ computerAct: computerActOp,
488
+ computerScreenshot: computerScreenshotOp,
295
489
  setEgress: setEgressOp,
296
490
  exec: execOp,
297
491
  deleteFile: deleteFileOp,
@@ -301,8 +495,11 @@ export const sandboxesOps = {
301
495
  moveFile: moveFileOp,
302
496
  statFile: statFileOp,
303
497
  forkSandbox: forkSandboxOp,
498
+ releaseLease: releaseLeaseOp,
499
+ holdLease: holdLeaseOp,
304
500
  streamLogs: streamLogsOp,
305
501
  pauseSandbox: pauseSandboxOp,
502
+ createPortHost: createPortHostOp,
306
503
  createPortUrl: createPortUrlOp,
307
504
  listProcesses: listProcessesOp,
308
505
  killProcess: killProcessOp,
@@ -326,6 +523,8 @@ export class SandboxesAPI extends Namespace {
326
523
  * `metadata[<key>]=<value>` (up to 4 pairs) keeps only sandboxes whose `metadata` holds every pair given, with
327
524
  * exactly that value: `GET /v1/sandboxes?metadata[customer]=acme&metadata[ticket]=ENG-1423`. A sandbox whose
328
525
  * create lost its answer (a dropped connection) is found this way by a tag it was created with.
526
+ * `owner=project&created_by_key=<key_id>` lists the services a key deployed, and `root=<sandbox_id>` the
527
+ * sandboxes one of them started.
329
528
  *
330
529
  * `GET /v1/sandboxes` · scope `sandboxes:read` · served by the node
331
530
  */
@@ -408,6 +607,14 @@ export class SandboxesAPI extends Namespace {
408
607
  * the daemon (streamed execs, PTY sessions, log streams, port preview connections, the sandbox's outbound
409
608
  * connections and its calls to `http://127.0.0.1:7700`) drop at the restart and can be opened again.
410
609
  *
610
+ * From an image (`image: "img_…"`, `POST /v1/images`): the sandbox restores the image's warm snapshot and
611
+ * has the image's size; a `vcpu` or `memory_mib` other than it answers `400 invalid_request`. `image` needs the
612
+ * `images.import` flag on for your organization (`404 feature_not_enabled` otherwise), answers `404
613
+ * image_not_found` for an image of another project and `409 image_not_ready` (with `current_status`) until the
614
+ * image is `ready`. `template: "tpl_…"` with the image's template ID works the same way without the flag (the
615
+ * template exists only once an import has run). Give `image` alone: with `template` or `snapshot` it answers
616
+ * `400 invalid_request`.
617
+ *
411
618
  * Disk: a sandbox's disk is its own copy-on-write copy of the template's (or snapshot's) disk; it is deleted
412
619
  * when the sandbox ends and never given to another sandbox. The disks of an organization's running and paused
413
620
  * sandboxes on a node add up to at most `sandboxes.disk_total_max` (each sandbox counting its `disk_gib`;
@@ -415,6 +622,12 @@ export class SandboxesAPI extends Namespace {
415
622
  * create the concurrency limit allows); past it a create is refused with `422 limit_exceeded`. While the
416
623
  * node's disk store is nearly full, creates are refused with `503 capacity_unavailable` and `Retry-After`.
417
624
  *
625
+ * Desktops: a sandbox of a template with the `computer` capability (`desktop`) also counts against
626
+ * `sandboxes.desktops_concurrent`, its running and paused sandboxes of such templates (forks included); past it
627
+ * a create or fork is refused with `429 concurrency_limited` and `Retry-After`, as past `sandboxes.concurrent`.
628
+ * Its environment has `DISPLAY=:1` (the desktop's X server) unless `env` sets `DISPLAY`, so commands reach the
629
+ * screen. `GET /v1/sandboxes/capacity` says how many more would be created now.
630
+ *
418
631
  * Returns the sandbox object (`SandboxInfo`). `create()` sends the same request and returns a `Sandbox`
419
632
  * handle instead (`exec`, `files`, `ports`), which `await using` deletes when the scope ends.
420
633
  *
@@ -423,6 +636,35 @@ export class SandboxesAPI extends Namespace {
423
636
  createSandbox(body, options) {
424
637
  return createSandboxSafely((b, o) => this._client._call(createSandboxOp, { body: b }, o), body, options, this._client.maxRetries);
425
638
  }
639
+ /**
640
+ * Check room for more sandboxes
641
+ *
642
+ * How many more sandboxes of one template and size your organization could create on this node now, and
643
+ * which limit refuses the next one. Call it before a wave of creates instead of meeting `429` or `503`
644
+ * answers. The default shape is the `desktop` template at its default size; name another with `template`,
645
+ * `vcpu` and `memory_mib`.
646
+ *
647
+ * `room` is the least of three counts. `org` is `sandboxes.concurrent`: your running and paused sandboxes
648
+ * (and creates in flight) against the limit; paused sandboxes count, so delete the ones you are done with
649
+ * rather than leave them paused. `desktops` is `sandboxes.desktops_concurrent`, the running and paused
650
+ * sandboxes of templates with the `computer` capability; it counts toward `room` only when the template has
651
+ * that capability. `node` is this node: `parked` is how many sandboxes of the shape wait warm in its pool
652
+ * (a create claims one without a restore), and `room` is how many sandboxes of the shape the memory left
653
+ * under the node's microVM memory limit holds, each counting its `memory_mib` plus the node's per-microVM
654
+ * overhead, or `0` while the node's disk store is too full for new sandboxes. `node.room` is `null` when the
655
+ * node cannot read that limit, and then it does not count toward `room`.
656
+ *
657
+ * `binding` names the limit that refuses the next create (`org_concurrency`, `desktops` or `node`) when
658
+ * `room` is `0`, with `retry_after_s`, and is `null` while a create would pass. The answer is a reading, not
659
+ * a reservation: another create can take the room first. `sandboxes.disk_total_max` is left out (its beta
660
+ * default never refuses a create the concurrency limit allows). Behind the `sandboxes.desktop` feature flag:
661
+ * until it is on for your organization the operation answers `404 feature_not_enabled`.
662
+ *
663
+ * `GET /v1/sandboxes/capacity` · scope `sandboxes:read` · served by the node
664
+ */
665
+ getCapacity(params, options) {
666
+ return this._client._call(getCapacityOp, { query: params }, options);
667
+ }
426
668
  /**
427
669
  * List snapshots
428
670
  *
@@ -453,29 +695,244 @@ export class SandboxesAPI extends Namespace {
453
695
  getSnapshot(snapshotId, options) {
454
696
  return this._client._call(getSnapshotOp, { path: [snapshotId] }, options);
455
697
  }
698
+ /**
699
+ * List swarms
700
+ *
701
+ * Lists swarms in this project, newest first, without their children (`GET /v1/sandboxes/swarms/{swarm_id}`
702
+ * returns them). Swarms are kept for 7 days after they finish.
703
+ *
704
+ * `GET /v1/sandboxes/swarms` · scope `sandboxes:read` · served by the node
705
+ */
706
+ listSwarms(params, options) {
707
+ return this._client._list(listSwarmsOp, { query: params }, options);
708
+ }
709
+ /**
710
+ * Start a swarm
711
+ *
712
+ * Forks one checkpoint into children, runs a command in each child, and gathers every child's exit code,
713
+ * output and timing. The checkpoint is a forkable sandbox (`from.sandbox`, running or paused) or a snapshot
714
+ * (`from.snapshot`). Each child is a new sandbox with a fresh identity, as a fork's or a restore's is: it keeps
715
+ * the checkpoint's environment, secrets, files, egress, ports and grant, and gets its own ID.
716
+ *
717
+ * Give the children one by one in `children` (at most `sandboxes.swarm_children_max`; a child's index is its
718
+ * position), or give `count` children that all run `defaults`. Each child's command runs as
719
+ * `POST /v1/sandboxes/{sandbox_id}/exec` would run it streamed, with `B3OS_SWARM_ID` and `B3OS_SWARM_INDEX`
720
+ * added to its environment, so one command can shard work by index. `env` is stored with the swarm's record
721
+ * for as long as it is kept: pass secrets as the checkpoint's `secrets`, never in `env`.
722
+ *
723
+ * A child whose sandbox would expire before its command's `timeout_ms` has passed gets a longer lifetime, the
724
+ * command's timeout plus 30 seconds, up to `sandboxes.timeout_max`.
725
+ *
726
+ * A child's non-zero exit is a result, not a failure of the swarm. The swarm `succeeded` once every child's
727
+ * command ended (exited, timed out, or could not run) or `stop_when` was met; it `failed` only when no child
728
+ * could start (the fork or restore failed) or the node restarted while it ran. With
729
+ * `stop_when: first_success`, the first child to exit 0 is `result.winner` and the other children's commands
730
+ * are killed (`canceled`). Each stream of output keeps its first `output_max_bytes` bytes, in the record and
731
+ * in the events.
732
+ *
733
+ * After its command ends a child is deleted, unless `keep` keeps it: `succeeded` keeps the children that
734
+ * exited 0, `all` keeps every child. A kept child is an ordinary sandbox that runs to its own `expires_at`,
735
+ * counts against `sandboxes.concurrent` and is billed until you delete it.
736
+ *
737
+ * All children are reserved at once, nothing started unless every one fits: past `sandboxes.concurrent` the
738
+ * answer is `429 concurrency_limited` with `Retry-After`, past `sandboxes.disk_total_max` `422 limit_exceeded`.
739
+ * 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
740
+ * hold no volume (`409 volume_attached`). Creating a swarm needs `sandboxes:write` and also `sandboxes:run`.
741
+ * Swarms are listed for 7 days after they finish. Behind the `sandboxes.swarms` feature flag: until it is on
742
+ * for your organization every swarm operation answers `404 feature_not_enabled`.
743
+ *
744
+ * `POST /v1/sandboxes/swarms` · scope `sandboxes:write` · served by the node
745
+ */
746
+ createSwarm(body, options) {
747
+ return this._client._job(createSwarmOp, { body }, options);
748
+ }
749
+ /**
750
+ * Get a swarm
751
+ *
752
+ * Returns the swarm with its status, progress, result, timing and every child with its exit code, output and
753
+ * timing. While it runs, children that have not ended show `queued` or `running`. `?wait=` holds the answer
754
+ * until the swarm ends or the wait runs out.
755
+ *
756
+ * `GET /v1/sandboxes/swarms/{swarm_id}` · scope `sandboxes:read` · served by the node
757
+ */
758
+ getSwarm(swarmId, params, options) {
759
+ return this._client._call(getSwarmOp, { path: [swarmId], query: params }, options);
760
+ }
761
+ /**
762
+ * Cancel a swarm
763
+ *
764
+ * Stops the swarm: commands still running are killed and those children end `canceled`; each child is then
765
+ * deleted unless the swarm's `keep` keeps it (`all` keeps every child, `succeeded` the ones that exited 0).
766
+ * Returns the swarm with status `canceled`.
767
+ *
768
+ * `POST /v1/sandboxes/swarms/{swarm_id}/cancel` · scope `sandboxes:write` · served by the node
769
+ */
770
+ cancelSwarm(swarmId, options) {
771
+ return this._client._call(cancelSwarmOp, { path: [swarmId] }, options);
772
+ }
773
+ /**
774
+ * List a swarm's children
775
+ *
776
+ * Lists the swarm's children by index, with each child's exit code, output and timing. Available while the swarm runs.
777
+ *
778
+ * `GET /v1/sandboxes/swarms/{swarm_id}/children` · scope `sandboxes:read` · served by the node
779
+ */
780
+ listSwarmChildren(swarmId, params, options) {
781
+ return this._client._list(listSwarmChildrenOp, { path: [swarmId], query: params }, options);
782
+ }
783
+ /**
784
+ * Stream a swarm's events
785
+ *
786
+ * Server-sent events for the swarm: lifecycle events, `swarm.forked` with each child's sandbox ID, then
787
+ * `child.started`, `child.exited` or `child.failed` per child, and `child.stdout` and `child.stderr` when the
788
+ * swarm was created with `stream_output: true`. Ends after the terminal event. Reconnect with `Last-Event-ID`
789
+ * to resume. Events are kept with the swarm, so the stream reads the same, with the same `seq`, after the node
790
+ * restarts.
791
+ *
792
+ * `GET /v1/sandboxes/swarms/{swarm_id}/events` · scope `sandboxes:read` · served by the node
793
+ */
794
+ swarmEvents(swarmId, options) {
795
+ return this._client._stream(swarmEventsOp, { path: [swarmId] }, options, {
796
+ terminal: isTerminalJobEvent,
797
+ reconnectOnEnd: true,
798
+ });
799
+ }
456
800
  /**
457
801
  * List templates
458
802
  *
459
803
  * Lists the templates sandboxes can start from (`base`, `code-interpreter`, `agent`, and `browser` where a node
460
804
  * builds it, which the beta node does not yet: Chrome already running in the snapshot, a VM-isolated browser
461
805
  * with DevTools on port 9222) with their OS, runtimes, capabilities, defaults and `size_classes` (the sizes kept
462
- * pre-warmed). It does not list a template's packages.
806
+ * pre-warmed). It does not list a template's packages. The node's templates have `owner: node`; your project's
807
+ * imported images add their templates with `owner: project` and `image` set (`POST /v1/images`). Other
808
+ * projects' image templates are never listed, and getting one answers `404 template_not_found`.
463
809
  *
464
810
  * `GET /v1/sandboxes/templates` · scope `sandboxes:read` · served by the node
465
811
  */
466
812
  listTemplates(options) {
467
813
  return this._client._call(listTemplatesOp, {}, options);
468
814
  }
815
+ /**
816
+ * Create a template
817
+ *
818
+ * Makes a template for this project's sandboxes from a public OCI image (`image`, a reference) or from a
819
+ * Dockerfile build (`build`), with an optional `name` the project's creates start from:
820
+ * `POST /v1/sandboxes {"template": "py:3.11"}`. It takes the request `POST /v1/images` takes (with `image` in
821
+ * place of `ref`), and the template is that image's: one object, listed and deleted with `/v1/images`. The
822
+ * answer is the template's view: its `tpl_` ID (fixed from the start), `name`, `status` (the image's), `image`
823
+ * (the `img_` ID), `rootfs_sha256` once the image is flattened, and `key`. `202` for a new image, `200` for
824
+ * the project's image of the same request. Watch it with `GET /v1/images/{image_id}?wait=30` until `ready`;
825
+ * a create by name before then answers `409 image_not_ready`.
826
+ *
827
+ * A name is unique among the project's images (`409 image_name_taken`) and never a node template's
828
+ * (`422 image_name_reserved`). Another project's name answers `404 template_not_found`, as a template that
829
+ * does not exist. Behind the `images.build` flag (and `images.import`): until it is on for your organization
830
+ * the answer is `404 feature_not_enabled`. `503 product_unavailable` on a node without the images product.
831
+ *
832
+ * A private image names a registry connection in `auth`, as `POST /v1/images` does (`ImageRegistryAuth`): a
833
+ * vault connection of this project of type `basic` whose `hosts` list the registry and its token service.
834
+ * Using it also needs `vault:run` (`403` without it). Another project's connection, or one this credential may
835
+ * not use, answers `404 connection_not_found`; one that is not a registry connection for the image's registry,
836
+ * `422 image_auth_invalid`; a credential the registry refuses, `422 image_refused` with `reason: credentials`.
837
+ * The node reads the secret once, keeps it in memory for that one import and sends it only to the registry's
838
+ * token service: it is never logged, recorded or put in an error. A build takes no `auth`.
839
+ *
840
+ * `POST /v1/sandboxes/templates` · scope `sandboxes:write` · served by the node
841
+ */
842
+ createTemplate(body, options) {
843
+ return this._client._call(createTemplateOp, { body }, options);
844
+ }
469
845
  /**
470
846
  * Get a template
471
847
  *
472
- * Returns one template by name (`base`) or ID (`tpl_…`).
848
+ * 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`.
473
849
  *
474
850
  * `GET /v1/sandboxes/templates/{template}` · scope `sandboxes:read` · served by the node
475
851
  */
476
852
  getTemplate(template, options) {
477
853
  return this._client._call(getTemplateOp, { path: [template] }, options);
478
854
  }
855
+ /**
856
+ * List volumes
857
+ *
858
+ * Lists the project's volumes on this node, newest first. Deleted volumes are listed only with `status=deleted`.
859
+ *
860
+ * `GET /v1/sandboxes/volumes` · scope `sandboxes:read` · served by the node
861
+ */
862
+ listVolumes(params, options) {
863
+ return this._client._list(listVolumesOp, { query: params }, options);
864
+ }
865
+ /**
866
+ * Create a volume
867
+ *
868
+ * Creates an ext4 volume of `size_gib` on this node: data that outlives the sandboxes that mount it. Mount it
869
+ * in a sandbox with `volumes` on `POST /v1/sandboxes`; it is held by one running or paused sandbox at a time.
870
+ * Its blocks are allocated at once and reserved on the node's disk, so a full node disk cannot fail a write to
871
+ * it. Bills `sandboxes.volume_gib_h` (its size times the hours it exists, mounted or not) until it is deleted.
872
+ *
873
+ * In this beta a volume is one copy on the node's one drive: there is no backup, and it is not encrypted at
874
+ * rest, like every sandbox disk. Have the code that writes to it fsync what matters: what an app wrote and did
875
+ * not flush when its sandbox's microVM stopped without warning is lost.
876
+ *
877
+ * `POST /v1/sandboxes/volumes` · scope `sandboxes:write` · served by the node
878
+ */
879
+ createVolume(body, options) {
880
+ return this._client._call(createVolumeOp, { body }, options);
881
+ }
882
+ /**
883
+ * Delete a volume
884
+ *
885
+ * Marks the volume deleted: it is no longer listed or mounted, stops billing, and is purged (its data gone) at
886
+ * `purge_at`, 7 days later, unless you restore it first. Refused while a sandbox holds it (`409
887
+ * volume_attached`). Nothing else deletes a volume.
888
+ *
889
+ * `DELETE /v1/sandboxes/volumes/{volume_id}` · scope `sandboxes:write` · served by the node
890
+ */
891
+ deleteVolume(volumeId, options) {
892
+ return this._client._call(deleteVolumeOp, { path: [volumeId] }, options);
893
+ }
894
+ /**
895
+ * Get a volume
896
+ *
897
+ * Returns a volume, deleted ones in their grace included.
898
+ *
899
+ * `GET /v1/sandboxes/volumes/{volume_id}` · scope `sandboxes:read` · served by the node
900
+ */
901
+ getVolume(volumeId, options) {
902
+ return this._client._call(getVolumeOp, { path: [volumeId] }, options);
903
+ }
904
+ /**
905
+ * Grow a volume or change its metadata
906
+ *
907
+ * Replaces `metadata`, and grows the volume to `size_gib`. A volume grows only, and only while no sandbox
908
+ * holds it (`409 volume_attached`): its file system grows to the new size the next time a sandbox mounts it.
909
+ *
910
+ * `PATCH /v1/sandboxes/volumes/{volume_id}` · scope `sandboxes:write` · served by the node
911
+ */
912
+ updateVolume(volumeId, body, options) {
913
+ return this._client._call(updateVolumeOp, { path: [volumeId], body }, options);
914
+ }
915
+ /**
916
+ * Purge a volume now
917
+ *
918
+ * Removes the volume and its data now, deleted or not, without waiting for `purge_at`. `confirm` must be the
919
+ * volume's name. Refused while a sandbox holds it (`409 volume_attached`). This cannot be undone.
920
+ *
921
+ * `POST /v1/sandboxes/volumes/{volume_id}/purge` · scope `sandboxes:write` · served by the node
922
+ */
923
+ purgeVolume(volumeId, body, options) {
924
+ return this._client._call(purgeVolumeOp, { path: [volumeId], body }, options);
925
+ }
926
+ /**
927
+ * Restore a deleted volume
928
+ *
929
+ * 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.
930
+ *
931
+ * `POST /v1/sandboxes/volumes/{volume_id}/restore` · scope `sandboxes:write` · served by the node
932
+ */
933
+ restoreVolume(volumeId, options) {
934
+ return this._client._call(restoreVolumeOp, { path: [volumeId] }, options);
935
+ }
479
936
  /**
480
937
  * Delete a sandbox
481
938
  *
@@ -496,6 +953,85 @@ export class SandboxesAPI extends Namespace {
496
953
  getSandbox(sandboxId, options) {
497
954
  return this._client._call(getSandboxOp, { path: [sandboxId] }, options);
498
955
  }
956
+ /**
957
+ * Read a desktop's screen size and pointer
958
+ *
959
+ * The screen size and the pointer position of a sandbox made from a template with the `computer`
960
+ * capability (`desktop`), and who controls its input. `controller` is always `agent` for now. A sandbox of
961
+ * another template answers `409 computer_unavailable`.
962
+ *
963
+ * A paused sandbox is resumed first when your key also has `sandboxes:write` (the scope of
964
+ * `POST /v1/sandboxes/{sandbox_id}/resume`); without it the answer is `409 sandbox_not_running`. A paused
965
+ * sandbox past its `expires_at` is not resumed: extend it with `POST /v1/sandboxes/{sandbox_id}/timeout` first.
966
+ * `503 desktop_unavailable` means the desktop's screen and input server in the sandbox did not answer; it is
967
+ * restarted within a few seconds of stopping. Behind the `sandboxes.desktop` feature flag: until it is on for
968
+ * your organization the operation answers `404 feature_not_enabled`.
969
+ *
970
+ * `GET /v1/sandboxes/{sandbox_id}/computer` · scope `sandboxes:read` · served by the node
971
+ */
972
+ getComputer(sandboxId, options) {
973
+ return this._client._call(getComputerOp, { path: [sandboxId] }, options);
974
+ }
975
+ /**
976
+ * Send mouse and keyboard actions to a desktop
977
+ *
978
+ * Runs 1 to 32 mouse and keyboard actions in order on a sandbox made from a template with the `computer`
979
+ * capability (`desktop`), then optionally waits for the screen to settle and takes a screenshot, all in one
980
+ * call. Action names follow Anthropic's computer-use actions, so a harness maps them one to one. Coordinates
981
+ * are screen pixels from the top left (`GET /v1/sandboxes/{sandbox_id}/computer` gives the screen size); an
982
+ * action without `x` and `y` acts at the pointer. `type` types up to 8,192 bytes of UTF-8 text (newline and
983
+ * tab included, other control characters refused); `key` presses a chord of xdotool key names
984
+ * (`ctrl+shift+t`, `Return`, `alt+F4`); `key_down` and `key_up` hold and release one key; `wait` waits; the
985
+ * waits of one call add up to at most 30,000 ms.
986
+ *
987
+ * The whole batch is checked before any input is sent: a bad action answers `400 invalid_request` naming it
988
+ * (`actions[2]`), and nothing ran. Then each action gets a result in `results`, in order: `delivery` says
989
+ * whether its input reached the X server (`delivered_unverified`: sent and synced; what the application did
990
+ * with it is not checked) and `retry` whether sending it again is safe (`unsafe` once a click, text or a key
991
+ * landed). An action that fails stops the batch; the actions after it are `not_delivered` with `retry:
992
+ * safe`. Held buttons and keys are released when a batch fails part way.
993
+ *
994
+ * `screenshot` adds a screenshot after the actions (`{format, quality}`, the same as the screenshot
995
+ * operation's query; `null` or left out: none). `settle` waits before the screenshot until the screen has
996
+ * not changed for `quiet_ms` (80 by default), at most `max_ms` (1,000 by default); `settled_by` says which
997
+ * ended the wait. `cursor` is where the pointer ended, `null` when the desktop's X server went away during
998
+ * the batch (then `screenshot` is `null` too). A failed screenshot after the actions also leaves `screenshot`
999
+ * `null` with the results intact.
1000
+ *
1001
+ * A paused sandbox is resumed first when your key also has `sandboxes:write`, as for
1002
+ * `GET /v1/sandboxes/{sandbox_id}/computer`; without it the answer is `409 sandbox_not_running`. A sandbox of
1003
+ * another template answers `409 computer_unavailable`. A `503` or `504` after the batch was sent to the
1004
+ * sandbox says so in its detail: some actions may have run, so take a screenshot before you send them again.
1005
+ * The node logs each action's name, its coordinates and the batch's timing, never typed text (its length
1006
+ * only), keys or screenshots. Behind the `sandboxes.desktop` feature flag: until it is on for your
1007
+ * organization the operation answers `404 feature_not_enabled`.
1008
+ *
1009
+ * `POST /v1/sandboxes/{sandbox_id}/computer/actions` · scope `sandboxes:run` · served by the node
1010
+ */
1011
+ computerAct(sandboxId, body, options) {
1012
+ return this._client._call(computerActOp, { path: [sandboxId], body }, options);
1013
+ }
1014
+ /**
1015
+ * Take a screenshot of a desktop
1016
+ *
1017
+ * Captures the whole screen of a sandbox made from a template with the `computer` capability (`desktop`).
1018
+ * With `Accept: image/png` or `image/jpeg` (or `image/*`, `*\/*`, or no `Accept`) the answer is the image
1019
+ * bytes; with `Accept: application/json` it is `{format, width, height, data_base64}`, the shape of a vision
1020
+ * screenshot. `format` is `jpeg` (at `quality`, 80 by default) unless the query or `Accept` asks for `png`;
1021
+ * `quality` applies to JPEG only. `Server-Timing` has `capture` and `encode` (the time inside the sandbox),
1022
+ * `desk` (the round trip to it) and `resume` when a paused sandbox was resumed first.
1023
+ *
1024
+ * A paused sandbox is resumed first when your key also has `sandboxes:write`, as for
1025
+ * `GET /v1/sandboxes/{sandbox_id}/computer`; without it the answer is `409 sandbox_not_running`. A sandbox of
1026
+ * another template answers `409 computer_unavailable`. Screenshots are never logged or stored by the node.
1027
+ * Behind the `sandboxes.desktop` feature flag: until it is on for your organization the operation answers
1028
+ * `404 feature_not_enabled`.
1029
+ *
1030
+ * `GET /v1/sandboxes/{sandbox_id}/computer/screenshot` · scope `sandboxes:read` · served by the node
1031
+ */
1032
+ computerScreenshot(sandboxId, params, options) {
1033
+ return this._client._call(computerScreenshotOp, { path: [sandboxId], query: params }, options);
1034
+ }
499
1035
  /**
500
1036
  * Change a sandbox's egress policy
501
1037
  *
@@ -608,7 +1144,8 @@ export class SandboxesAPI extends Namespace {
608
1144
  * `forkable: true` (forkable sandboxes are restored for themselves rather than claimed from a pool, and track
609
1145
  * the pages they change); forks are forkable too. The source pauses while its changed memory is written
610
1146
  * (`pause`, `base`, `snapshot`, `export` phases in `Server-Timing`), then runs on; like a snapshot this resets
611
- * its open connections to the outside.
1147
+ * its open connections to the outside. A paused source is resumed for the fork and paused again (`resume`
1148
+ * and `repause` phases), so a checkpoint can wait paused, billing neither meter, between forks.
612
1149
  * Each fork counts against your sandbox concurrency and, with the source's `disk_gib`, against
613
1150
  * `sandboxes.disk_total_max` (`422 limit_exceeded`). While the node's snapshot or disk store is nearly full,
614
1151
  * forks are refused with `503 capacity_unavailable`.
@@ -618,6 +1155,60 @@ export class SandboxesAPI extends Namespace {
618
1155
  forkSandbox(sandboxId, body, options) {
619
1156
  return this._client._call(forkSandboxOp, { path: [sandboxId], body }, options);
620
1157
  }
1158
+ /**
1159
+ * Release a sandbox's lease
1160
+ *
1161
+ * Ends the sandbox's lease (`end_reason: released`). The sandbox keeps running until its current `expires_at`,
1162
+ * which you can still move with `POST /v1/sandboxes/{sandbox_id}/timeout`. Releasing a sandbox that holds no
1163
+ * lease, or one that has stopped, changes nothing and answers the sandbox. A sandbox's own credential cannot
1164
+ * release a lease (`403 forbidden`, `reason: sandbox`).
1165
+ *
1166
+ * `DELETE /v1/sandboxes/{sandbox_id}/lease` · scope `sandboxes:write` · served by the node
1167
+ */
1168
+ releaseLease(sandboxId, options) {
1169
+ return this._client._call(releaseLeaseOp, { path: [sandboxId] }, options);
1170
+ }
1171
+ /**
1172
+ * Keep a sandbox running under a lease
1173
+ *
1174
+ * Holds a lease on the sandbox under `key`, a name of your choosing (the deploy engine uses
1175
+ * `b3os:<app>/<service>`). While the lease is held and the sandbox runs, the node keeps it running past its
1176
+ * `timeout_s` and past `sandboxes.timeout_max`: whenever less than half of `sandboxes.lease_term` (900 s) is
1177
+ * left before `expires_at`, the node moves `expires_at` to `lease_term` from now. Nothing outside the node has
1178
+ * to renew it.
1179
+ *
1180
+ * One live sandbox in a project holds a key at a time. Holding a key on this sandbox takes it from the sandbox
1181
+ * that held it: that lease ends (`end_reason: replaced`) and that sandbox's `expires_at` moves to at most
1182
+ * `lease_term` from now, so it stops by then unless something extends it. A sandbox holds one lease; a call
1183
+ * with another key changes the key it holds. A call with the key it already holds changes nothing.
1184
+ *
1185
+ * `expect_holder` makes the call conditional on what you read: the sandbox you saw holding `key`, or `null` when
1186
+ * you saw none. The node takes the key only while that is still so; otherwise it answers `409
1187
+ * lease_holder_changed` with the sandbox that holds it now (`holder`), and changes nothing. A caller that read an
1188
+ * older state (a check that read the generation before a deploy handed the key to a newer one) then never takes
1189
+ * the key back from the sandbox that got it since. Without `expect_holder` the call takes the key from whichever
1190
+ * sandbox holds it.
1191
+ *
1192
+ * The lease ends when you release it (`DELETE …/lease`, `end_reason: released`; the sandbox then runs out its
1193
+ * current `expires_at`) and when the sandbox stops for any reason (`end_reason` is its `stop_reason`:
1194
+ * `deleted`, `timeout`, `failed`, `budget`, `revoked`). A paused sandbox is not renewed: it ends at
1195
+ * `expires_at` like any paused sandbox. An organization holds at most `sandboxes.leases_max` (5) leases on a
1196
+ * node; one more is `422 limit_exceeded`, and lowering the limit ends none already held. A sandbox's own
1197
+ * credential (the one its in-VM API holds) cannot hold or release a lease (`403 forbidden`, `reason: sandbox`),
1198
+ * so code can never keep its own sandbox, or another, running with it. A real API key you put into a sandbox (in
1199
+ * its `env` or `secrets`) is not the sandbox's own credential: code holding it can hold a lease as any caller
1200
+ * can, within `sandboxes.leases_max` and the organization's credits and spend caps.
1201
+ *
1202
+ * A leased sandbox is billed like any running one (`sandboxes.vcpu_ms`, `sandboxes.gib_ms`), so the call is
1203
+ * admitted like a create (credits, spend cap). The node checks a running sandbox's budget every 10 s and stops
1204
+ * a leased one, ending its lease, as it stops any other (`stop_reason: budget` or `revoked`; a project's service
1205
+ * never stops for its key's revoke or expiry, so not `revoked`).
1206
+ *
1207
+ * `PUT /v1/sandboxes/{sandbox_id}/lease` · scope `sandboxes:write` · served by the node
1208
+ */
1209
+ holdLease(sandboxId, body, options) {
1210
+ return this._client._call(holdLeaseOp, { path: [sandboxId], body }, options);
1211
+ }
621
1212
  /**
622
1213
  * Stream process logs
623
1214
  *
@@ -657,6 +1248,38 @@ export class SandboxesAPI extends Namespace {
657
1248
  pauseSandbox(sandboxId, options) {
658
1249
  return this._client._call(pauseSandboxOp, { path: [sandboxId] }, options);
659
1250
  }
1251
+ /**
1252
+ * Give a sandbox port its own host
1253
+ *
1254
+ * Gives `port` of the sandbox its own host, `https://<port>-sbx-<id>.b3os.io` (`<id>` is the sandbox ID without
1255
+ * `sbx_`), and returns a link to it. The app is served at `/` and keeps its cookies, as an application's
1256
+ * address does: it gets the request's whole path with no prefix, `Host` is the host, and the cookies it sets
1257
+ * stay on this host (`cookies`, `isolated` by default: the same rules as app addresses). Use it for apps that
1258
+ * need the root path or sign-in cookies. `POST /v1/sandboxes/{sandbox_id}/ports/{port}/url` keeps working as
1259
+ * before.
1260
+ *
1261
+ * Shared by link only, never public. The link (`url`) works for `ttl_s` seconds (10 minutes by default, at
1262
+ * most 24 hours); its first page load sets a cookie that keeps that browser in for 24 hours, and a program can
1263
+ * send the link's `b3os_link` value in `x-b3os-link` instead. Anyone else gets a 401 page, the same whether or
1264
+ * not the sandbox or the host exists. Each call returns a new link and leaves earlier ones working; `rotate:
1265
+ * true` first replaces the host's secret, so every earlier link and cookie of this host stops working within 6
1266
+ * seconds. `cookies` sets the host's cookie rule; left out, the host keeps the one it has.
1267
+ *
1268
+ * The port must be in the sandbox's `ports` and the sandbox running or paused (404 `port_not_exposed`, 409
1269
+ * `sandbox_not_running`, and 404 `sandbox_not_found` for a sandbox of another project). While the sandbox is
1270
+ * paused or stopped its host answers 503. The host is that sandbox's and port's for good and ends with the
1271
+ * sandbox; a fork or a restore has a new ID, so new hosts. A host with no call for 49 hours is forgotten: the
1272
+ * next call makes it again with a new secret. A dev server must accept the host (for Vite,
1273
+ * `server.allowedHosts: ['.b3os.io']`). Not yet available to code inside a sandbox (its API answers 421
1274
+ * `edge_only`). Port 49983 is kept for E2B's envd and gets no host (400). Hosts count toward no address limit.
1275
+ * B3 can block a sandbox's hosts (403 `app_host_blocked`). An organization may call this 60 times a minute
1276
+ * (429 `rate_limited` with `Retry-After` past that).
1277
+ *
1278
+ * `POST /v1/sandboxes/{sandbox_id}/ports/{port}/host` · scope `sandboxes:run` · served by beta-api.b3os.org
1279
+ */
1280
+ createPortHost(sandboxId, port, body, options) {
1281
+ return this._client._call(createPortHostOp, { path: [sandboxId, port], body }, options);
1282
+ }
660
1283
  /**
661
1284
  * Get a URL for a port
662
1285
  *
@@ -697,7 +1320,10 @@ export class SandboxesAPI extends Namespace {
697
1320
  /**
698
1321
  * Signal a background process
699
1322
  *
700
- * Sends a signal (default `TERM`) to a background process and its process group, and returns the process.
1323
+ * Sends a signal (default `TERM`) to a background process and its process group, and returns the process. On a
1324
+ * process the node supervises (an exec with `restart`), the call first ends the supervision (`state: stopped`
1325
+ * in the sandbox's `supervised`), so the process stays down; with `restart: true` it stays supervised and the
1326
+ * node starts it again once it exits, counted as a restart.
701
1327
  *
702
1328
  * `POST /v1/sandboxes/{sandbox_id}/processes/{pid}/kill` · scope `sandboxes:run` · served by the node
703
1329
  */
@@ -764,8 +1390,9 @@ export class SandboxesAPI extends Namespace {
764
1390
  * searches and calls to other sandboxes), newest first, from the node's request log. These are the records
765
1391
  * `GET /v1/requests?sandbox_id=` lists, for a caller that may read the sandbox: it needs only `sandboxes:read`,
766
1392
  * not `platform:read`, and never returns another sandbox's records. It takes the same paging and the
767
- * `product`, `operation_id`, `status`, `trace_id` and `since` filters; any other query parameter is
768
- * `400 invalid_request`. Requests made to the sandbox's public ports are not listed. A sandbox stopped more
1393
+ * `product`, `operation_id`, `status`, `trace_id`, `since` and `pack` filters; any other query parameter is
1394
+ * `400 invalid_request`. `pack=io.b3os/wikipedia` lists the sandbox's calls of that pack's actions, through
1395
+ * `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
769
1396
  * than 7 days ago is not found.
770
1397
  *
771
1398
  * `GET /v1/sandboxes/{sandbox_id}/requests` · scope `sandboxes:read` · served by the node