withruntime 0.11.2 → 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 (164) hide show
  1. package/BLAXEL.md +2 -2
  2. package/COMPATIBILITY.md +74 -9
  3. package/DAYTONA.md +33 -5
  4. package/E2B.md +85 -24
  5. package/README.md +9 -8
  6. package/README.src.md +8 -7
  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 +29 -0
  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 +14 -5
  17. package/dist/blaxel/sandbox.js +63 -7
  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 +5 -1
  29. package/dist/cli.js +405 -204
  30. package/dist/client.d.ts +2 -4
  31. package/dist/client.js +27 -11
  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 +6 -0
  51. package/dist/daytona/daytona.js +30 -3
  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 +8 -2
  59. package/dist/daytona/sandbox.js +16 -2
  60. package/dist/domains/index.d.ts +9 -0
  61. package/dist/domains/index.js +10 -0
  62. package/dist/e2b/commands.d.ts +1 -1
  63. package/dist/e2b/commands.js +6 -7
  64. package/dist/e2b/errors.d.ts +17 -0
  65. package/dist/e2b/errors.js +40 -1
  66. package/dist/e2b/index.d.ts +2 -2
  67. package/dist/e2b/index.js +1 -1
  68. package/dist/e2b/sandbox.d.ts +27 -21
  69. package/dist/e2b/sandbox.js +34 -8
  70. package/dist/e2b/unsupported.js +1 -1
  71. package/dist/errors.d.ts +10 -1
  72. package/dist/errors.js +16 -4
  73. package/dist/freestyle/index.d.ts +285 -37
  74. package/dist/freestyle/index.js +656 -144
  75. package/dist/identity.d.ts +3 -0
  76. package/dist/identity.js +27 -0
  77. package/dist/images/index.d.ts +9 -0
  78. package/dist/images/index.js +10 -0
  79. package/dist/index.d.ts +1 -0
  80. package/dist/ips/index.d.ts +9 -0
  81. package/dist/ips/index.js +10 -0
  82. package/dist/jobs/index.d.ts +9 -0
  83. package/dist/jobs/index.js +10 -0
  84. package/dist/keys.js +2 -0
  85. package/dist/login.js +2 -0
  86. package/dist/machine.d.ts +12 -3
  87. package/dist/machine.js +20 -3
  88. package/dist/mcp.js +1 -1
  89. package/dist/modal/index.d.ts +339 -61
  90. package/dist/modal/index.js +781 -121
  91. package/dist/network-cli.d.ts +3 -1
  92. package/dist/network-cli.js +78 -36
  93. package/dist/networks/index.d.ts +11 -0
  94. package/dist/networks/index.js +10 -0
  95. package/dist/ports/index.d.ts +9 -0
  96. package/dist/ports/index.js +10 -0
  97. package/dist/product-names.d.ts +52 -0
  98. package/dist/product-names.js +164 -0
  99. package/dist/product-renames.d.ts +103 -0
  100. package/dist/product-renames.js +189 -0
  101. package/dist/products/apps.d.ts +176 -0
  102. package/dist/products/apps.js +165 -0
  103. package/dist/products/billing.d.ts +41 -0
  104. package/dist/products/billing.js +13 -0
  105. package/dist/products/browser.d.ts +10 -0
  106. package/dist/products/browsers.d.ts +71 -0
  107. package/dist/products/browsers.js +102 -0
  108. package/dist/products/builds.d.ts +126 -0
  109. package/dist/products/builds.js +221 -0
  110. package/dist/products/index.d.ts +3 -16
  111. package/dist/products/index.js +3 -14
  112. package/dist/products/jobs.d.ts +17 -0
  113. package/dist/products/jobs.js +27 -10
  114. package/dist/products/logs.d.ts +245 -0
  115. package/dist/products/logs.js +274 -0
  116. package/dist/products/logs.test.d.ts +1 -0
  117. package/dist/products/logs.test.js +343 -0
  118. package/dist/products/network-products.d.ts +38 -7
  119. package/dist/products/network-products.js +31 -18
  120. package/dist/products/observability.d.ts +3 -2
  121. package/dist/products/private-network.js +1 -1
  122. package/dist/products/queues.d.ts +149 -0
  123. package/dist/products/queues.js +213 -0
  124. package/dist/products/referrals.d.ts +21 -7
  125. package/dist/products/referrals.js +3 -3
  126. package/dist/products/secrets.d.ts +7 -3
  127. package/dist/products/secrets.js +39 -18
  128. package/dist/products/signed-requests.d.ts +21 -0
  129. package/dist/products/signed-requests.js +11 -0
  130. package/dist/products/streams.d.ts +73 -0
  131. package/dist/products/streams.js +17 -0
  132. package/dist/products/switching.d.ts +35 -7
  133. package/dist/products/switching.js +4 -3
  134. package/dist/products/volumes.d.ts +3 -0
  135. package/dist/record-cli.d.ts +23 -0
  136. package/dist/record-cli.js +308 -0
  137. package/dist/renamed-products.d.ts +38 -0
  138. package/dist/renamed-products.js +34 -0
  139. package/dist/runloop/index.d.ts +9 -2
  140. package/dist/runloop/index.js +29 -8
  141. package/dist/runloop/sdk.d.ts +131 -0
  142. package/dist/runloop/sdk.js +167 -0
  143. package/dist/sandbox.d.ts +3 -2
  144. package/dist/sandbox.js +14 -9
  145. package/dist/sandboxes/index.d.ts +11 -0
  146. package/dist/sandboxes/index.js +12 -0
  147. package/dist/snapshots/index.d.ts +9 -0
  148. package/dist/snapshots/index.js +11 -0
  149. package/dist/snapshots.d.ts +7 -4
  150. package/dist/sprites/index.d.ts +343 -31
  151. package/dist/sprites/index.js +866 -84
  152. package/dist/ssh.d.ts +1 -1
  153. package/dist/ssh.js +11 -11
  154. package/dist/terminal.d.ts +24 -0
  155. package/dist/terminal.js +32 -0
  156. package/dist/transport.d.ts +15 -1
  157. package/dist/transport.js +56 -3
  158. package/dist/tunnel.js +1 -1
  159. package/dist/types.d.ts +63 -0
  160. package/dist/vercel/sandbox.js +5 -3
  161. package/dist/vercel/snapshot.js +10 -2
  162. package/dist/volumes/index.d.ts +9 -0
  163. package/dist/volumes/index.js +10 -0
  164. 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
  });
