withruntime 0.11.1 → 0.12.0

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 (176) hide show
  1. package/BLAXEL.md +3 -3
  2. package/COMPATIBILITY.md +74 -9
  3. package/DAYTONA.md +33 -5
  4. package/E2B.md +137 -48
  5. package/README.md +11 -9
  6. package/README.src.md +11 -9
  7. package/VERCEL.md +43 -5
  8. package/compatibility-lock.json +58 -49
  9. package/dist/billing-cli.d.ts +1 -1
  10. package/dist/billing-cli.js +77 -1
  11. package/dist/blaxel/errors.d.ts +14 -0
  12. package/dist/blaxel/errors.js +33 -4
  13. package/dist/blaxel/index.d.ts +2 -2
  14. package/dist/blaxel/index.js +4 -4
  15. package/dist/blaxel/interpreter.d.ts +2 -5
  16. package/dist/blaxel/sandbox.d.ts +15 -7
  17. package/dist/blaxel/sandbox.js +64 -9
  18. package/dist/blaxel/snapshot.d.ts +4 -0
  19. package/dist/blaxel/snapshot.js +4 -0
  20. package/dist/cli/logs.d.ts +21 -0
  21. package/dist/cli/logs.js +188 -0
  22. package/dist/cli/logs.test.d.ts +1 -0
  23. package/dist/cli/logs.test.js +272 -0
  24. package/dist/cli-extras.d.ts +3 -3
  25. package/dist/cli-extras.js +17 -12
  26. package/dist/cli-words.d.ts +10 -1
  27. package/dist/cli-words.js +18 -0
  28. package/dist/cli.d.ts +6 -2
  29. package/dist/cli.js +468 -219
  30. package/dist/client.d.ts +13 -63
  31. package/dist/client.js +35 -124
  32. package/dist/cloudflare/errors.d.ts +143 -0
  33. package/dist/cloudflare/errors.js +167 -0
  34. package/dist/cloudflare/index.d.ts +175 -6
  35. package/dist/cloudflare/index.js +416 -26
  36. package/dist/cloudflare/interpreter.d.ts +119 -0
  37. package/dist/cloudflare/interpreter.js +223 -0
  38. package/dist/cloudflare/streams.d.ts +38 -0
  39. package/dist/cloudflare/streams.js +145 -0
  40. package/dist/cloudflare/watch.d.ts +9 -0
  41. package/dist/cloudflare/watch.js +24 -0
  42. package/dist/codesandbox/index.d.ts +216 -28
  43. package/dist/codesandbox/index.js +478 -78
  44. package/dist/compat/core.d.ts +18 -0
  45. package/dist/compat/core.js +29 -0
  46. package/dist/compat/files.d.ts +1 -0
  47. package/dist/compat/files.js +25 -5
  48. package/dist/daytona/computer-use.d.ts +13 -4
  49. package/dist/daytona/computer-use.js +66 -8
  50. package/dist/daytona/daytona.d.ts +7 -2
  51. package/dist/daytona/daytona.js +31 -5
  52. package/dist/daytona/errors.d.ts +11 -0
  53. package/dist/daytona/errors.js +18 -0
  54. package/dist/daytona/filesystem.js +2 -1
  55. package/dist/daytona/image.d.ts +13 -9
  56. package/dist/daytona/image.js +18 -12
  57. package/dist/daytona/index.d.ts +1 -1
  58. package/dist/daytona/sandbox.d.ts +9 -3
  59. package/dist/daytona/sandbox.js +17 -3
  60. package/dist/domains/index.d.ts +9 -0
  61. package/dist/domains/index.js +10 -0
  62. package/dist/e2b/client.d.ts +15 -2
  63. package/dist/e2b/client.js +61 -7
  64. package/dist/e2b/commands.d.ts +4 -1
  65. package/dist/e2b/commands.js +17 -7
  66. package/dist/e2b/errors.d.ts +43 -2
  67. package/dist/e2b/errors.js +78 -6
  68. package/dist/e2b/filesystem.d.ts +1 -1
  69. package/dist/e2b/filesystem.js +82 -16
  70. package/dist/e2b/index.d.ts +3 -3
  71. package/dist/e2b/index.js +2 -2
  72. package/dist/e2b/sandbox.d.ts +50 -35
  73. package/dist/e2b/sandbox.js +228 -185
  74. package/dist/e2b/unsupported.d.ts +19 -0
  75. package/dist/e2b/unsupported.js +22 -1
  76. package/dist/e2b/users.d.ts +9 -0
  77. package/dist/e2b/users.js +22 -0
  78. package/dist/errors.d.ts +14 -5
  79. package/dist/errors.js +28 -14
  80. package/dist/freestyle/index.d.ts +285 -37
  81. package/dist/freestyle/index.js +656 -144
  82. package/dist/identity.d.ts +3 -0
  83. package/dist/identity.js +27 -0
  84. package/dist/images/index.d.ts +9 -0
  85. package/dist/images/index.js +10 -0
  86. package/dist/index.d.ts +1 -0
  87. package/dist/ips/index.d.ts +9 -0
  88. package/dist/ips/index.js +10 -0
  89. package/dist/jobs/index.d.ts +9 -0
  90. package/dist/jobs/index.js +10 -0
  91. package/dist/keys.js +2 -0
  92. package/dist/login.js +2 -0
  93. package/dist/machine.d.ts +189 -0
  94. package/dist/machine.js +521 -0
  95. package/dist/mcp.js +1 -1
  96. package/dist/modal/index.d.ts +339 -61
  97. package/dist/modal/index.js +781 -121
  98. package/dist/network-cli.d.ts +3 -1
  99. package/dist/network-cli.js +78 -36
  100. package/dist/networks/index.d.ts +11 -0
  101. package/dist/networks/index.js +10 -0
  102. package/dist/openai-agents/index.d.ts +1 -1
  103. package/dist/openai-agents/index.js +1 -1
  104. package/dist/ports/index.d.ts +9 -0
  105. package/dist/ports/index.js +10 -0
  106. package/dist/product-names.d.ts +52 -0
  107. package/dist/product-names.js +164 -0
  108. package/dist/product-renames.d.ts +103 -0
  109. package/dist/product-renames.js +189 -0
  110. package/dist/products/apps.d.ts +176 -0
  111. package/dist/products/apps.js +165 -0
  112. package/dist/products/billing.d.ts +41 -0
  113. package/dist/products/billing.js +13 -0
  114. package/dist/products/browser.d.ts +10 -0
  115. package/dist/products/browsers.d.ts +71 -0
  116. package/dist/products/browsers.js +102 -0
  117. package/dist/products/builds.d.ts +126 -0
  118. package/dist/products/builds.js +221 -0
  119. package/dist/products/index.d.ts +3 -16
  120. package/dist/products/index.js +3 -14
  121. package/dist/products/jobs.d.ts +19 -3
  122. package/dist/products/jobs.js +28 -12
  123. package/dist/products/limits.d.ts +4 -10
  124. package/dist/products/logs.d.ts +245 -0
  125. package/dist/products/logs.js +274 -0
  126. package/dist/products/logs.test.d.ts +1 -0
  127. package/dist/products/logs.test.js +343 -0
  128. package/dist/products/network-products.d.ts +38 -7
  129. package/dist/products/network-products.js +31 -18
  130. package/dist/products/network.d.ts +1 -1
  131. package/dist/products/observability.d.ts +3 -2
  132. package/dist/products/private-network.js +1 -1
  133. package/dist/products/queues.d.ts +149 -0
  134. package/dist/products/queues.js +213 -0
  135. package/dist/products/referrals.d.ts +21 -7
  136. package/dist/products/referrals.js +3 -3
  137. package/dist/products/secrets.d.ts +8 -4
  138. package/dist/products/secrets.js +39 -18
  139. package/dist/products/signed-requests.d.ts +21 -0
  140. package/dist/products/signed-requests.js +11 -0
  141. package/dist/products/streams.d.ts +73 -0
  142. package/dist/products/streams.js +17 -0
  143. package/dist/products/switching.d.ts +37 -10
  144. package/dist/products/switching.js +4 -3
  145. package/dist/products/volumes.d.ts +3 -0
  146. package/dist/record-cli.d.ts +23 -0
  147. package/dist/record-cli.js +308 -0
  148. package/dist/renamed-products.d.ts +38 -0
  149. package/dist/renamed-products.js +34 -0
  150. package/dist/runloop/index.d.ts +9 -2
  151. package/dist/runloop/index.js +29 -8
  152. package/dist/runloop/sdk.d.ts +131 -0
  153. package/dist/runloop/sdk.js +167 -0
  154. package/dist/sandbox.d.ts +10 -94
  155. package/dist/sandbox.js +22 -371
  156. package/dist/sandboxes/index.d.ts +11 -0
  157. package/dist/sandboxes/index.js +12 -0
  158. package/dist/snapshots/index.d.ts +9 -0
  159. package/dist/snapshots/index.js +11 -0
  160. package/dist/snapshots.d.ts +7 -4
  161. package/dist/sprites/index.d.ts +343 -31
  162. package/dist/sprites/index.js +866 -84
  163. package/dist/ssh.d.ts +1 -1
  164. package/dist/ssh.js +11 -11
  165. package/dist/terminal.d.ts +24 -0
  166. package/dist/terminal.js +32 -0
  167. package/dist/transport.d.ts +18 -2
  168. package/dist/transport.js +61 -6
  169. package/dist/tunnel.js +1 -1
  170. package/dist/types.d.ts +116 -8
  171. package/dist/vercel/sandbox.d.ts +1 -2
  172. package/dist/vercel/sandbox.js +6 -5
  173. package/dist/vercel/snapshot.js +10 -2
  174. package/dist/volumes/index.d.ts +9 -0
  175. package/dist/volumes/index.js +10 -0
  176. package/package.json +48 -2
