withruntime 0.8.3 → 0.9.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 (92) hide show
  1. package/COMPATIBILITY.md +145 -0
  2. package/E2B.md +23 -13
  3. package/README.md +8 -5
  4. package/README.src.md +8 -5
  5. package/compatibility-lock.json +281 -0
  6. package/dist/ai-harness/index.js +2 -2
  7. package/dist/api-defaults.d.ts +17 -0
  8. package/dist/api-defaults.js +22 -0
  9. package/dist/blaxel/preview.d.ts +1 -1
  10. package/dist/blaxel/preview.js +1 -1
  11. package/dist/blaxel/process.d.ts +1 -1
  12. package/dist/blaxel/process.js +11 -2
  13. package/dist/cli-words.d.ts +27 -0
  14. package/dist/cli-words.js +135 -0
  15. package/dist/cli.js +162 -31
  16. package/dist/client.d.ts +4 -1
  17. package/dist/client.js +8 -2
  18. package/dist/cloudflare/index.d.ts +294 -0
  19. package/dist/cloudflare/index.js +554 -0
  20. package/dist/cloudflare/worker.d.ts +415 -0
  21. package/dist/cloudflare/worker.js +297 -0
  22. package/dist/codesandbox/guest-service.d.ts +31 -0
  23. package/dist/codesandbox/guest-service.js +453 -0
  24. package/dist/codesandbox/index.d.ts +386 -0
  25. package/dist/codesandbox/index.js +1313 -0
  26. package/dist/compat/core.d.ts +39 -0
  27. package/dist/compat/core.js +199 -0
  28. package/dist/compat/files.d.ts +26 -0
  29. package/dist/compat/files.js +115 -0
  30. package/dist/compat/shell.d.ts +4 -0
  31. package/dist/compat/shell.js +165 -0
  32. package/dist/daytona/context.js +2 -1
  33. package/dist/daytona/process.d.ts +1 -1
  34. package/dist/daytona/process.js +27 -4
  35. package/dist/e2b/code-interpreter.d.ts +4 -5
  36. package/dist/e2b/code-interpreter.js +54 -56
  37. package/dist/e2b/commands.d.ts +5 -4
  38. package/dist/e2b/commands.js +37 -29
  39. package/dist/e2b/errors.js +1 -1
  40. package/dist/e2b/filesystem.d.ts +8 -6
  41. package/dist/e2b/filesystem.js +127 -28
  42. package/dist/e2b/sandbox.d.ts +4 -3
  43. package/dist/e2b/sandbox.js +10 -10
  44. package/dist/errors.d.ts +8 -0
  45. package/dist/errors.js +15 -2
  46. package/dist/freestyle/index.d.ts +301 -0
  47. package/dist/freestyle/index.js +310 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/mcp.js +2 -2
  50. package/dist/modal/index.d.ts +205 -0
  51. package/dist/modal/index.js +485 -0
  52. package/dist/network-cli.js +1 -1
  53. package/dist/openai-agents/index.js +9 -26
  54. package/dist/products/audit.d.ts +3 -0
  55. package/dist/products/index.d.ts +2 -0
  56. package/dist/products/index.js +2 -0
  57. package/dist/products/interpreter.d.ts +11 -4
  58. package/dist/products/interpreter.js +33 -9
  59. package/dist/products/jobs.d.ts +1 -1
  60. package/dist/products/jobs.js +5 -4
  61. package/dist/products/limits.d.ts +10 -0
  62. package/dist/products/previews.d.ts +10 -2
  63. package/dist/products/previews.js +3 -2
  64. package/dist/products/tailscale.d.ts +57 -0
  65. package/dist/products/tailscale.js +17 -0
  66. package/dist/products/watch.d.ts +25 -4
  67. package/dist/products/watch.js +75 -14
  68. package/dist/runloop/index.d.ts +340 -0
  69. package/dist/runloop/index.js +438 -0
  70. package/dist/runloop/pagination.d.ts +46 -0
  71. package/dist/runloop/pagination.js +82 -0
  72. package/dist/runloop/snapshots.d.ts +52 -0
  73. package/dist/runloop/snapshots.js +244 -0
  74. package/dist/sandbox.d.ts +40 -9
  75. package/dist/sandbox.js +273 -76
  76. package/dist/snapshots.d.ts +11 -1
  77. package/dist/snapshots.js +11 -1
  78. package/dist/sprites/index.d.ts +251 -0
  79. package/dist/sprites/index.js +552 -0
  80. package/dist/tar.d.ts +8 -1
  81. package/dist/tar.js +185 -35
  82. package/dist/tools/index.js +2 -1
  83. package/dist/transport.d.ts +20 -2
  84. package/dist/transport.js +48 -11
  85. package/dist/types.d.ts +52 -3
  86. package/dist/vercel/command.js +12 -1
  87. package/dist/vercel/errors.d.ts +2 -2
  88. package/dist/vercel/errors.js +12 -1
  89. package/dist/vercel/filesystem.d.ts +21 -18
  90. package/dist/vercel/filesystem.js +95 -48
  91. package/dist/vercel/sandbox.js +5 -5
  92. package/package.json +45 -3
