withruntime 1.1.2 → 1.4.58

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 (77) hide show
  1. package/README.md +5 -2
  2. package/dist/generated/agentSessions.d.ts +2 -2
  3. package/dist/generated/agentSessions.js +2 -2
  4. package/dist/generated/agents.d.ts +2 -2
  5. package/dist/generated/agents.js +1 -1
  6. package/dist/generated/apps.d.ts +8 -6
  7. package/dist/generated/apps.js +10 -6
  8. package/dist/generated/browsers.d.ts +8 -6
  9. package/dist/generated/browsers.js +10 -6
  10. package/dist/generated/builds.d.ts +8 -6
  11. package/dist/generated/builds.js +10 -6
  12. package/dist/generated/ci.d.ts +106 -6
  13. package/dist/generated/ci.js +14 -6
  14. package/dist/generated/containers.d.ts +8 -6
  15. package/dist/generated/containers.js +10 -6
  16. package/dist/generated/desktops.d.ts +8 -6
  17. package/dist/generated/desktops.js +10 -6
  18. package/dist/generated/dropins/e2b.d.ts +180 -0
  19. package/dist/generated/dropins/e2b.js +342 -0
  20. package/dist/generated/dropins/e2b_code_interpreter.d.ts +180 -0
  21. package/dist/generated/dropins/e2b_code_interpreter.js +342 -0
  22. package/dist/generated/dropins/modal.d.ts +195 -0
  23. package/dist/generated/dropins/modal.js +375 -0
  24. package/dist/generated/dropins/runtime.d.ts +74 -0
  25. package/dist/generated/dropins/runtime.js +180 -0
  26. package/dist/generated/dropins/vercel.d.ts +78 -0
  27. package/dist/generated/dropins/vercel.js +154 -0
  28. package/dist/generated/egressIps.d.ts +2 -2
  29. package/dist/generated/egressIps.js +2 -2
  30. package/dist/generated/functions.d.ts +8 -6
  31. package/dist/generated/functions.js +10 -6
  32. package/dist/generated/identities.d.ts +42 -4
  33. package/dist/generated/identities.js +60 -0
  34. package/dist/generated/images.d.ts +3 -0
  35. package/dist/generated/images.js +4 -0
  36. package/dist/generated/index.d.ts +1 -1
  37. package/dist/generated/jobs.d.ts +2 -2
  38. package/dist/generated/jobs.js +1 -1
  39. package/dist/generated/keys.d.ts +28 -0
  40. package/dist/generated/keys.js +4 -0
  41. package/dist/generated/notebooks.d.ts +8 -6
  42. package/dist/generated/notebooks.js +10 -6
  43. package/dist/generated/ports.d.ts +2 -0
  44. package/dist/generated/projects.d.ts +49 -7
  45. package/dist/generated/projects.js +72 -3
  46. package/dist/generated/roles.d.ts +43 -5
  47. package/dist/generated/roles.js +61 -0
  48. package/dist/generated/routes.js +1 -1
  49. package/dist/generated/runtime.d.ts +49 -3
  50. package/dist/generated/runtime.js +235 -26
  51. package/dist/generated/sandboxes.d.ts +33 -14
  52. package/dist/generated/sandboxes.js +10 -6
  53. package/dist/generated/sites.d.ts +8 -6
  54. package/dist/generated/sites.js +10 -6
  55. package/dist/generated/snapshots.d.ts +7 -2
  56. package/dist/generated/snapshots.js +6 -2
  57. package/dist/generated/usage.d.ts +9 -3
  58. package/dist/generated/volumes.d.ts +30 -11
  59. package/dist/generated/volumes.js +19 -6
  60. package/dist/generated/workspaces.d.ts +8 -6
  61. package/dist/generated/workspaces.js +10 -6
  62. package/dist/v2/cli.d.ts +29 -0
  63. package/dist/v2/cli.js +156 -7
  64. package/dist/v2/login.d.ts +4 -0
  65. package/dist/v2/login.js +1 -1
  66. package/dist/v2/mcp.d.ts +4 -2
  67. package/dist/v2/mcp.js +69 -12
  68. package/dist/v2/openapi.json +2656 -1375
  69. package/dist/v2/shims/base.d.ts +0 -3
  70. package/dist/v2/shims/base.js +2 -7
  71. package/dist/v2/shims/blaxel.js +2 -1
  72. package/dist/v2/shims/daytona.js +3 -2
  73. package/dist/v2/shims/morph.js +3 -1
  74. package/dist/v2/shims/vercel.js +2 -1
  75. package/package.json +3 -2
  76. package/dist/v2/shims/e2b.d.ts +0 -142
  77. package/dist/v2/shims/e2b.js +0 -238