@@ -25,3 +25,6 @@ export declare function identityToken(input: {
25
25
  lifetimeSeconds?: number;
26
26
  signal?: AbortSignal;
27
27
  }): Promise<IdentityToken>;
28
+ /** Headers for a call to the website's connect API: this sandbox's identity
29
+ * token, or none outside a sandbox or when one cannot be had. Never throws. */
30
+ export declare function sandboxIdentityHeaders(): Promise<Record<string, string>>;
package/dist/identity.js CHANGED
@@ -55,3 +55,30 @@ export async function identityToken(input) {
55
55
  });
56
56
  return body;
57
57
  }
58
+ /** The header and audience the website keys its per-network limits on
59
+ * (apps/cloud-web/src/lib/limit-key.ts): inside a sandbox, Runtime's own
60
+ * sign-in calls count against this sandbox, not the address every sandbox on
61
+ * its host shares. */
62
+ const LIMIT_HEADER = "x-runtime-sandbox-identity";
63
+ const LIMIT_AUDIENCE = "https://withruntime.com/limits";
64
+ let limitToken;
65
+ /** Headers for a call to the website's connect API: this sandbox's identity
66
+ * token, or none outside a sandbox or when one cannot be had. Never throws. */
67
+ export async function sandboxIdentityHeaders() {
68
+ if (limitToken && Date.now() < limitToken.until)
69
+ return { [LIMIT_HEADER]: limitToken.token };
70
+ if (!(await requestCredentials()))
71
+ return {};
72
+ try {
73
+ const issued = await identityToken({
74
+ audience: LIMIT_AUDIENCE,
75
+ signal: AbortSignal.timeout(3_000),
76
+ });
77
+ // Renewed a minute before it lapses, so a slow call never carries a dead one.
78
+ limitToken = { token: issued.token, until: Date.parse(issued.expiresAt) - 60_000 };
79
+ return { [LIMIT_HEADER]: issued.token };
80
+ }
81
+ catch {
82
+ return {};
83
+ }
84
+ }
@@ -0,0 +1,9 @@
1
+ /** `withruntime/images`: Images alone. Custom images to start sandboxes from.
2
+ *
3
+ * import { images } from "withruntime/images";
4
+ * const client = images(); // RUNTIME_API_KEY, or this machine's saved connection
5
+ */
6
+ import { Runtime, type RuntimeOptions } from "../client.js";
7
+ export type * from "../products/images.js";
8
+ /** `runtime.images` of a client made with `options`. */
9
+ export declare function images(options?: RuntimeOptions): Runtime["images"];
@@ -0,0 +1,10 @@
1
+ /** `withruntime/images`: Images alone. Custom images to start sandboxes from.
2
+ *
3
+ * import { images } from "withruntime/images";
4
+ * const client = images(); // RUNTIME_API_KEY, or this machine's saved connection
5
+ */
6
+ import { Runtime } from "../client.js";
7
+ /** `runtime.images` of a client made with `options`. */
8
+ export function images(options) {
9
+ return new Runtime(options).images;
10
+ }
package/dist/index.d.ts CHANGED
@@ -26,6 +26,7 @@ export type { Volume, VolumeBackup, CreateVolume, VolumeAttachment } from "./pro
26
26
  export type { CreateJob, Job, JobCompute, JobDefinition, JobLogs, JobRun, JobRunState, JobSchedule, } from "./products/jobs.js";