package/dist/machine.d.ts CHANGED
@@ -17,6 +17,10 @@ export type MachineInfo = {
17
17
  expiresAt: string;
18
18
  endsAt?: string | null;
19
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;
20
24
  };
21
25
  /** Any other call's request options, as the caller gave them: `timeoutMs` is
22
26
  * the call's whole deadline, and 0 turns it off. */
@@ -29,7 +33,6 @@ export declare function machinePage<M, Info>(product: MachineProduct, t: Transpo
29
33
  data: Info[];
30
34
  nextCursor: string | null;
31
35
  }, query: Record<string, unknown>, options?: RequestOptions): Page<M>;
32
- /** One machine: its record and the verbs every machine product shares. */
33
36
  export declare abstract class Machine<Info extends MachineInfo, Settings extends object, Deleted> implements AsyncDisposable {
34
37
  #private;
35
38
  constructor(product: MachineProduct, transport: Transport, info: Info);
@@ -104,8 +107,9 @@ export declare abstract class Machine<Info extends MachineInfo, Settings extends
104
107
  * unless autoWake is off); a stopped one ends the loop. It does not keep a
105
108
  * Node or Bun process alive by itself. */
106
109
  keepAlive(options?: KeepAliveOptions): () => void;
107
- /** Days a paused sandbox is kept before deletion (1 to 365). */
108
- setRetention(days: number, options?: RequestOptions): Promise<this>;
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>;
109
113
  /** Keeps this sandbox's whole machine (files, memory, running processes) as
110
114
  * a snapshot to start new sandboxes from. A running sandbox is paused for
111
115
  * the moment it takes, then woken; a paused one stays paused. Past
@@ -116,6 +120,10 @@ export declare abstract class Machine<Info extends MachineInfo, Settings extends
116
120
  restart(options?: RequestOptions & {
117
121
  wait?: boolean;
118
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. */
119
127
  [Symbol.asyncDispose](): Promise<void>;
120
128
  toJSON(): Info;
121
129
  }