@@ -131,22 +131,21 @@ function unsupported(feature, alternative) {
131
131
  /** Where Runtime serves previews; getHost names a host under it. */
132
132
  const PREVIEW_DOMAIN = "runtimehost.com";
133
133
  export class Sandbox {
134
+ requestTimeoutMs;
134
135
  static defaultTemplate = "base";
135
136
  files;
136
137
  commands;
137
138
  #client;
138
139
  #runtime;
139
- #envs;
140
140
  #home;
141
141
  /** Ports shared as public previews, by port: the one share each asked for. */
142
142
  #shares = new Map();
143
143
  /** Use Sandbox.create or Sandbox.connect. */
144
- constructor(runtime, client, envs = {}) {
144
+ constructor(runtime, client, requestTimeoutMs = 60_000) {
145
+ this.requestTimeoutMs = requestTimeoutMs;
145
146
  this.#runtime = runtime;
146
147
  this.#client = client;
147
- this.#envs = envs;
148
148
  const ctx = {
149
- envs,
150
149
  ensureHome: (text) => this.#ensureHome(text),
151
150
  };
152
151
  // A getter, so the modules see the sandbox as it is after each refresh.
@@ -165,9 +164,6 @@ export class Sandbox {
165
164
  get client() {
166
165
  return this.#client;
167
166
  }
168
- get envs() {
169
- return this.#envs;
170
- }
171
167
  /** E2B's home is /home/user and Runtime's is /workspace. The first time a
172
168
  * path or command names /home/user, it is made a link to /workspace (unless
173
169
  * something is already there), so paths written for E2B work. */
@@ -195,6 +191,9 @@ export class Sandbox {
195
191
  // asked (autoResume); Runtime's automatic wake is the same thing (0093).
196
192
  ...(opts.lifecycle ? { autoWake: opts.lifecycle.autoResume === true } : {}),
197
193
  ...(opts.metadata && Object.keys(opts.metadata).length ? { labels: opts.metadata } : {}),
194
+ // Runtime keeps them with the sandbox: every command, terminal and
195
+ // interpreter in it gets them, from this client or any other.
196
+ ...(opts.envs && Object.keys(opts.envs).length ? { env: opts.envs } : {}),
198
197
  ...(opts.allowInternetAccess === false ? { network: { internet: false } } : {}),
199
198
  };
200
199
  const source = await guard("other", () => resolveTemplate(client, template));
@@ -206,7 +205,7 @@ export class Sandbox {
206
205
  ...opts.runtime?.create,
207
206
  };
208
207
  const runtime = await guard("sandbox", () => client.sandboxes.create(create, request(opts)));
209
- return new this(runtime, client, { ...opts.envs });
208
+ return new this(runtime, client, opts.requestTimeoutMs);
210
209
  }
211
210
  /** Connects to a sandbox by id, waking it if it is paused, as E2B does. A
212
211
  * `timeoutMs` moves a running sandbox's end later, never earlier. */
@@ -214,7 +213,7 @@ export class Sandbox {
214
213
  const client = clientFor(opts);
215
214
  const runtime = await guard("sandbox", () => client.sandboxes.get(sandboxId, request(opts)));
216
215
  await resume(runtime, opts);
217
- return new this(runtime, client);
216
+ return new this(runtime, client, opts.requestTimeoutMs);
218
217
  }
219
218
  /** Wakes this sandbox if it is paused. */
220
219
  async connect(opts = {}) {
@@ -309,8 +308,9 @@ export class Sandbox {
309
308
  // honoured after the forks exist, so this is refused before any are made.
310
309
  throw new NotSupportedError("A timeout for forks (fork timeoutMs)", "Fork without it, then call setTimeout(ms) on each fork.");
311
310
  const copies = await guard("sandbox", () => this.#runtime.fork({ count: opts.count ?? 1, ...request(opts) }));
311
+ // Copies keep the source's environment on Runtime's side.
312
312
  const Kind = this.constructor;
313
- return copies.map((copy) => new Kind(copy, this.#client, { ...this.#envs }));
313
+ return copies.map((copy) => new Kind(copy, this.#client));
314
314
  }
315
315
  /** Keeps the sandbox's whole machine as a Runtime snapshot; start from it
316
316
  * with Sandbox.create(snapshotId). */
package/dist/errors.d.ts CHANGED
@@ -1,3 +1,11 @@
1
+ /** Every failure the SDK raises. `code` is stable and machine-readable,
2
+ * `hint` says what to do next, and `requestId` is what to quote in a report
3
+ * (runtime.feedback.submit, `runtime feedback`, or support). */
4
+ /** A product switched off on this deployment, or paused on purpose: the API
5
+ * answers these 503s in fixed words (`serverFault` "off" in
6
+ * packages/cloud/src/api/respond.ts) and retrying cannot change them.
7
+ * host_unavailable and busy pass, and are retried. */
8
+ export declare const DELIBERATE: ReadonlySet<string>;
1
9
  /** Refusals of a create that clear when a sandbox stops or pauses, or a host
2
10
  * frees room: the trial's slots, an email domain's trial slots, the account's
3
11
  * quota and the region's capacity. `sandboxes.create` waits them out, retrying
package/dist/errors.js CHANGED
@@ -1,8 +1,21 @@
1
1
  /** Every failure the SDK raises. `code` is stable and machine-readable,
2
2
  * `hint` says what to do next, and `requestId` is what to quote in a report
3
3
  * (runtime.feedback.submit, `runtime feedback`, or support). */
4
- /** Switched off on purpose: retrying cannot change them. */
5
- const DELIBERATE = new Set(["fork_unavailable", "previews_unavailable", "unavailable"]);
4
+ /** A product switched off on this deployment, or paused on purpose: the API
5
+ * answers these 503s in fixed words (`serverFault` "off" in
6
+ * packages/cloud/src/api/respond.ts) and retrying cannot change them.
7
+ * host_unavailable and busy pass, and are retried. */
8
+ export const DELIBERATE = new Set([
9
+ "unavailable",
10
+ "unsupported",
11
+ "fork_unavailable",
12
+ "previews_unavailable",
13
+ "network_unavailable",
14
+ "network_rules_unavailable",
15
+ "secrets_unavailable",
16
+ "identity_unavailable",
17
+ "env_unavailable",
18
+ ]);
6
19
  /** Refusals that pass on their own: a host frees room, a trial slot frees. */
7
20
  const PASSING = new Set(["no_capacity", "trial_busy"]);
8
21
  /** Refusals of a create that clear when a sandbox stops or pauses, or a host
@@ -0,0 +1,301 @@
1
+ import type { Runtime } from "../client.js";
2
+ import type { Sandbox } from "../sandbox.js";
3
+ import { CompatibilityError, type ClientOptions } from "../compat/core.js";
4
+ export { CompatibilityError };
5
+ export type VmState = "starting" | "running" | "pausing" | "paused" | "stopped";
6
+ export interface FirewallRule {
7
+ action: "allow";
8
+ source: Record<string, never>;
9
+ destination: {
10
+ public: true;
11
+ };
12
+ }
13
+ export interface CreateVmOptions {
14
+ snapshotId?: string | null;
15
+ slug?: string | null;
16
+ displayName?: string | null;
17
+ idleTimeoutSeconds?: number | null;
18
+ metadata?: Record<string, string>;
19
+ firewall: {
20
+ rules: FirewallRule[];
21
+ };
22
+ }
23
+ export interface ExecOptions {
24
+ command: string;
25
+ linuxUser?: string;
26
+ timeoutMs?: number;
27
+ env?: Record<string, string>;
28
+ stdin?: string;
29
+ }
30
+ export declare class Freestyle {
31
+ readonly vms: VmsNamespace;
32
+ constructor(options?: ClientOptions);
33
+ }
34
+ export declare class VmsNamespace {
35
+ private readonly runtime;
36
+ readonly snapshots: {
37
+ get: (id: string) => Promise<{
38
+ id: string;
39
+ sourceVmId: string;
40
+ slug: string | null;
41
+ public: boolean;
42
+ createdAt: string;
43
+ updatedAt: string;
44
+ ttlSeconds: number;
45
+ }>;
46
+ delete: (id: string) => Promise<void>;
47
+ list: () => Promise<{
48
+ snapshots: {
49
+ id: string;
50
+ sourceVmId: string;
51
+ slug: string | null;
52
+ public: boolean;
53
+ createdAt: string;
54
+ updatedAt: string;
55
+ ttlSeconds: number;
56
+ }[];
57
+ }>;
58
+ };
59
+ constructor(runtime: Runtime);
60
+ private resolveSnapshot;
61
+ create(options: CreateVmOptions): Promise<{
62
+ vm: Vm;
63
+ vmId: string;
64
+ data: {
65
+ id: string;
66
+ state: "paused" | "stopped" | "stopping" | "starting" | "running" | "pausing" | "resuming";
67
+ slug: string | null;
68
+ displayName: string | null;
69
+ resources: {
70
+ cpu: number;
71
+ memory: number;
72
+ storage: number;
73
+ };
74
+ metadata: {
75
+ [k: string]: string;
76
+ };
77
+ idleTimeoutSeconds: number | undefined;
78
+ vpcs: never[];
79
+ networks: never[];
80
+ createdAt: string;
81
+ updatedAt: string;
82
+ };
83
+ firewallRules: {
84
+ id: string;
85
+ source: {
86
+ vmId: string;
87
+ };
88
+ action: "allow";
89
+ destination: {
90
+ public: true;
91
+ };
92
+ }[];
93
+ tlsRules: never[];
94
+ }>;
95
+ ref(id: string): Vm;
96
+ get(id: string): Promise<{
97
+ id: string;
98
+ state: "paused" | "stopped" | "stopping" | "starting" | "running" | "pausing" | "resuming";
99
+ slug: string | null;
100
+ displayName: string | null;
101
+ resources: {
102
+ cpu: number;
103
+ memory: number;
104
+ storage: number;
105
+ };
106
+ metadata: {
107
+ [k: string]: string;
108
+ };
109
+ idleTimeoutSeconds: number | undefined;
110
+ vpcs: never[];
111
+ networks: never[];
112
+ createdAt: string;
113
+ updatedAt: string;
114
+ }>;
115
+ delete(id: string): Promise<void>;
116
+ list(options?: {
117
+ state?: string;
118
+ slug?: string;
119
+ metadata?: string;
120
+ limit?: number;
121
+ offset?: number;
122
+ }): Promise<{
123
+ vms: {
124
+ id: string;
125
+ state: "paused" | "stopped" | "stopping" | "starting" | "running" | "pausing" | "resuming";
126
+ slug: string | null;
127
+ displayName: string | null;
128
+ resources: {
129
+ cpu: number;
130
+ memory: number;
131
+ storage: number;
132
+ };
133
+ metadata: {
134
+ [k: string]: string;
135
+ };
136
+ idleTimeoutSeconds: number | undefined;
137
+ vpcs: never[];
138
+ networks: never[];
139
+ createdAt: string;
140
+ updatedAt: string;
141
+ }[];
142
+ totalCount: number;
143
+ runningCount: number;
144
+ startingCount: number;
145
+ pausingCount: number;
146
+ pausedCount: number;
147
+ stoppedCount: number;
148
+ }>;
149
+ }
150
+ export interface ReadFileOptions {
151
+ offset?: number;
152
+ length?: number;
153
+ signal?: AbortSignal;
154
+ }
155
+ export interface WriteFileOptions {
156
+ mode?: number;
157
+ signal?: AbortSignal;
158
+ chunkSize?: number;
159
+ maxAttempts?: number;
160
+ onProgress?: (progress: {
161
+ completedBytes: number;
162
+ totalBytes: number;
163
+ }) => void;
164
+ }
165
+ export declare class VmFilesystem {
166
+ private readonly get;
167
+ private readonly files;
168
+ constructor(get: () => Promise<Sandbox>);
169
+ readFile(path: string, options?: ReadFileOptions): Promise<Uint8Array<ArrayBuffer>>;
170
+ readTextFile(path: string, options?: ReadFileOptions): Promise<string>;
171
+ readFileStream(path: string, options?: ReadFileOptions): Promise<ReadableStream<Uint8Array<ArrayBufferLike>>>;
172
+ writeFile(path: string, content: string | Uint8Array | Blob, options?: WriteFileOptions): Promise<void>;
173
+ writeTextFile(path: string, content: string, options?: WriteFileOptions): Promise<void>;
174
+ mkdir(path: string): Promise<void>;
175
+ remove(path: string): Promise<void>;
176
+ exists(path: string): Promise<boolean>;
177
+ readDir(path: string): Promise<{
178
+ name: string;
179
+ kind: "file" | "directory" | "symlink" | "other";
180
+ }[]>;
181
+ stat(path: string): Promise<{
182
+ size: number;
183
+ isFile: boolean;
184
+ isDirectory: boolean;
185
+ isSymlink: boolean;
186
+ permissions: string;
187
+ owner: string;
188
+ group: string;
189
+ modified: string;
190
+ }>;
191
+ }
192
+ export declare class Vm {
193
+ private readonly runtime;
194
+ readonly id: string;
195
+ readonly fs: VmFilesystem;
196
+ constructor(runtime: Runtime, id: string);
197
+ data(): Promise<{
198
+ id: string;
199
+ state: "paused" | "stopped" | "stopping" | "starting" | "running" | "pausing" | "resuming";
200
+ slug: string | null;
201
+ displayName: string | null;
202
+ resources: {
203
+ cpu: number;
204
+ memory: number;
205
+ storage: number;
206
+ };
207
+ metadata: {
208
+ [k: string]: string;
209
+ };
210
+ idleTimeoutSeconds: number | undefined;
211
+ vpcs: never[];
212
+ networks: never[];
213
+ createdAt: string;
214
+ updatedAt: string;
215
+ }>;
216
+ start(): Promise<{
217
+ id: string;
218
+ state: "paused" | "stopped" | "stopping" | "starting" | "running" | "pausing" | "resuming";
219
+ slug: string | null;
220
+ displayName: string | null;
221
+ resources: {
222
+ cpu: number;
223
+ memory: number;
224
+ storage: number;
225
+ };
226
+ metadata: {
227
+ [k: string]: string;
228
+ };
229
+ idleTimeoutSeconds: number | undefined;
230
+ vpcs: never[];
231
+ networks: never[];
232
+ createdAt: string;
233
+ updatedAt: string;
234
+ }>;
235
+ pause(): Promise<{
236
+ id: string;
237
+ state: "paused" | "stopped" | "stopping" | "starting" | "running" | "pausing" | "resuming";
238
+ slug: string | null;
239
+ displayName: string | null;
240
+ resources: {
241
+ cpu: number;
242
+ memory: number;
243
+ storage: number;
244
+ };
245
+ metadata: {
246
+ [k: string]: string;
247
+ };
248
+ idleTimeoutSeconds: number | undefined;
249
+ vpcs: never[];
250
+ networks: never[];
251
+ createdAt: string;
252
+ updatedAt: string;
253
+ }>;
254
+ delete(): Promise<void>;
255
+ update(options: {
256
+ slug?: string;
257
+ displayName?: string;
258
+ idleTimeoutSeconds?: number;
259
+ metadata?: Record<string, string>;
260
+ }): Promise<{
261
+ id: string;
262
+ state: "paused" | "stopped" | "stopping" | "starting" | "running" | "pausing" | "resuming";
263
+ slug: string | null;
264
+ displayName: string | null;
265
+ resources: {
266
+ cpu: number;
267
+ memory: number;
268
+ storage: number;
269
+ };
270
+ metadata: {
271
+ [k: string]: string;
272
+ };
273
+ idleTimeoutSeconds: number | undefined;
274
+ vpcs: never[];
275
+ networks: never[];
276
+ createdAt: string;
277
+ updatedAt: string;
278
+ }>;
279
+ exec(options: string | ExecOptions): Promise<{
280
+ stdout: string;
281
+ stderr: string;
282
+ statusCode: number | null;
283
+ }>;
284
+ snapshot(options?: {
285
+ slug?: string;
286
+ displayName?: string;
287
+ ttlSeconds?: number;
288
+ }): Promise<{
289
+ snapshotId: string;
290
+ sourceVmId: string;
291
+ snapshot: {
292
+ id: string;
293
+ sourceVmId: string;
294
+ slug: string | null;
295
+ public: boolean;
296
+ createdAt: string;
297
+ updatedAt: string;
298
+ ttlSeconds: number;
299
+ };
300
+ }>;
301
+ }