27
27
  export type { CheckedDomain, DnsRecord, Domain, EgressAddress, TcpPort, Tunnel as PrivateTunnel, TunnelPeer, TunnelPeerCreated, SetUpstreamProxy, UpstreamProxy, } from "./products/network-products.js";
28
28
  export type { PrivateNetwork } from "./products/private-network.js";
29
+ export type { SignedRequests } from "./products/signed-requests.js";
29
30
  export { verifyWebhook, WebhookVerificationError, type MetricPoint, type MetricRange, type OtelExport, type RuntimeEvent, type SandboxMetrics, type Webhook, type WebhookDelivery, type WebhookEventType, } from "./products/observability.js";
30
31
  export { Snapshots, type Snapshot, type SnapshotOptions } from "./snapshots.js";
31
32
  export { Transport, VERSION, apiOrigin, type RequestOptions, type Call } from "./transport.js";
@@ -0,0 +1,9 @@
1
+ /** `withruntime/ips`: IPs alone. Dedicated outbound addresses every sandbox of the account sends from.
2
+ *
3
+ * import { ips } from "withruntime/ips";
4
+ * const client = ips(); // RUNTIME_API_KEY, or this machine's saved connection
5
+ */
6
+ import { Runtime, type RuntimeOptions } from "../client.js";
7
+ export type { EgressAddress, NetworkFunding } from "../products/network-products.js";
8
+ /** `runtime.ips` of a client made with `options`. */
9
+ export declare function ips(options?: RuntimeOptions): Runtime["ips"];
@@ -0,0 +1,10 @@
1
+ /** `withruntime/ips`: IPs alone. Dedicated outbound addresses every sandbox of the account sends from.
2
+ *
3
+ * import { ips } from "withruntime/ips";
4
+ * const client = ips(); // RUNTIME_API_KEY, or this machine's saved connection
5
+ */
6
+ import { Runtime } from "../client.js";
7
+ /** `runtime.ips` of a client made with `options`. */
8
+ export function ips(options) {
9
+ return new Runtime(options).ips;
10
+ }
@@ -0,0 +1,9 @@
1
+ /** `withruntime/jobs`: Jobs alone. A command in a fresh sandbox, once or on a schedule.
2
+ *
3
+ * import { jobs } from "withruntime/jobs";
4
+ * const client = jobs(); // RUNTIME_API_KEY, or this machine's saved connection
5
+ */
6
+ import { Runtime, type RuntimeOptions } from "../client.js";
7
+ export type * from "../products/jobs.js";
8
+ /** `runtime.jobs` of a client made with `options`. */
9
+ export declare function jobs(options?: RuntimeOptions): Runtime["jobs"];
@@ -0,0 +1,10 @@
1
+ /** `withruntime/jobs`: Jobs alone. A command in a fresh sandbox, once or on a schedule.
2
+ *
3
+ * import { jobs } from "withruntime/jobs";
4
+ * const client = jobs(); // RUNTIME_API_KEY, or this machine's saved connection
5
+ */
6
+ import { Runtime } from "../client.js";
7
+ /** `runtime.jobs` of a client made with `options`. */
8
+ export function jobs(options) {
9
+ return new Runtime(options).jobs;
10
+ }
package/dist/keys.js CHANGED
@@ -5,6 +5,7 @@ import { promisify } from "node:util";
5
5
  import { connectionOrigins } from "./credentials.js";