@@ -133,6 +141,7 @@ export type CreateOptions = RequestOptions & {
133
141
  export declare abstract class Machines<M extends Machine<Info, object, Deleted>, Info extends MachineInfo, Create extends {
134
142
  name?: string;
135
143
  getOrCreate?: boolean;
144
+ keep?: boolean;
136
145
  }, Deleted> {
137
146
  #private;
138
147
  constructor(product: MachineProduct, t: Transport, wrap: (t: Transport, info: Info) => M);
package/dist/machine.js CHANGED
@@ -40,6 +40,10 @@ export function machinePage(product, t, wrap, body, query, options = {}) {
40
40
  }), query, options));
41
41
  }
42
42
  /** One machine: its record and the verbs every machine product shares. */
43
+ /** Machines `create` made, which the end of an `await using` block deletes
44
+ * (Marc, 6 October 2026: deleted unless the code passes `keep: true`). One
45
+ * from `get`, or an existing one `getOrCreate` found, is only stopped. */
46
+ const deleteAtBlockEnd = new WeakSet();
43
47
  export class Machine {
44
48
  #info;
45
49
  #keepAlive;
@@ -227,7 +231,8 @@ export class Machine {
227
231
  void tick();
228
232
  return end;
229
233
  }
230
- /** Days a paused sandbox is kept before deletion (1 to 365). */
234
+ /** Days a paused sandbox is kept before deletion (1 to 365), or `null` to
235
+ * keep it while your account has credit. */
231
236
  async setRetention(days, options = {}) {
232
237
  return this.#lifecycle("retention", { ...options, wait: false }, { days });
233
238
  }
@@ -374,8 +379,16 @@ export class Machine {
374
379
  }));
375
380
  return this;
376
381
  }
382
+ /** The end of an `await using` block. A sandbox this client created is
383
+ * deleted, as E2B's block kills it, unless it was created with
384
+ * `keep: true`; one it found with `get` or `getOrCreate` is stopped, which
385
+ * keeps its disk. */
377
386
  async [Symbol.asyncDispose]() {
378
387
  this.#keepAlive?.();
388
+ if (deleteAtBlockEnd.has(this)) {
389
+ await this.delete().catch(() => undefined);
390
+ return;
391
+ }
379
392
  if (this.#info.state === "stopped")
380
393
  return;
381
394
  await this.stop({ wait: false }).catch(() => undefined);
@@ -400,7 +413,7 @@ export class Machines {
400
413
  * When every slot without credit or the account's quota is taken, it waits for one to
401
414
  * free, up to `waitForCapacityMs` (the client's, two minutes by default). */
402
415
  async create(input = {}, options = {}) {
403
- const { wait, ...body } = input;
416
+ const { wait, keep, ...body } = input;
404
417
  const began = performance.now();
405
418
  // Time spent waiting for capacity is the room's, not the deadline's.
406
419
  let waited = 0;
@@ -417,6 +430,8 @@ export class Machines {
417
430
  },
418
431
  });
419
432
  const machine = this.#wrap(this.#t, info);
433
+ if (!keep && !info.reused)
434
+ deleteAtBlockEnd.add(machine);
420
435
  if (wait !== false && info.state !== "running") {
421
436
  // One deadline for the whole create: the wait for running gets what the
422
437
  // create left of it (1 ms when nothing is left, so it ends as a timeout).
@@ -431,7 +446,9 @@ export class Machines {
431
446
  });
432
447
  if (machine.state !== "running")
433
448
  throw new RuntimeError({
434
- message: `${this.#product.noun} ${info.id} is ${machine.state}, not running.`,
449
+ message: info.replayed
450
+ ? `${this.#product.noun} ${info.id} was made by an earlier call with this idempotency key and is ${machine.state} now. It did not fail to start; create again with a new key.`
451
+ : `${this.#product.noun} ${info.id} is ${machine.state}, not running.`,
435
452
  code: "start_failed",
436
453
  status: 0,
437
454
  hint: `Read it with runtime.${this.#product.plural}.get(id); stopReason says why.`,
package/dist/mcp.js CHANGED
@@ -163,7 +163,7 @@ export async function serveMcp(env = process.env, options = {}) {
163
163
  }));
164
164
  await post(JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }));
165
165
  write({ jsonrpc: "2.0", method: "notifications/tools/list_changed" });
166
- return text(`Connected as ${outcome.agentName}. Runtime's tools are available now: list the tools again, then start with runtime_sandbox_create.`);
166
+ return text(`Connected as ${outcome.agentName}. Runtime's tools are available now: list the tools again, then start with runtime_sandboxes_create.`);
167
167
  }
168
168
  await new Promise((resolve) => setTimeout(resolve, 3000));
169
169
  }