@@ -0,0 +1,180 @@
1
+ import type { Runtime } from "../index.js";
2
+ import { Process } from "./runtime.js";
3
+ export declare class CommandResult {
4
+ readonly stdout: string;
5
+ readonly stderr: string;
6
+ readonly exitCode: number;
7
+ constructor(answer: object);
8
+ }
9
+ export declare class CommandExitError extends Error {
10
+ readonly stdout: string;
11
+ readonly stderr: string;
12
+ readonly exitCode: number;
13
+ constructor(answer: object);
14
+ }
15
+ export declare class Execution {
16
+ readonly text: string;
17
+ readonly logs: {
18
+ stdout: string[];
19
+ stderr: string[];
20
+ };
21
+ readonly error: {
22
+ name: string;
23
+ value: string;
24
+ traceback: string;
25
+ } | null;
26
+ constructor(answer: object);
27
+ }
28
+ export declare class CommandHandle {
29
+ #private;
30
+ constructor(p: Process);
31
+ get pid(): string;
32
+ get exitCode(): number | null;
33
+ wait(): Promise<CommandResult>;
34
+ kill(signal?: string): Promise<void>;
35
+ }
36
+ export declare class EntryInfo {
37
+ readonly name: string;
38
+ readonly type: string;
39
+ readonly path: string;
40
+ readonly size: number;
41
+ constructor(_k: Runtime, v: {
42
+ name?: string;
43
+ type?: string;
44
+ path?: string;
45
+ size?: number;
46
+ });
47
+ }
48
+ export declare class WriteInfo {
49
+ readonly path: string;
50
+ readonly size: number;
51
+ constructor(_k: Runtime, v: {
52
+ path?: string;
53
+ size?: number;
54
+ });
55
+ }
56
+ export declare class SandboxInfo {
57
+ readonly sandboxId: string;
58
+ readonly templateId: string;
59
+ readonly name: string;
60
+ readonly state: string;
61
+ readonly startedAt: string;
62
+ constructor(_k: Runtime, v: {
63
+ sandboxId?: string;
64
+ templateId?: string;
65
+ name?: string;
66
+ state?: string;
67
+ startedAt?: string;
68
+ });
69
+ }
70
+ export declare class E2B {
71
+ readonly Sandbox: E2BSandbox;
72
+ readonly Volume: E2BVolume;
73
+ readonly Template: E2BTemplate;
74
+ readonly Secret: E2BSecret;
75
+ constructor(..._: unknown[]);
76
+ }
77
+ export declare class E2BSandbox {
78
+ constructor(..._: unknown[]);
79
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
80
+ create(..._: unknown[]): never;
81
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
82
+ list(..._: unknown[]): never;
83
+ }
84
+ export declare class E2BVolume {
85
+ constructor(..._: unknown[]);
86
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
87
+ create(..._: unknown[]): never;
88
+ }
89
+ export declare class E2BTemplate {
90
+ constructor(..._: unknown[]);
91
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
92
+ exists(..._: unknown[]): never;
93
+ }
94
+ export declare class E2BSecret {
95
+ constructor(..._: unknown[]);
96
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
97
+ create(..._: unknown[]): never;
98
+ }
99
+ export declare class Sandbox {
100
+ #private;
101
+ readonly sandboxId: string;
102
+ constructor(k: Runtime, sandboxId: string);
103
+ private get id();
104
+ get commands(): SandboxCommands;
105
+ get files(): SandboxFiles;
106
+ static create(template?: string | {
107
+ timeoutMs?: number;
108
+ metadata?: Record<string, string>;
109
+ envs?: Record<string, string>;
110
+ [option: string]: unknown;
111
+ }, opts?: {
112
+ timeoutMs?: number;
113
+ metadata?: Record<string, string>;
114
+ envs?: Record<string, string>;
115
+ [option: string]: unknown;
116
+ }): Promise<Sandbox>;
117
+ static connect(sandboxId: string): Promise<Sandbox>;
118
+ static kill(sandboxId: string): Promise<boolean>;
119
+ static setTimeout(sandboxId: string, timeoutMs: number): Promise<void>;
120
+ static getInfo(sandboxId: string): Promise<SandboxInfo>;
121
+ /** @deprecated Not served on Runtime: pages of sandboxes are the core's sandboxes.list (withruntime). */
122
+ static list(..._: unknown[]): never;
123
+ kill(): Promise<boolean>;
124
+ setTimeout(timeoutMs: number): Promise<void>;
125
+ getInfo(): Promise<SandboxInfo>;
126
+ pause(): Promise<boolean>;
127
+ /** @deprecated Not served on Runtime: a port opens at its preview's URL, with its token when private: previews.create (withruntime). */
128
+ getHost(..._: unknown[]): never;
129
+ runCode(code: string, opts?: {
130
+ language?: string;
131
+ timeoutMs?: number;
132
+ [option: string]: unknown;
133
+ }): Promise<Execution>;
134
+ }
135
+ export declare class SandboxCommands {
136
+ #private;
137
+ private readonly id;
138
+ constructor(k: Runtime, id: string);
139
+ run(cmd: string, opts: {
140
+ background?: boolean;
141
+ cwd?: string;
142
+ envs?: Record<string, string>;
143
+ user?: string;
144
+ timeoutMs?: number;
145
+ stdin?: boolean;
146
+ onStdout?: (data: string) => void;
147
+ onStderr?: (data: string) => void;
148
+ [option: string]: unknown;
149
+ } & {
150
+ background: true;
151
+ }): Promise<CommandHandle>;
152
+ run(cmd: string, opts?: {
153
+ background?: boolean;
154
+ cwd?: string;
155
+ envs?: Record<string, string>;
156
+ user?: string;
157
+ timeoutMs?: number;
158
+ stdin?: boolean;
159
+ onStdout?: (data: string) => void;
160
+ onStderr?: (data: string) => void;
161
+ [option: string]: unknown;
162
+ }): Promise<CommandResult>;
163
+ /** @deprecated Not served on Runtime: a command is ended by kill() on the handle run({ background: true }) answers. */
164
+ kill(..._: unknown[]): never;
165
+ /** @deprecated Not served on Runtime: a command's input is the core's sandboxes.writeProcess (withruntime). */
166
+ sendStdin(..._: unknown[]): never;
167
+ }
168
+ export declare class SandboxFiles {
169
+ #private;
170
+ private readonly id;
171
+ constructor(k: Runtime, id: string);
172
+ write(path: string, data: string | Uint8Array): Promise<WriteInfo>;
173
+ read(path: string): Promise<string>;
174
+ list(path: string): Promise<EntryInfo[]>;
175
+ getInfo(path: string): Promise<EntryInfo>;
176
+ makeDir(path: string): Promise<unknown>;
177
+ remove(path: string): Promise<void>;
178
+ rename(oldPath: string, newPath: string): Promise<EntryInfo>;
179
+ }
180
+ export default Sandbox;
@@ -0,0 +1,342 @@
1
+ // Generated by spec-gen from engines/front/crates/spec. Do not edit:
2
+ // change the spec and run `cargo run -p runtime-front-spec-gen -- write`.
3
+ /* withruntime/e2b: E2B's Sandbox on Runtime. Change the import from "e2b" to "withruntime/e2b" ("@e2b/code-interpreter" to "withruntime/e2b/code-interpreter"); RUNTIME_API_KEY replaces E2B_API_KEY, which is never read or sent. A sandbox is deleted 300 s after create unless timeoutMs or setTimeout says otherwise, as on E2B. */
4
+ import { Process, Refused, client, refuseOthers } from "./runtime.js";
5
+ export class CommandResult {
6
+ stdout;
7
+ stderr;
8
+ exitCode;
9
+ constructor(answer) {
10
+ const a = answer;
11
+ this.stdout = (a["stdout"] ?? "");
12
+ this.stderr = (a["stderr"] ?? "");
13
+ this.exitCode = Number(a["exitCode"] ?? -1);
14
+ }
15
+ }
16
+ export class CommandExitError extends Error {
17
+ stdout;
18
+ stderr;
19
+ exitCode;
20
+ constructor(answer) {
21
+ const a = answer;
22
+ super(`The command exited with code ${String(a["exitCode"])}: ${a["stderr"] ?? ""}`);
23
+ this.name = "CommandExitError";
24
+ this.stdout = (a["stdout"] ?? "");
25
+ this.stderr = (a["stderr"] ?? "");
26
+ this.exitCode = Number(a["exitCode"] ?? -1);
27
+ }
28
+ }
29
+ export class Execution {
30
+ text;
31
+ logs;
32
+ error;
33
+ constructor(answer) {
34
+ const a = answer;
35
+ this.text = ((a["results"] ?? []).find((x) => x["main"])?.["text"] ?? "");
36
+ this.logs = ((o) => ({ stdout: (o["stdout"] ?? "").split(/(?<=\n)/).filter(Boolean), stderr: (o["stderr"] ?? "").split(/(?<=\n)/).filter(Boolean) }))(a);
37
+ this.error = (a["error"] == null ? null : ((o) => ({ name: (o["name"] ?? ""), value: (o["value"] ?? ""), traceback: (o["traceback"] ?? "") }))(a["error"]));
38
+ }
39
+ }
40
+ export class CommandHandle {
41
+ #p;
42
+ constructor(p) {
43
+ this.#p = p;
44
+ }
45
+ get pid() {
46
+ return this.#p.id ?? "";
47
+ }
48
+ get exitCode() {
49
+ return this.#p.exitCode;
50
+ }
51
+ async wait() {
52
+ return this.#p.ran().then((r) => { if (r.exitCode !== 0)
53
+ throw new CommandExitError(r); return new CommandResult(r); });
54
+ }
55
+ async kill(signal) {
56
+ return this.#p.signal(signal);
57
+ }
58
+ }
59
+ export class EntryInfo {
60
+ name;
61
+ type;
62
+ path;
63
+ size;
64
+ constructor(_k, v) {
65
+ this.name = v.name ?? "";
66
+ this.type = v.type ?? "";
67
+ this.path = v.path ?? "";
68
+ this.size = v.size ?? 0;
69
+ }
70
+ }
71
+ export class WriteInfo {
72
+ path;
73
+ size;
74
+ constructor(_k, v) {
75
+ this.path = v.path ?? "";
76
+ this.size = v.size ?? 0;
77
+ }
78
+ }
79
+ export class SandboxInfo {
80
+ sandboxId;
81
+ templateId;
82
+ name;
83
+ state;
84
+ startedAt;
85
+ constructor(_k, v) {
86
+ this.sandboxId = v.sandboxId ?? "";
87
+ this.templateId = v.templateId ?? "";
88
+ this.name = v.name ?? "";
89
+ this.state = v.state ?? "";
90
+ this.startedAt = v.startedAt ?? "";
91
+ }
92
+ }
93
+ export class E2B {
94
+ Sandbox;
95
+ Volume;
96
+ Template;
97
+ Secret;
98
+ constructor(..._) {
99
+ this.Sandbox = new E2BSandbox();
100
+ this.Volume = new E2BVolume();
101
+ this.Template = new E2BTemplate();
102
+ this.Secret = new E2BSecret();
103
+ }
104
+ }
105
+ export class E2BSandbox {
106
+ constructor(..._) { }
107
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
108
+ create(..._) {
109
+ throw new Refused("e2b", "E2B.Sandbox.create", "an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox");
110
+ }
111
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
112
+ list(..._) {
113
+ throw new Refused("e2b", "E2B.Sandbox.list", "an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox");
114
+ }
115
+ }
116
+ export class E2BVolume {
117
+ constructor(..._) { }
118
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
119
+ create(..._) {
120
+ throw new Refused("e2b", "E2B.Volume.create", "an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox");
121
+ }
122
+ }
123
+ export class E2BTemplate {
124
+ constructor(..._) { }
125
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
126
+ exists(..._) {
127
+ throw new Refused("e2b", "E2B.Template.exists", "an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox");
128
+ }
129
+ }
130
+ export class E2BSecret {
131
+ constructor(..._) { }
132
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
133
+ create(..._) {
134
+ throw new Refused("e2b", "E2B.Secret.create", "an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox");
135
+ }
136
+ }
137
+ export class Sandbox {
138
+ sandboxId;
139
+ #k;
140
+ constructor(k, sandboxId) {
141
+ this.sandboxId = sandboxId;
142
+ this.#k = k;
143
+ }
144
+ get id() {
145
+ return this.sandboxId;
146
+ }
147
+ get commands() {
148
+ return new SandboxCommands(this.#k, this.id);
149
+ }
150
+ get files() {
151
+ return new SandboxFiles(this.#k, this.id);
152
+ }
153
+ static async create(template, opts = {}) {
154
+ const k = client();
155
+ if (typeof template === "object") {
156
+ opts = template;
157
+ template = undefined;
158
+ }
159
+ refuseOthers("e2b", "Sandbox.create", opts, ["envs", "metadata", "requestTimeoutMs", "timeoutMs"]);
160
+ const answer = await k.sandboxes.create({
161
+ ...(template !== undefined ? { from: template } : {}),
162
+ deleteAfterSeconds: Math.ceil((opts.timeoutMs ?? 300000) / 1000),
163
+ ...(opts.metadata !== undefined ? { labels: opts.metadata } : {}),
164
+ ...(opts.envs !== undefined ? { env: opts.envs } : {}),
165
+ });
166
+ for (const each of ["mkdir -p /home/user && chown runtime:runtime /home/user"])
167
+ await k.sandboxes.exec(answer.id, {
168
+ cmd: each,
169
+ user: "root",
170
+ });
171
+ return new Sandbox(k, answer.id);
172
+ }
173
+ static async connect(sandboxId) {
174
+ const k = client();
175
+ const answer = await k.sandboxes.get(sandboxId, {});
176
+ return new Sandbox(k, answer.id);
177
+ }
178
+ static async kill(sandboxId) {
179
+ const k = client();
180
+ await k.sandboxes.delete(sandboxId);
181
+ return true;
182
+ }
183
+ static async setTimeout(sandboxId, timeoutMs) {
184
+ const k = client();
185
+ await k.sandboxes.update(sandboxId, {
186
+ deleteAfterSeconds: Math.ceil(timeoutMs / 1000),
187
+ });
188
+ }
189
+ static async getInfo(sandboxId) {
190
+ const k = client();
191
+ const answer = await k.sandboxes.get(sandboxId, {});
192
+ return new SandboxInfo(k, {
193
+ ...(answer.id !== undefined ? { sandboxId: answer.id } : {}),
194
+ ...(answer.image !== undefined ? { templateId: answer.image } : {}),
195
+ ...(answer.name !== undefined ? { name: answer.name } : {}),
196
+ ...(answer.state !== undefined ? { state: answer.state } : {}),
197
+ ...(answer.createdAt !== undefined ? { startedAt: answer.createdAt } : {}),
198
+ });
199
+ }
200
+ /** @deprecated Not served on Runtime: pages of sandboxes are the core's sandboxes.list (withruntime). */
201
+ static list(..._) {
202
+ throw new Refused("e2b", "Sandbox.list", "pages of sandboxes are the core's sandboxes.list (withruntime)");
203
+ }
204
+ async kill() {
205
+ await this.#k.sandboxes.delete(this.id);
206
+ return true;
207
+ }
208
+ async setTimeout(timeoutMs) {
209
+ await this.#k.sandboxes.update(this.id, {
210
+ deleteAfterSeconds: Math.ceil(timeoutMs / 1000),
211
+ });
212
+ }
213
+ async getInfo() {
214
+ const answer = await this.#k.sandboxes.get(this.id, {});
215
+ return new SandboxInfo(this.#k, {
216
+ ...(answer.id !== undefined ? { sandboxId: answer.id } : {}),
217
+ ...(answer.image !== undefined ? { templateId: answer.image } : {}),
218
+ ...(answer.name !== undefined ? { name: answer.name } : {}),
219
+ ...(answer.state !== undefined ? { state: answer.state } : {}),
220
+ ...(answer.createdAt !== undefined ? { startedAt: answer.createdAt } : {}),
221
+ });
222
+ }
223
+ async pause() {
224
+ await this.#k.sandboxes.pause(this.id);
225
+ return true;
226
+ }
227
+ /** @deprecated Not served on Runtime: a port opens at its preview's URL, with its token when private: previews.create (withruntime). */
228
+ getHost(..._) {
229
+ throw new Refused("e2b", "Sandbox.getHost", "a port opens at its preview's URL, with its token when private: previews.create (withruntime)");
230
+ }
231
+ async runCode(code, opts = {}) {
232
+ refuseOthers("e2b", "Sandbox.runCode", opts, ["language", "requestTimeoutMs", "timeoutMs"]);
233
+ const answer = await this.#k.sandboxes.runCode(this.id, {
234
+ code: code,
235
+ ...(opts.language !== undefined ? { language: opts.language } : {}),
236
+ ...(opts.timeoutMs !== undefined ? { timeoutSeconds: Math.ceil(opts.timeoutMs / 1000) } : {}),
237
+ });
238
+ return new Execution(answer);
239
+ }
240
+ }
241
+ export class SandboxCommands {
242
+ id;
243
+ #k;
244
+ constructor(k, id) {
245
+ this.id = id;
246
+ this.#k = k;
247
+ }
248
+ async run(cmd, opts = {}) {
249
+ refuseOthers("e2b", "Sandbox.commands.run", opts, ["background", "cwd", "envs", "onStderr", "onStdout", "requestTimeoutMs", "stdin", "timeoutMs", "user"]);
250
+ const answer = await this.#k.sandboxes.exec(this.id, {
251
+ cmd: cmd,
252
+ cwd: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(opts.cwd),
253
+ env: { ...{ "HOME": "/home/user" }, ...(opts.envs ?? {}) },
254
+ ...(opts.user !== undefined ? { user: opts.user } : {}),
255
+ timeoutSeconds: Math.ceil((opts.timeoutMs ?? 60000) / 1000),
256
+ ...(opts.stdin !== undefined ? { stdinOpen: opts.stdin } : {}),
257
+ wait: false,
258
+ });
259
+ const p = new Process(this.#k, this.id, answer.id);
260
+ const ran = p.ran({ stdout: opts.onStdout, stderr: opts.onStderr });
261
+ if (opts.background === true)
262
+ return new CommandHandle(p);
263
+ return await ran.then((r) => { if (r.exitCode !== 0)
264
+ throw new CommandExitError(r); return new CommandResult(r); });
265
+ }
266
+ /** @deprecated Not served on Runtime: a command is ended by kill() on the handle run({ background: true }) answers. */
267
+ kill(..._) {
268
+ throw new Refused("e2b", "Sandbox.commands.kill", "a command is ended by kill() on the handle run({ background: true }) answers");
269
+ }
270
+ /** @deprecated Not served on Runtime: a command's input is the core's sandboxes.writeProcess (withruntime). */
271
+ sendStdin(..._) {
272
+ throw new Refused("e2b", "Sandbox.commands.sendStdin", "a command's input is the core's sandboxes.writeProcess (withruntime)");
273
+ }
274
+ }
275
+ export class SandboxFiles {
276
+ id;
277
+ #k;
278
+ constructor(k, id) {
279
+ this.id = id;
280
+ this.#k = k;
281
+ }
282
+ async write(path, data) {
283
+ const answer = await this.#k.sandboxes.write(this.id, data, {
284
+ path: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(path),
285
+ });
286
+ return new WriteInfo(this.#k, {
287
+ ...(answer.path !== undefined ? { path: answer.path } : {}),
288
+ ...(answer.size !== undefined ? { size: answer.size } : {}),
289
+ });
290
+ }
291
+ async read(path) {
292
+ const answer = await this.#k.sandboxes.read(this.id, {
293
+ path: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(path),
294
+ });
295
+ return new TextDecoder().decode(answer);
296
+ }
297
+ async list(path) {
298
+ const answer = await this.#k.sandboxes.listFiles(this.id, {
299
+ path: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(path),
300
+ });
301
+ return answer.items.map((item) => new EntryInfo(this.#k, {
302
+ ...(item.name !== undefined ? { name: item.name } : {}),
303
+ ...(item.type !== undefined ? { type: item.type } : {}),
304
+ ...(item.path !== undefined ? { path: item.path } : {}),
305
+ ...(item.size !== undefined ? { size: item.size } : {}),
306
+ }));
307
+ }
308
+ async getInfo(path) {
309
+ const answer = await this.#k.sandboxes.stat(this.id, {
310
+ path: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(path),
311
+ });
312
+ return new EntryInfo(this.#k, {
313
+ ...(answer.name !== undefined ? { name: answer.name } : {}),
314
+ ...(answer.type !== undefined ? { type: answer.type } : {}),
315
+ ...(answer.path !== undefined ? { path: answer.path } : {}),
316
+ ...(answer.size !== undefined ? { size: answer.size } : {}),
317
+ });
318
+ }
319
+ async makeDir(path) {
320
+ const answer = await this.#k.sandboxes.mkdir(this.id, {
321
+ path: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(path),
322
+ parents: true,
323
+ });
324
+ return answer.created;
325
+ }
326
+ async remove(path) {
327
+ await this.#k.sandboxes.remove(this.id, {
328
+ path: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(path),
329
+ recursive: true,
330
+ });
331
+ }
332
+ async rename(oldPath, newPath) {
333
+ const answer = await this.#k.sandboxes.rename(this.id, {
334
+ from: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(oldPath),
335
+ to: ((p) => (p === undefined ? "/home/user" : p.startsWith("/") ? p : `/home/user/${p}`))(newPath),
336
+ });
337
+ return new EntryInfo(this.#k, {
338
+ ...(answer.to !== undefined ? { path: answer.to } : {}),
339
+ });
340
+ }
341
+ }
342
+ export default Sandbox;
@@ -0,0 +1,180 @@
1
+ import type { Runtime } from "../index.js";
2
+ import { Process } from "./runtime.js";
3
+ export declare class CommandResult {
4
+ readonly stdout: string;
5
+ readonly stderr: string;
6
+ readonly exitCode: number;
7
+ constructor(answer: object);
8
+ }
9
+ export declare class CommandExitError extends Error {
10
+ readonly stdout: string;
11
+ readonly stderr: string;
12
+ readonly exitCode: number;
13
+ constructor(answer: object);
14
+ }
15
+ export declare class Execution {
16
+ readonly text: string;
17
+ readonly logs: {
18
+ stdout: string[];
19
+ stderr: string[];
20
+ };
21
+ readonly error: {
22
+ name: string;
23
+ value: string;
24
+ traceback: string;
25
+ } | null;
26
+ constructor(answer: object);
27
+ }
28
+ export declare class CommandHandle {
29
+ #private;
30
+ constructor(p: Process);
31
+ get pid(): string;
32
+ get exitCode(): number | null;
33
+ wait(): Promise<CommandResult>;
34
+ kill(signal?: string): Promise<void>;
35
+ }
36
+ export declare class EntryInfo {
37
+ readonly name: string;
38
+ readonly type: string;
39
+ readonly path: string;
40
+ readonly size: number;
41
+ constructor(_k: Runtime, v: {
42
+ name?: string;
43
+ type?: string;
44
+ path?: string;
45
+ size?: number;
46
+ });
47
+ }
48
+ export declare class WriteInfo {
49
+ readonly path: string;
50
+ readonly size: number;
51
+ constructor(_k: Runtime, v: {
52
+ path?: string;
53
+ size?: number;
54
+ });
55
+ }
56
+ export declare class SandboxInfo {
57
+ readonly sandboxId: string;
58
+ readonly templateId: string;
59
+ readonly name: string;
60
+ readonly state: string;
61
+ readonly startedAt: string;
62
+ constructor(_k: Runtime, v: {
63
+ sandboxId?: string;
64
+ templateId?: string;
65
+ name?: string;
66
+ state?: string;
67
+ startedAt?: string;
68
+ });
69
+ }
70
+ export declare class E2B {
71
+ readonly Sandbox: E2BSandbox;
72
+ readonly Volume: E2BVolume;
73
+ readonly Template: E2BTemplate;
74
+ readonly Secret: E2BSecret;
75
+ constructor(..._: unknown[]);
76
+ }
77
+ export declare class E2BSandbox {
78
+ constructor(..._: unknown[]);
79
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
80
+ create(..._: unknown[]): never;
81
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
82
+ list(..._: unknown[]): never;
83
+ }
84
+ export declare class E2BVolume {
85
+ constructor(..._: unknown[]);
86
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
87
+ create(..._: unknown[]): never;
88
+ }
89
+ export declare class E2BTemplate {
90
+ constructor(..._: unknown[]);
91
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
92
+ exists(..._: unknown[]): never;
93
+ }
94
+ export declare class E2BSecret {
95
+ constructor(..._: unknown[]);
96
+ /** @deprecated Not served on Runtime: an E2B client carries E2B's API key; Runtime reads RUNTIME_API_KEY: use Sandbox. */
97
+ create(..._: unknown[]): never;
98
+ }
99
+ export declare class Sandbox {
100
+ #private;
101
+ readonly sandboxId: string;
102
+ constructor(k: Runtime, sandboxId: string);
103
+ private get id();
104
+ get commands(): SandboxCommands;
105
+ get files(): SandboxFiles;
106
+ static create(template?: string | {
107
+ timeoutMs?: number;
108
+ metadata?: Record<string, string>;
109
+ envs?: Record<string, string>;
110
+ [option: string]: unknown;
111
+ }, opts?: {
112
+ timeoutMs?: number;
113
+ metadata?: Record<string, string>;
114
+ envs?: Record<string, string>;
115
+ [option: string]: unknown;
116
+ }): Promise<Sandbox>;
117
+ static connect(sandboxId: string): Promise<Sandbox>;
118
+ static kill(sandboxId: string): Promise<boolean>;
119
+ static setTimeout(sandboxId: string, timeoutMs: number): Promise<void>;
120
+ static getInfo(sandboxId: string): Promise<SandboxInfo>;
121
+ /** @deprecated Not served on Runtime: pages of sandboxes are the core's sandboxes.list (withruntime). */
122
+ static list(..._: unknown[]): never;
123
+ kill(): Promise<boolean>;
124
+ setTimeout(timeoutMs: number): Promise<void>;
125
+ getInfo(): Promise<SandboxInfo>;
126
+ pause(): Promise<boolean>;
127
+ /** @deprecated Not served on Runtime: a port opens at its preview's URL, with its token when private: previews.create (withruntime). */
128
+ getHost(..._: unknown[]): never;
129
+ runCode(code: string, opts?: {
130
+ language?: string;
131
+ timeoutMs?: number;
132
+ [option: string]: unknown;
133
+ }): Promise<Execution>;
134
+ }
135
+ export declare class SandboxCommands {
136
+ #private;
137
+ private readonly id;
138
+ constructor(k: Runtime, id: string);
139
+ run(cmd: string, opts: {
140
+ background?: boolean;
141
+ cwd?: string;
142
+ envs?: Record<string, string>;
143
+ user?: string;
144
+ timeoutMs?: number;
145
+ stdin?: boolean;
146
+ onStdout?: (data: string) => void;
147
+ onStderr?: (data: string) => void;
148
+ [option: string]: unknown;
149
+ } & {
150
+ background: true;
151
+ }): Promise<CommandHandle>;
152
+ run(cmd: string, opts?: {
153
+ background?: boolean;
154
+ cwd?: string;
155
+ envs?: Record<string, string>;
156
+ user?: string;
157
+ timeoutMs?: number;
158
+ stdin?: boolean;
159
+ onStdout?: (data: string) => void;
160
+ onStderr?: (data: string) => void;
161
+ [option: string]: unknown;
162
+ }): Promise<CommandResult>;
163
+ /** @deprecated Not served on Runtime: a command is ended by kill() on the handle run({ background: true }) answers. */
164
+ kill(..._: unknown[]): never;
165
+ /** @deprecated Not served on Runtime: a command's input is the core's sandboxes.writeProcess (withruntime). */
166
+ sendStdin(..._: unknown[]): never;
167
+ }
168
+ export declare class SandboxFiles {
169
+ #private;
170
+ private readonly id;
171
+ constructor(k: Runtime, id: string);
172
+ write(path: string, data: string | Uint8Array): Promise<WriteInfo>;
173
+ read(path: string): Promise<string>;
174
+ list(path: string): Promise<EntryInfo[]>;
175
+ getInfo(path: string): Promise<EntryInfo>;
176
+ makeDir(path: string): Promise<unknown>;
177
+ remove(path: string): Promise<void>;
178
+ rename(oldPath: string, newPath: string): Promise<EntryInfo>;
179
+ }
180
+ export default Sandbox;