6
6
  import { RuntimeError } from "./errors.js";
7
7
  import { named } from "./cli-name.js";
8
+ import { sandboxIdentityHeaders } from "./identity.js";
8
9
  import { describeRoute, envFetch } from "./proxy.js";
9
10
  const KEY = /^rtcloud_([a-f0-9-]{36})_[A-Za-z0-9_-]{43}$/;
10
11
  /** How often to ask whether the owner has answered. The website answers
@@ -79,6 +80,7 @@ export async function createKey(request, env, options = {}) {
79
80
  headers: {
80
81
  "content-type": "application/json",
81
82
  ...(key ? { authorization: `Bearer ${key}` } : {}),
83
+ ...(await sandboxIdentityHeaders()),
82
84
  },
83
85
  body: JSON.stringify(body),
84
86
  });
package/dist/login.js CHANGED
@@ -5,6 +5,7 @@ import { promisify } from "node:util";
5
5
  import { me, named } from "./cli-name.js";
6
6
  import { Runtime } from "./client.js";
7
7
  import { checkBrowserOrigins, connectionOrigins, connectionStore } from "./credentials.js";
8
+ import { sandboxIdentityHeaders } from "./identity.js";
8
9
  import { describeRoute, envFetch } from "./proxy.js";
9
10
  class ConnectionError extends Error {
10
11
  status;
@@ -80,6 +81,7 @@ function connection(env, options) {
80
81
  headers: {
81
82
  "content-type": "application/json",
82
83
  ...(key ? { authorization: `Bearer ${key}` } : {}),
84
+ ...(await sandboxIdentityHeaders()),
83
85
  },
84
86
  body: JSON.stringify(body ?? {}),
85
87
  });
@@ -0,0 +1,189 @@
1
+ import { RuntimeError } from "./errors.js";
2
+ import { Page } from "./page.js";
3
+ import type { Snapshot, SnapshotOptions } from "./snapshots.js";
4
+ import type { RequestOptions, Transport } from "./transport.js";
5
+ import type { KeepAliveOptions } from "./types.js";
6
+ /** One machine product: the API serves it at /v1/<plural>, and its errors
7
+ * call one of it by `noun`. */
8
+ export type MachineProduct = {
9
+ readonly plural: string;
10
+ readonly noun: string;
11
+ };
12
+ /** What every machine's record carries for the verbs shared here. */
13
+ export type MachineState = "starting" | "running" | "pausing" | "paused" | "resuming" | "stopping" | "stopped";
14
+ export type MachineInfo = {
15
+ id: string;
16
+ state: MachineState;
17
+ expiresAt: string;
18
+ endsAt?: string | null;
19
+ start?: unknown;
20
+ /** True when getOrCreate found the name already held. */
21
+ reused?: boolean;
22
+ /** True when the answer repeats an earlier call under the same idempotency key. */
23
+ replayed?: boolean;
24
+ };
25
+ /** Any other call's request options, as the caller gave them: `timeoutMs` is
26
+ * the call's whole deadline, and 0 turns it off. */
27
+ export declare function requestOnly(options: RequestOptions): RequestOptions;
28
+ /** DELETE /v1/<plural>/{id}, for `machine.delete()` and the product's
29
+ * `delete(id)`. */
30
+ export declare function deleteMachine<Deleted>(product: MachineProduct, t: Transport, id: string, options?: RequestOptions): Promise<Deleted>;
31
+ /** One page of a product's list, and the pages after it. */
32
+ export declare function machinePage<M, Info>(product: MachineProduct, t: Transport, wrap: (t: Transport, info: Info) => M, body: {
33
+ data: Info[];
34
+ nextCursor: string | null;
35
+ }, query: Record<string, unknown>, options?: RequestOptions): Page<M>;
36
+ export declare abstract class Machine<Info extends MachineInfo, Settings extends object, Deleted> implements AsyncDisposable {
37
+ #private;
38
+ constructor(product: MachineProduct, transport: Transport, info: Info);
39
+ get id(): string;
40
+ /** What the API last said about this sandbox. `refresh()` asks again. */
41
+ get info(): Info;
42
+ get state(): Info["state"];
43
+ refresh(options?: RequestOptions): Promise<this>;
44
+ /** Waits (server-side, no polling) until the sandbox reaches `state`. */
45
+ waitFor(state: "running" | "paused" | "stopped", options?: {
46
+ timeoutSeconds?: number;
47
+ } & RequestOptions): Promise<this>;
48
+ stop(options?: RequestOptions & {
49
+ wait?: boolean;
50
+ }): Promise<this>;
51
+ pause(options?: RequestOptions & {
52
+ wait?: boolean;
53
+ }): Promise<this>;
54
+ /** Deletes it for good: stops it if it runs or is paused, deletes its disk
55
+ * and paused memory, revokes its previews and ports, and removes it from
56
+ * lists. Its snapshots, usage and audit entries stay. Deleting it again
57
+ * answers the same. */
58
+ delete(options?: RequestOptions): Promise<Deleted>;
59
+ /** Carries on a paused sandbox; for one with a time limit,
60
+ * `timeoutSeconds` is its new one. */
61
+ wake(options?: RequestOptions & {
62
+ wait?: boolean;
63
+ timeoutSeconds?: number;
64
+ }): Promise<this>;
65
+ /** More time before its time limit ends (at most an hour ahead of now). A
66
+ * sandbox with no time limit needs none: the call answers at once and
67
+ * changes nothing. */
68
+ extend(seconds: number, options?: RequestOptions): Promise<this>;
69
+ /** Changes its name, labels, automatic wake, idle pause or persistence;
70
+ * fields left out stay as they are. `persistent: true` keeps it running
71
+ * while credit lasts (paid only). */
72
+ update(settings: Settings, options?: RequestOptions): Promise<this>;
73
+ /** Moves it to another image (id, name, name:tag or name@version), keeping
74
+ * its id, /workspace (its home: dotfiles, pip --user and npm -g installs),
75
+ * volumes, environment, name and previews. Its processes restart, and
76
+ * everything else on its old disk (sudo installs, apt packages, /etc) is
77
+ * lost; snapshot it first to keep everything. A running sandbox is paused
78
+ * first. A switch that fails is undone (`switch_undone`), the sandbox on
79
+ * its old image with nothing lost. Charged as a wake. `keep` is optional:
80
+ * "workspace" is the only value, and it is sent either way, so an API from
81
+ * before it was optional accepts the call too. */
82
+ switchImage(image: string, options?: RequestOptions & {
83
+ keep?: "workspace";
84
+ }): Promise<this>;
85
+ /** Gives it more or fewer vCPUs or more or less memory by a restart: its id,
86
+ * whole disk, volumes, environment, name and previews stay, and its
87
+ * programs stop (snapshot it first to keep its memory too). A running sandbox is paused, or stopped if it is
88
+ * persistent, and comes back running at the new size on the same server; a
89
+ * paused or stopped one is started. Memory bills on the new size from then.
90
+ * Refused, with nothing changed, when the server has no room
91
+ * (`no_capacity`), above your quota or the 2 vCPU and 4 GiB without credit, or
92
+ * while a snapshot or fork of it is being taken. `restart` is optional:
93
+ * true is the only value, and it is sent either way, so an API from before
94
+ * it was optional accepts the call too. */
95
+ resize(size: {
96
+ vcpu?: number;
97
+ memoryMiB?: number;
98
+ }, options?: RequestOptions & {
99
+ restart?: true;
100
+ }): Promise<this>;
101
+ /** Keeps a sandbox with a time limit running past it, in the background,
102
+ * until stop() or the returned function ends it: every `everySeconds` (60)
103
+ * it extends the limit so that `marginSeconds` (600) remain, never more
104
+ * than the hour ahead the API allows. A sandbox with no time limit
105
+ * (`endsAt` null) needs none, and is only watched. Running time is billed
106
+ * as it is used. A paused sandbox is left paused (a request wakes it,
107
+ * unless autoWake is off); a stopped one ends the loop. It does not keep a
108
+ * Node or Bun process alive by itself. */
109
+ keepAlive(options?: KeepAliveOptions): () => void;
110
+ /** Days a paused sandbox is kept before deletion (1 to 365), or `null` to
111
+ * keep it while your account has credit. */
112
+ setRetention(days: number | null, options?: RequestOptions): Promise<this>;
113
+ /** Keeps this sandbox's whole machine (files, memory, running processes) as
114
+ * a snapshot to start new sandboxes from. A running sandbox is paused for
115
+ * the moment it takes, then woken; a paused one stays paused. Past
116
+ * `timeoutMs` (ten minutes unless given) mid-capture, it stays paused and
117
+ * the error names the snapshot. */
118
+ snapshot(options?: SnapshotOptions & RequestOptions): Promise<Snapshot>;
119
+ /** Starts a stopped persistent sandbox again from its disk (memory is not kept). */
120
+ restart(options?: RequestOptions & {
121
+ wait?: boolean;
122
+ }): Promise<this>;
123
+ /** The end of an `await using` block. A sandbox this client created is
124
+ * deleted, as E2B's block kills it, unless it was created with
125
+ * `keep: true`; one it found with `get` or `getOrCreate` is stopped, which
126
+ * keeps its disk. */
127
+ [Symbol.asyncDispose](): Promise<void>;
128
+ toJSON(): Info;
129
+ }
130
+ /** How a product's `create` waits when every slot without credit, the account's quota
131
+ * or the region is full. */
132
+ export type CreateOptions = RequestOptions & {
133
+ /** How long to keep retrying a refusal that clears by itself. Default: the
134
+ * client's, two minutes; 0 fails at once. */
135
+ waitForCapacityMs?: number;
136
+ /** Called before each wait, with the refusal and the milliseconds until the
137
+ * next try: to tell a person why nothing has happened yet. */
138
+ onCapacityWait?: (refusal: RuntimeError, waitMs: number) => void;
139
+ };
140
+ /** A machine product's collection: `runtime.<product>`. */
141
+ export declare abstract class Machines<M extends Machine<Info, object, Deleted>, Info extends MachineInfo, Create extends {
142
+ name?: string;
143
+ getOrCreate?: boolean;
144
+ keep?: boolean;
145
+ }, Deleted> {
146
+ #private;
147
+ constructor(product: MachineProduct, t: Transport, wrap: (t: Transport, info: Info) => M);
148
+ /** Creates a sandbox and waits until it is running. Every field is optional:
149
+ * with none you get the included usage while it lasts, the default region and a
150
+ * 2 vCPU / 4 GiB machine from a warm template. `wait: false` returns at once.
151
+ * When every slot without credit or the account's quota is taken, it waits for one to
152
+ * free, up to `waitForCapacityMs` (the client's, two minutes by default). */
153
+ create(input?: Create & {
154
+ wait?: boolean;
155
+ }, options?: CreateOptions): Promise<M>;
156
+ /** The sandbox named `name` in this account, ready to use: running as it
157
+ * is, woken if it is paused, restarted if it is stopped and persistent, or
158
+ * created with `input` when no sandbox has the name. `sandbox.info.reused`
159
+ * says which. The other fields apply only when it is created. */
160
+ getOrCreate(name: string, input?: Omit<Create, "name" | "getOrCreate"> & {
161
+ wait?: boolean;
162
+ }, options?: CreateOptions): Promise<M>;
163
+ get(id: string, options?: RequestOptions): Promise<M>;
164
+ /** Deletes a sandbox for good, by id, without reading it first: see
165
+ * `sandbox.delete()`. Deleting it again answers the same. */
166
+ delete(id: string, options?: RequestOptions): Promise<Deleted>;
167
+ /** Live sandboxes, oldest first. Await for a page, or `for await` over all.
168
+ * Request options apply to the initial request and every subsequent page. */
169
+ list(filter?: {
170
+ state?: Info["state"][];
171
+ includeStopped?: boolean;
172
+ /** Every label must match. */
173
+ labels?: Record<string, string>;
174
+ name?: string;
175
+ limit?: number;
176
+ }, options?: RequestOptions): Promise<Page<M>>;
177
+ /** Stops every live sandbox whose labels all match, eight at a time, and
178
+ * says which stopped and which failed; one failure does not stop the rest.
179
+ * Needs at least one label, so stopping everything is never one call. */
180
+ stopAll(filter: {
181
+ labels: Record<string, string>;
182
+ }, options?: RequestOptions): Promise<{
183
+ stopped: string[];
184
+ failed: {
185
+ id: string;
186
+ error: unknown;
187
+ }[];
188
+ }>;
189
+ }