@tpmjs/tools-e2b 0.1.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.
@@ -0,0 +1,328 @@
1
+ import * as ai from 'ai';
2
+
3
+ /**
4
+ * E2B Cloud Sandbox Tools for TPMJS
5
+ * Create and manage cloud sandboxes for AI code execution.
6
+ *
7
+ * Authentication: Set E2B_API_KEY env var with your API key from https://e2b.dev/dashboard
8
+ *
9
+ * SDK Packages:
10
+ * JavaScript/TypeScript: @e2b/code-interpreter
11
+ * Python: e2b-code-interpreter
12
+ */
13
+ interface E2BSandbox {
14
+ sandboxId: string;
15
+ templateId: string;
16
+ status: string;
17
+ startedAt?: string;
18
+ clientId?: string;
19
+ metadata?: Record<string, string>;
20
+ }
21
+ interface E2BSandboxList {
22
+ sandboxes: E2BSandbox[];
23
+ count: number;
24
+ }
25
+ interface E2BExecResult {
26
+ stdout: string;
27
+ stderr: string;
28
+ results: unknown[];
29
+ error?: {
30
+ name: string;
31
+ message: string;
32
+ traceback?: string;
33
+ };
34
+ duration: number;
35
+ }
36
+ interface E2BFileInfo {
37
+ name: string;
38
+ path: string;
39
+ type: 'file' | 'directory';
40
+ size?: number;
41
+ }
42
+ interface E2BTemplate {
43
+ templateId: string;
44
+ buildId?: string;
45
+ cpuCount?: number;
46
+ memoryMB?: number;
47
+ status?: string;
48
+ public?: boolean;
49
+ }
50
+ interface E2BMetrics {
51
+ cpuPct: number;
52
+ memUsedMB: number;
53
+ networkIngressMB: number;
54
+ networkEgressMB: number;
55
+ }
56
+ interface CreateSandboxInput {
57
+ template?: string;
58
+ timeoutMs?: number;
59
+ metadata?: Record<string, string>;
60
+ envVars?: Record<string, string>;
61
+ }
62
+ interface SandboxIdInput {
63
+ sandboxId: string;
64
+ }
65
+ interface ListSandboxesInput {
66
+ templateId?: string;
67
+ }
68
+ interface SetTimeoutInput {
69
+ sandboxId: string;
70
+ timeoutMs: number;
71
+ }
72
+ interface RunCodeInput {
73
+ sandboxId: string;
74
+ code: string;
75
+ language?: string;
76
+ timeoutMs?: number;
77
+ }
78
+ interface RunCommandInput {
79
+ sandboxId: string;
80
+ command: string;
81
+ cwd?: string;
82
+ background?: boolean;
83
+ timeoutMs?: number;
84
+ }
85
+ interface WriteFileInput {
86
+ sandboxId: string;
87
+ path: string;
88
+ content: string;
89
+ }
90
+ interface ReadFileInput {
91
+ sandboxId: string;
92
+ path: string;
93
+ }
94
+ interface ListFilesInput {
95
+ sandboxId: string;
96
+ path: string;
97
+ }
98
+ interface UploadFileInput {
99
+ sandboxId: string;
100
+ path: string;
101
+ content?: string;
102
+ url?: string;
103
+ }
104
+ interface DownloadFileInput {
105
+ sandboxId: string;
106
+ path: string;
107
+ }
108
+ interface MakeDirectoryInput {
109
+ sandboxId: string;
110
+ path: string;
111
+ }
112
+ interface WatchDirectoryInput {
113
+ sandboxId: string;
114
+ path: string;
115
+ }
116
+ interface ResumeInput {
117
+ sandboxId: string;
118
+ timeoutMs?: number;
119
+ }
120
+ interface SetEnvVarsInput {
121
+ sandboxId: string;
122
+ envVars: Record<string, string>;
123
+ }
124
+ interface InstallPackagesInput {
125
+ sandboxId: string;
126
+ packages: string[];
127
+ }
128
+ /**
129
+ * Create a new E2B sandbox
130
+ */
131
+ declare const createSandbox: ai.Tool<CreateSandboxInput, E2BSandbox>;
132
+ /**
133
+ * Get sandbox details
134
+ */
135
+ declare const getSandbox: ai.Tool<SandboxIdInput, E2BSandbox>;
136
+ /**
137
+ * List all sandboxes
138
+ */
139
+ declare const listSandboxes: ai.Tool<ListSandboxesInput, E2BSandboxList>;
140
+ /**
141
+ * Kill a sandbox
142
+ */
143
+ declare const killSandbox: ai.Tool<SandboxIdInput, {
144
+ killed: boolean;
145
+ sandboxId: string;
146
+ }>;
147
+ /**
148
+ * Set sandbox timeout
149
+ */
150
+ declare const setTimeout: ai.Tool<SetTimeoutInput, {
151
+ success: boolean;
152
+ expiresAt: string;
153
+ }>;
154
+ /**
155
+ * Run code in sandbox
156
+ */
157
+ declare const runCode: ai.Tool<RunCodeInput, E2BExecResult>;
158
+ /**
159
+ * Run shell command
160
+ */
161
+ declare const runCommand: ai.Tool<RunCommandInput, {
162
+ stdout: string;
163
+ stderr: string;
164
+ exitCode: number;
165
+ processId?: string;
166
+ }>;
167
+ /**
168
+ * Write file to sandbox
169
+ */
170
+ declare const writeFile: ai.Tool<WriteFileInput, {
171
+ success: boolean;
172
+ path: string;
173
+ size: number;
174
+ }>;
175
+ /**
176
+ * Read file from sandbox
177
+ */
178
+ declare const readFile: ai.Tool<ReadFileInput, {
179
+ content: string;
180
+ path: string;
181
+ size: number;
182
+ }>;
183
+ /**
184
+ * List files in sandbox
185
+ */
186
+ declare const listFiles: ai.Tool<ListFilesInput, {
187
+ entries: E2BFileInfo[];
188
+ count: number;
189
+ }>;
190
+ /**
191
+ * Upload file to sandbox
192
+ */
193
+ declare const uploadFile: ai.Tool<UploadFileInput, {
194
+ success: boolean;
195
+ path: string;
196
+ size: number;
197
+ }>;
198
+ /**
199
+ * Download file from sandbox
200
+ */
201
+ declare const downloadFile: ai.Tool<DownloadFileInput, {
202
+ content: string;
203
+ filename: string;
204
+ size: number;
205
+ mimeType: string;
206
+ }>;
207
+ /**
208
+ * Create directory in sandbox
209
+ */
210
+ declare const makeDirectory: ai.Tool<MakeDirectoryInput, {
211
+ success: boolean;
212
+ path: string;
213
+ }>;
214
+ /**
215
+ * Watch directory for changes
216
+ */
217
+ declare const watchDirectory: ai.Tool<WatchDirectoryInput, {
218
+ entries: E2BFileInfo[];
219
+ watcherId: string;
220
+ }>;
221
+ /**
222
+ * Pause sandbox (using keepalive approach)
223
+ */
224
+ declare const pauseSandbox: ai.Tool<SandboxIdInput, {
225
+ success: boolean;
226
+ sandboxId: string;
227
+ status: string;
228
+ }>;
229
+ /**
230
+ * Resume (reconnect to) sandbox
231
+ */
232
+ declare const resumeSandbox: ai.Tool<ResumeInput, {
233
+ sandboxId: string;
234
+ status: string;
235
+ }>;
236
+ /**
237
+ * Set environment variables
238
+ */
239
+ declare const setEnvVars: ai.Tool<SetEnvVarsInput, {
240
+ success: boolean;
241
+ count: number;
242
+ }>;
243
+ /**
244
+ * Get sandbox metrics
245
+ */
246
+ declare const getMetrics: ai.Tool<SandboxIdInput, E2BMetrics>;
247
+ /**
248
+ * Install Python packages
249
+ */
250
+ declare const installPackages: ai.Tool<InstallPackagesInput, {
251
+ success: boolean;
252
+ installed: string[];
253
+ errors?: string[];
254
+ }>;
255
+ declare const _default: {
256
+ createSandbox: ai.Tool<CreateSandboxInput, E2BSandbox>;
257
+ getSandbox: ai.Tool<SandboxIdInput, E2BSandbox>;
258
+ listSandboxes: ai.Tool<ListSandboxesInput, E2BSandboxList>;
259
+ killSandbox: ai.Tool<SandboxIdInput, {
260
+ killed: boolean;
261
+ sandboxId: string;
262
+ }>;
263
+ setTimeout: ai.Tool<SetTimeoutInput, {
264
+ success: boolean;
265
+ expiresAt: string;
266
+ }>;
267
+ runCode: ai.Tool<RunCodeInput, E2BExecResult>;
268
+ runCommand: ai.Tool<RunCommandInput, {
269
+ stdout: string;
270
+ stderr: string;
271
+ exitCode: number;
272
+ processId?: string;
273
+ }>;
274
+ writeFile: ai.Tool<WriteFileInput, {
275
+ success: boolean;
276
+ path: string;
277
+ size: number;
278
+ }>;
279
+ readFile: ai.Tool<ReadFileInput, {
280
+ content: string;
281
+ path: string;
282
+ size: number;
283
+ }>;
284
+ listFiles: ai.Tool<ListFilesInput, {
285
+ entries: E2BFileInfo[];
286
+ count: number;
287
+ }>;
288
+ uploadFile: ai.Tool<UploadFileInput, {
289
+ success: boolean;
290
+ path: string;
291
+ size: number;
292
+ }>;
293
+ downloadFile: ai.Tool<DownloadFileInput, {
294
+ content: string;
295
+ filename: string;
296
+ size: number;
297
+ mimeType: string;
298
+ }>;
299
+ makeDirectory: ai.Tool<MakeDirectoryInput, {
300
+ success: boolean;
301
+ path: string;
302
+ }>;
303
+ watchDirectory: ai.Tool<WatchDirectoryInput, {
304
+ entries: E2BFileInfo[];
305
+ watcherId: string;
306
+ }>;
307
+ pauseSandbox: ai.Tool<SandboxIdInput, {
308
+ success: boolean;
309
+ sandboxId: string;
310
+ status: string;
311
+ }>;
312
+ resumeSandbox: ai.Tool<ResumeInput, {
313
+ sandboxId: string;
314
+ status: string;
315
+ }>;
316
+ setEnvVars: ai.Tool<SetEnvVarsInput, {
317
+ success: boolean;
318
+ count: number;
319
+ }>;
320
+ getMetrics: ai.Tool<SandboxIdInput, E2BMetrics>;
321
+ installPackages: ai.Tool<InstallPackagesInput, {
322
+ success: boolean;
323
+ installed: string[];
324
+ errors?: string[];
325
+ }>;
326
+ };
327
+
328
+ export { type E2BExecResult, type E2BFileInfo, type E2BMetrics, type E2BSandbox, type E2BSandboxList, type E2BTemplate, createSandbox, _default as default, downloadFile, getMetrics, getSandbox, installPackages, killSandbox, listFiles, listSandboxes, makeDirectory, pauseSandbox, readFile, resumeSandbox, runCode, runCommand, setEnvVars, setTimeout, uploadFile, watchDirectory, writeFile };
package/dist/index.js ADDED
@@ -0,0 +1,751 @@
1
+ // src/index.ts
2
+ import { Sandbox } from "@e2b/code-interpreter";
3
+ import { jsonSchema, tool } from "ai";
4
+ var sandboxCache = /* @__PURE__ */ new Map();
5
+ async function getOrConnectSandbox(sandboxId) {
6
+ if (!sandboxId) {
7
+ throw new Error("sandboxId is required");
8
+ }
9
+ const cached = sandboxCache.get(sandboxId);
10
+ if (cached) {
11
+ return cached;
12
+ }
13
+ try {
14
+ const sandbox = await Sandbox.connect(sandboxId);
15
+ sandboxCache.set(sandboxId, sandbox);
16
+ return sandbox;
17
+ } catch (error) {
18
+ const message = error instanceof Error ? error.message : "Unknown error";
19
+ throw new Error(`Failed to connect to sandbox ${sandboxId}: ${message}`);
20
+ }
21
+ }
22
+ function removeSandboxFromCache(sandboxId) {
23
+ sandboxCache.delete(sandboxId);
24
+ }
25
+ var createSandbox = tool({
26
+ description: 'Create a new E2B cloud sandbox from a template. Sandboxes are isolated Linux environments for AI code execution. Defaults to "base" template with 5 minute timeout if not specified. Requires E2B_API_KEY.',
27
+ inputSchema: jsonSchema({
28
+ type: "object",
29
+ properties: {
30
+ template: {
31
+ type: "string",
32
+ description: 'Template ID to use (default: "base" for Code Interpreter)'
33
+ },
34
+ timeoutMs: {
35
+ type: "number",
36
+ description: "Sandbox timeout in milliseconds (default: 300000 = 5 minutes)"
37
+ },
38
+ metadata: {
39
+ type: "object",
40
+ description: "Custom metadata key-value pairs to attach to sandbox",
41
+ additionalProperties: { type: "string" }
42
+ },
43
+ envVars: {
44
+ type: "object",
45
+ description: "Environment variables to set in the sandbox",
46
+ additionalProperties: { type: "string" }
47
+ }
48
+ },
49
+ required: [],
50
+ additionalProperties: false
51
+ }),
52
+ async execute(input) {
53
+ const templateId = input.template || "base";
54
+ const timeoutMs = input.timeoutMs || 3e5;
55
+ try {
56
+ const sandbox = await Sandbox.create(templateId, {
57
+ timeoutMs,
58
+ metadata: input.metadata,
59
+ envs: input.envVars
60
+ });
61
+ sandboxCache.set(sandbox.sandboxId, sandbox);
62
+ return {
63
+ sandboxId: sandbox.sandboxId,
64
+ templateId,
65
+ status: "running",
66
+ startedAt: (/* @__PURE__ */ new Date()).toISOString(),
67
+ clientId: sandbox.sandboxId,
68
+ metadata: input.metadata
69
+ };
70
+ } catch (error) {
71
+ const message = error instanceof Error ? error.message : "Unknown error";
72
+ throw new Error(`Failed to create sandbox with template "${templateId}": ${message}`);
73
+ }
74
+ }
75
+ });
76
+ var getSandbox = tool({
77
+ description: "Connect to and verify an existing E2B sandbox is running. Returns sandbox ID and connection status. Requires E2B_API_KEY.",
78
+ inputSchema: jsonSchema({
79
+ type: "object",
80
+ properties: {
81
+ sandboxId: {
82
+ type: "string",
83
+ description: "ID of the sandbox to retrieve"
84
+ }
85
+ },
86
+ required: ["sandboxId"],
87
+ additionalProperties: false
88
+ }),
89
+ async execute(input) {
90
+ try {
91
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
92
+ return {
93
+ sandboxId: sandbox.sandboxId,
94
+ templateId: sandbox.templateId || "base",
95
+ status: "running"
96
+ };
97
+ } catch (error) {
98
+ const message = error instanceof Error ? error.message : "Unknown error";
99
+ throw new Error(`Failed to get sandbox ${input.sandboxId}: ${message}`);
100
+ }
101
+ }
102
+ });
103
+ var listSandboxes = tool({
104
+ description: "List all running E2B sandboxes in your account with their status and metadata. Requires E2B_API_KEY.",
105
+ inputSchema: jsonSchema({
106
+ type: "object",
107
+ properties: {
108
+ templateId: {
109
+ type: "string",
110
+ description: "Filter sandboxes by template ID"
111
+ }
112
+ },
113
+ required: [],
114
+ additionalProperties: false
115
+ }),
116
+ async execute(_input) {
117
+ const sandboxes = await Sandbox.list();
118
+ return {
119
+ sandboxes: sandboxes.map((s) => ({
120
+ sandboxId: s.sandboxId,
121
+ templateId: s.templateId || "unknown",
122
+ status: "running",
123
+ startedAt: s.startedAt?.toISOString(),
124
+ clientId: s.clientId,
125
+ metadata: s.metadata
126
+ })),
127
+ count: sandboxes.length
128
+ };
129
+ }
130
+ });
131
+ var killSandbox = tool({
132
+ description: "Terminate a running E2B sandbox immediately. All data and processes are destroyed. Requires E2B_API_KEY.",
133
+ inputSchema: jsonSchema({
134
+ type: "object",
135
+ properties: {
136
+ sandboxId: {
137
+ type: "string",
138
+ description: "ID of the sandbox to terminate"
139
+ }
140
+ },
141
+ required: ["sandboxId"],
142
+ additionalProperties: false
143
+ }),
144
+ async execute(input) {
145
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
146
+ await sandbox.kill();
147
+ removeSandboxFromCache(input.sandboxId);
148
+ return { killed: true, sandboxId: input.sandboxId };
149
+ }
150
+ });
151
+ var setTimeout = tool({
152
+ description: "Set or extend the timeout for an E2B sandbox. The sandbox will be automatically killed when the timeout expires. Requires E2B_API_KEY.",
153
+ inputSchema: jsonSchema({
154
+ type: "object",
155
+ properties: {
156
+ sandboxId: {
157
+ type: "string",
158
+ description: "ID of the sandbox"
159
+ },
160
+ timeoutMs: {
161
+ type: "number",
162
+ description: "New timeout in milliseconds from now"
163
+ }
164
+ },
165
+ required: ["sandboxId", "timeoutMs"],
166
+ additionalProperties: false
167
+ }),
168
+ async execute(input) {
169
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
170
+ await sandbox.setTimeout(input.timeoutMs);
171
+ const expiresAt = new Date(Date.now() + input.timeoutMs).toISOString();
172
+ return { success: true, expiresAt };
173
+ }
174
+ });
175
+ var runCode = tool({
176
+ description: "Execute code in an E2B sandbox. Supports Python (default), JavaScript, TypeScript, R, Java, and Bash with streaming output and result capture. Requires E2B_API_KEY.",
177
+ inputSchema: jsonSchema({
178
+ type: "object",
179
+ properties: {
180
+ sandboxId: {
181
+ type: "string",
182
+ description: "ID of the sandbox to execute in"
183
+ },
184
+ code: {
185
+ type: "string",
186
+ description: "Code to execute"
187
+ },
188
+ language: {
189
+ type: "string",
190
+ description: "Language: python (default), javascript, typescript, r, java, bash"
191
+ },
192
+ timeoutMs: {
193
+ type: "number",
194
+ description: "Execution timeout in milliseconds (default: 60000)"
195
+ }
196
+ },
197
+ required: ["sandboxId", "code"],
198
+ additionalProperties: false
199
+ }),
200
+ async execute(input) {
201
+ const startTime = Date.now();
202
+ const language = input.language || "python";
203
+ const timeoutMs = input.timeoutMs || 6e4;
204
+ try {
205
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
206
+ const execution = await sandbox.runCode(input.code, {
207
+ language,
208
+ timeoutMs
209
+ });
210
+ const duration = Date.now() - startTime;
211
+ return {
212
+ stdout: execution.logs.stdout.join("\n"),
213
+ stderr: execution.logs.stderr.join("\n"),
214
+ results: execution.results.map((r) => r.toJSON()),
215
+ error: execution.error ? {
216
+ name: execution.error.name,
217
+ message: execution.error.value,
218
+ traceback: execution.error.traceback
219
+ } : void 0,
220
+ duration
221
+ };
222
+ } catch (error) {
223
+ const message = error instanceof Error ? error.message : "Unknown error";
224
+ throw new Error(`Failed to execute code in sandbox ${input.sandboxId}: ${message}`);
225
+ }
226
+ }
227
+ });
228
+ var runCommand = tool({
229
+ description: "Execute a shell command in an E2B sandbox with full shell access. Supports background processes and working directory. Requires E2B_API_KEY.",
230
+ inputSchema: jsonSchema({
231
+ type: "object",
232
+ properties: {
233
+ sandboxId: {
234
+ type: "string",
235
+ description: "ID of the sandbox"
236
+ },
237
+ command: {
238
+ type: "string",
239
+ description: "Shell command to execute"
240
+ },
241
+ cwd: {
242
+ type: "string",
243
+ description: "Working directory for the command"
244
+ },
245
+ background: {
246
+ type: "boolean",
247
+ description: "Run command in background (default: false)"
248
+ },
249
+ timeoutMs: {
250
+ type: "number",
251
+ description: "Command timeout in milliseconds (default: 60000)"
252
+ }
253
+ },
254
+ required: ["sandboxId", "command"],
255
+ additionalProperties: false
256
+ }),
257
+ async execute(input) {
258
+ const timeoutMs = input.timeoutMs || 6e4;
259
+ try {
260
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
261
+ if (input.background) {
262
+ const process = await sandbox.commands.run(input.command, {
263
+ cwd: input.cwd,
264
+ background: true,
265
+ timeoutMs
266
+ });
267
+ return {
268
+ stdout: "",
269
+ stderr: "",
270
+ exitCode: 0,
271
+ processId: String(process.pid)
272
+ };
273
+ }
274
+ const result = await sandbox.commands.run(input.command, {
275
+ cwd: input.cwd,
276
+ timeoutMs
277
+ });
278
+ return {
279
+ stdout: result.stdout,
280
+ stderr: result.stderr,
281
+ exitCode: result.exitCode
282
+ };
283
+ } catch (error) {
284
+ const message = error instanceof Error ? error.message : "Unknown error";
285
+ throw new Error(`Failed to run command in sandbox ${input.sandboxId}: ${message}`);
286
+ }
287
+ }
288
+ });
289
+ var writeFile = tool({
290
+ description: "Write content to a file in the E2B sandbox filesystem. Creates directories as needed. Requires E2B_API_KEY.",
291
+ inputSchema: jsonSchema({
292
+ type: "object",
293
+ properties: {
294
+ sandboxId: {
295
+ type: "string",
296
+ description: "ID of the sandbox"
297
+ },
298
+ path: {
299
+ type: "string",
300
+ description: "Absolute path in sandbox (e.g., /home/user/file.txt)"
301
+ },
302
+ content: {
303
+ type: "string",
304
+ description: "File content as string"
305
+ }
306
+ },
307
+ required: ["sandboxId", "path", "content"],
308
+ additionalProperties: false
309
+ }),
310
+ async execute(input) {
311
+ try {
312
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
313
+ await sandbox.files.write(input.path, input.content);
314
+ return {
315
+ success: true,
316
+ path: input.path,
317
+ size: input.content.length
318
+ };
319
+ } catch (error) {
320
+ const message = error instanceof Error ? error.message : "Unknown error";
321
+ throw new Error(`Failed to write file ${input.path} in sandbox ${input.sandboxId}: ${message}`);
322
+ }
323
+ }
324
+ });
325
+ var readFile = tool({
326
+ description: "Read content from a file in the E2B sandbox filesystem. Requires E2B_API_KEY.",
327
+ inputSchema: jsonSchema({
328
+ type: "object",
329
+ properties: {
330
+ sandboxId: {
331
+ type: "string",
332
+ description: "ID of the sandbox"
333
+ },
334
+ path: {
335
+ type: "string",
336
+ description: "Absolute path to file in sandbox"
337
+ }
338
+ },
339
+ required: ["sandboxId", "path"],
340
+ additionalProperties: false
341
+ }),
342
+ async execute(input) {
343
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
344
+ const content = await sandbox.files.read(input.path);
345
+ const textContent = typeof content === "string" ? content : new TextDecoder().decode(content);
346
+ return {
347
+ content: textContent,
348
+ path: input.path,
349
+ size: textContent.length
350
+ };
351
+ }
352
+ });
353
+ var listFiles = tool({
354
+ description: "List files and directories at a path in the E2B sandbox. Requires E2B_API_KEY.",
355
+ inputSchema: jsonSchema({
356
+ type: "object",
357
+ properties: {
358
+ sandboxId: {
359
+ type: "string",
360
+ description: "ID of the sandbox"
361
+ },
362
+ path: {
363
+ type: "string",
364
+ description: "Absolute path to list (e.g., /home/user)"
365
+ }
366
+ },
367
+ required: ["sandboxId", "path"],
368
+ additionalProperties: false
369
+ }),
370
+ async execute(input) {
371
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
372
+ const entries = await sandbox.files.list(input.path);
373
+ return {
374
+ entries: entries.map((e) => ({
375
+ name: e.name,
376
+ path: `${input.path}/${e.name}`,
377
+ type: e.type
378
+ })),
379
+ count: entries.length
380
+ };
381
+ }
382
+ });
383
+ var uploadFile = tool({
384
+ description: "Upload a file to the E2B sandbox from base64 content or a URL. Requires E2B_API_KEY.",
385
+ inputSchema: jsonSchema({
386
+ type: "object",
387
+ properties: {
388
+ sandboxId: {
389
+ type: "string",
390
+ description: "ID of the sandbox"
391
+ },
392
+ path: {
393
+ type: "string",
394
+ description: "Destination path in sandbox"
395
+ },
396
+ content: {
397
+ type: "string",
398
+ description: "Base64 encoded file content"
399
+ },
400
+ url: {
401
+ type: "string",
402
+ description: "URL to fetch file from (alternative to content)"
403
+ }
404
+ },
405
+ required: ["sandboxId", "path"],
406
+ additionalProperties: false
407
+ }),
408
+ async execute(input) {
409
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
410
+ let fileContent;
411
+ if (input.url) {
412
+ const response = await fetch(input.url);
413
+ fileContent = await response.arrayBuffer();
414
+ } else if (input.content) {
415
+ const binaryString = atob(input.content);
416
+ const bytes = new Uint8Array(binaryString.length);
417
+ for (let i = 0; i < binaryString.length; i++) {
418
+ bytes[i] = binaryString.charCodeAt(i);
419
+ }
420
+ fileContent = bytes.buffer;
421
+ } else {
422
+ throw new Error("Either content or url must be provided");
423
+ }
424
+ await sandbox.files.write(input.path, fileContent);
425
+ return {
426
+ success: true,
427
+ path: input.path,
428
+ size: fileContent.byteLength
429
+ };
430
+ }
431
+ });
432
+ var downloadFile = tool({
433
+ description: "Download a file from the E2B sandbox as base64 content. Requires E2B_API_KEY.",
434
+ inputSchema: jsonSchema({
435
+ type: "object",
436
+ properties: {
437
+ sandboxId: {
438
+ type: "string",
439
+ description: "ID of the sandbox"
440
+ },
441
+ path: {
442
+ type: "string",
443
+ description: "Path to file in sandbox"
444
+ }
445
+ },
446
+ required: ["sandboxId", "path"],
447
+ additionalProperties: false
448
+ }),
449
+ async execute(input) {
450
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
451
+ const content = await sandbox.files.read(input.path);
452
+ const filename = input.path.split("/").pop() || "file";
453
+ const ext = filename.split(".").pop()?.toLowerCase() || "";
454
+ let base64Content;
455
+ let contentLength;
456
+ if (typeof content === "string") {
457
+ base64Content = btoa(content);
458
+ contentLength = content.length;
459
+ } else {
460
+ const bytes = new Uint8Array(content);
461
+ contentLength = bytes.length;
462
+ let binary = "";
463
+ for (let i = 0; i < bytes.length; i++) {
464
+ binary += String.fromCharCode(bytes[i]);
465
+ }
466
+ base64Content = btoa(binary);
467
+ }
468
+ const mimeTypes = {
469
+ txt: "text/plain",
470
+ json: "application/json",
471
+ js: "text/javascript",
472
+ ts: "text/typescript",
473
+ py: "text/x-python",
474
+ html: "text/html",
475
+ css: "text/css",
476
+ png: "image/png",
477
+ jpg: "image/jpeg",
478
+ jpeg: "image/jpeg",
479
+ gif: "image/gif",
480
+ pdf: "application/pdf",
481
+ zip: "application/zip"
482
+ };
483
+ return {
484
+ content: base64Content,
485
+ filename,
486
+ size: contentLength,
487
+ mimeType: mimeTypes[ext] || "application/octet-stream"
488
+ };
489
+ }
490
+ });
491
+ var makeDirectory = tool({
492
+ description: "Create a directory in the E2B sandbox filesystem. Creates parent directories as needed. Requires E2B_API_KEY.",
493
+ inputSchema: jsonSchema({
494
+ type: "object",
495
+ properties: {
496
+ sandboxId: {
497
+ type: "string",
498
+ description: "ID of the sandbox"
499
+ },
500
+ path: {
501
+ type: "string",
502
+ description: "Absolute path of directory to create"
503
+ }
504
+ },
505
+ required: ["sandboxId", "path"],
506
+ additionalProperties: false
507
+ }),
508
+ async execute(input) {
509
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
510
+ await sandbox.files.makeDir(input.path);
511
+ return { success: true, path: input.path };
512
+ }
513
+ });
514
+ var watchDirectory = tool({
515
+ description: "Watch a directory in the E2B sandbox for file changes. Returns the initial state. Requires E2B_API_KEY.",
516
+ inputSchema: jsonSchema({
517
+ type: "object",
518
+ properties: {
519
+ sandboxId: {
520
+ type: "string",
521
+ description: "ID of the sandbox"
522
+ },
523
+ path: {
524
+ type: "string",
525
+ description: "Directory path to watch"
526
+ }
527
+ },
528
+ required: ["sandboxId", "path"],
529
+ additionalProperties: false
530
+ }),
531
+ async execute(input) {
532
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
533
+ const entries = await sandbox.files.list(input.path);
534
+ return {
535
+ entries: entries.map((e) => ({
536
+ name: e.name,
537
+ path: `${input.path}/${e.name}`,
538
+ type: e.type
539
+ })),
540
+ watcherId: `watch-${input.sandboxId}-${Date.now()}`
541
+ };
542
+ }
543
+ });
544
+ var pauseSandbox = tool({
545
+ description: "Disconnect from an E2B sandbox while keeping it running. The sandbox continues running and can be reconnected later using resumeSandbox. State is preserved in the sandbox. Requires E2B_API_KEY.",
546
+ inputSchema: jsonSchema({
547
+ type: "object",
548
+ properties: {
549
+ sandboxId: {
550
+ type: "string",
551
+ description: "ID of the sandbox to disconnect from"
552
+ }
553
+ },
554
+ required: ["sandboxId"],
555
+ additionalProperties: false
556
+ }),
557
+ async execute(input) {
558
+ if (!input.sandboxId) {
559
+ throw new Error("sandboxId is required");
560
+ }
561
+ try {
562
+ await getOrConnectSandbox(input.sandboxId);
563
+ } catch (error) {
564
+ const message = error instanceof Error ? error.message : "Unknown error";
565
+ throw new Error(`Cannot pause sandbox ${input.sandboxId}: ${message}`);
566
+ }
567
+ removeSandboxFromCache(input.sandboxId);
568
+ return {
569
+ success: true,
570
+ sandboxId: input.sandboxId,
571
+ status: "disconnected"
572
+ };
573
+ }
574
+ });
575
+ var resumeSandbox = tool({
576
+ description: "Reconnect to a running E2B sandbox that was previously disconnected using pauseSandbox. Optionally set a new timeout. Requires E2B_API_KEY.",
577
+ inputSchema: jsonSchema({
578
+ type: "object",
579
+ properties: {
580
+ sandboxId: {
581
+ type: "string",
582
+ description: "ID of the sandbox to reconnect to"
583
+ },
584
+ timeoutMs: {
585
+ type: "number",
586
+ description: "New timeout for the sandbox in milliseconds (optional)"
587
+ }
588
+ },
589
+ required: ["sandboxId"],
590
+ additionalProperties: false
591
+ }),
592
+ async execute(input) {
593
+ try {
594
+ const sandbox = await Sandbox.connect(input.sandboxId);
595
+ if (input.timeoutMs) {
596
+ await sandbox.setTimeout(input.timeoutMs);
597
+ }
598
+ sandboxCache.set(sandbox.sandboxId, sandbox);
599
+ return { sandboxId: sandbox.sandboxId, status: "running" };
600
+ } catch (error) {
601
+ const message = error instanceof Error ? error.message : "Unknown error";
602
+ throw new Error(`Failed to reconnect to sandbox ${input.sandboxId}: ${message}`);
603
+ }
604
+ }
605
+ });
606
+ var setEnvVars = tool({
607
+ description: "Set environment variables in an E2B sandbox. These persist for subsequent code executions in the same sandbox session. Special characters are safely escaped. Requires E2B_API_KEY.",
608
+ inputSchema: jsonSchema({
609
+ type: "object",
610
+ properties: {
611
+ sandboxId: {
612
+ type: "string",
613
+ description: "ID of the sandbox"
614
+ },
615
+ envVars: {
616
+ type: "object",
617
+ description: "Key-value pairs of environment variables to set",
618
+ additionalProperties: { type: "string" }
619
+ }
620
+ },
621
+ required: ["sandboxId", "envVars"],
622
+ additionalProperties: false
623
+ }),
624
+ async execute(input) {
625
+ try {
626
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
627
+ const escapeForShell = (str) => {
628
+ return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\$/g, "\\$").replace(/`/g, "\\`").replace(/!/g, "\\!");
629
+ };
630
+ for (const [key, value] of Object.entries(input.envVars)) {
631
+ await sandbox.commands.run(`export ${key}="${escapeForShell(value)}"`);
632
+ }
633
+ return { success: true, count: Object.keys(input.envVars).length };
634
+ } catch (error) {
635
+ const message = error instanceof Error ? error.message : "Unknown error";
636
+ throw new Error(`Failed to set environment variables in sandbox ${input.sandboxId}: ${message}`);
637
+ }
638
+ }
639
+ });
640
+ var getMetrics = tool({
641
+ description: "Get resource usage metrics for an E2B sandbox including CPU, memory, and network usage. Requires E2B_API_KEY.",
642
+ inputSchema: jsonSchema({
643
+ type: "object",
644
+ properties: {
645
+ sandboxId: {
646
+ type: "string",
647
+ description: "ID of the sandbox"
648
+ }
649
+ },
650
+ required: ["sandboxId"],
651
+ additionalProperties: false
652
+ }),
653
+ async execute(input) {
654
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
655
+ const cpuResult = await sandbox.commands.run(
656
+ "cat /proc/stat | grep 'cpu ' | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'"
657
+ );
658
+ const memResult = await sandbox.commands.run("free -m | grep Mem | awk '{print $3}'");
659
+ return {
660
+ cpuPct: parseFloat(cpuResult.stdout) || 0,
661
+ memUsedMB: parseInt(memResult.stdout) || 0,
662
+ networkIngressMB: 0,
663
+ networkEgressMB: 0
664
+ };
665
+ }
666
+ });
667
+ var installPackages = tool({
668
+ description: "Install Python packages in an E2B Code Interpreter sandbox using pip. Requires E2B_API_KEY.",
669
+ inputSchema: jsonSchema({
670
+ type: "object",
671
+ properties: {
672
+ sandboxId: {
673
+ type: "string",
674
+ description: "ID of the sandbox"
675
+ },
676
+ packages: {
677
+ type: "array",
678
+ items: { type: "string" },
679
+ description: "Array of package names to install (e.g., ['numpy', 'pandas==2.0.0'])"
680
+ }
681
+ },
682
+ required: ["sandboxId", "packages"],
683
+ additionalProperties: false
684
+ }),
685
+ async execute(input) {
686
+ const sandbox = await getOrConnectSandbox(input.sandboxId);
687
+ const installed = [];
688
+ const errors = [];
689
+ for (const pkg of input.packages) {
690
+ try {
691
+ const result = await sandbox.commands.run(`pip install ${pkg}`, { timeoutMs: 12e4 });
692
+ if (result.exitCode === 0) {
693
+ installed.push(pkg);
694
+ } else {
695
+ errors.push(`${pkg}: ${result.stderr}`);
696
+ }
697
+ } catch (error) {
698
+ errors.push(`${pkg}: ${error instanceof Error ? error.message : "Unknown error"}`);
699
+ }
700
+ }
701
+ return {
702
+ success: errors.length === 0,
703
+ installed,
704
+ errors: errors.length > 0 ? errors : void 0
705
+ };
706
+ }
707
+ });
708
+ var index_default = {
709
+ createSandbox,
710
+ getSandbox,
711
+ listSandboxes,
712
+ killSandbox,
713
+ setTimeout,
714
+ runCode,
715
+ runCommand,
716
+ writeFile,
717
+ readFile,
718
+ listFiles,
719
+ uploadFile,
720
+ downloadFile,
721
+ makeDirectory,
722
+ watchDirectory,
723
+ pauseSandbox,
724
+ resumeSandbox,
725
+ setEnvVars,
726
+ getMetrics,
727
+ installPackages
728
+ };
729
+ export {
730
+ createSandbox,
731
+ index_default as default,
732
+ downloadFile,
733
+ getMetrics,
734
+ getSandbox,
735
+ installPackages,
736
+ killSandbox,
737
+ listFiles,
738
+ listSandboxes,
739
+ makeDirectory,
740
+ pauseSandbox,
741
+ readFile,
742
+ resumeSandbox,
743
+ runCode,
744
+ runCommand,
745
+ setEnvVars,
746
+ setTimeout,
747
+ uploadFile,
748
+ watchDirectory,
749
+ writeFile
750
+ };
751
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * E2B Cloud Sandbox Tools for TPMJS\n * Create and manage cloud sandboxes for AI code execution.\n *\n * Authentication: Set E2B_API_KEY env var with your API key from https://e2b.dev/dashboard\n *\n * SDK Packages:\n * JavaScript/TypeScript: @e2b/code-interpreter\n * Python: e2b-code-interpreter\n */\n\nimport { Sandbox } from '@e2b/code-interpreter';\nimport { jsonSchema, tool } from 'ai';\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport interface E2BSandbox {\n sandboxId: string;\n templateId: string;\n status: string;\n startedAt?: string;\n clientId?: string;\n metadata?: Record<string, string>;\n}\n\nexport interface E2BSandboxList {\n sandboxes: E2BSandbox[];\n count: number;\n}\n\nexport interface E2BExecResult {\n stdout: string;\n stderr: string;\n results: unknown[];\n error?: { name: string; message: string; traceback?: string };\n duration: number;\n}\n\nexport interface E2BFileInfo {\n name: string;\n path: string;\n type: 'file' | 'directory';\n size?: number;\n}\n\nexport interface E2BTemplate {\n templateId: string;\n buildId?: string;\n cpuCount?: number;\n memoryMB?: number;\n status?: string;\n public?: boolean;\n}\n\nexport interface E2BMetrics {\n cpuPct: number;\n memUsedMB: number;\n networkIngressMB: number;\n networkEgressMB: number;\n}\n\n// Input types\ninterface CreateSandboxInput {\n template?: string;\n timeoutMs?: number;\n metadata?: Record<string, string>;\n envVars?: Record<string, string>;\n}\n\ninterface SandboxIdInput {\n sandboxId: string;\n}\n\ninterface ListSandboxesInput {\n templateId?: string;\n}\n\ninterface SetTimeoutInput {\n sandboxId: string;\n timeoutMs: number;\n}\n\ninterface RunCodeInput {\n sandboxId: string;\n code: string;\n language?: string;\n timeoutMs?: number;\n}\n\ninterface RunCommandInput {\n sandboxId: string;\n command: string;\n cwd?: string;\n background?: boolean;\n timeoutMs?: number;\n}\n\ninterface WriteFileInput {\n sandboxId: string;\n path: string;\n content: string;\n}\n\ninterface ReadFileInput {\n sandboxId: string;\n path: string;\n}\n\ninterface ListFilesInput {\n sandboxId: string;\n path: string;\n}\n\ninterface UploadFileInput {\n sandboxId: string;\n path: string;\n content?: string;\n url?: string;\n}\n\ninterface DownloadFileInput {\n sandboxId: string;\n path: string;\n}\n\ninterface MakeDirectoryInput {\n sandboxId: string;\n path: string;\n}\n\ninterface WatchDirectoryInput {\n sandboxId: string;\n path: string;\n}\n\ninterface ResumeInput {\n sandboxId: string;\n timeoutMs?: number;\n}\n\ninterface SetEnvVarsInput {\n sandboxId: string;\n envVars: Record<string, string>;\n}\n\ninterface InstallPackagesInput {\n sandboxId: string;\n packages: string[];\n}\n\n// ============================================================================\n// Sandbox Connection Cache\n// ============================================================================\n\nconst sandboxCache = new Map<string, Sandbox>();\n\nasync function getOrConnectSandbox(sandboxId: string): Promise<Sandbox> {\n if (!sandboxId) {\n throw new Error('sandboxId is required');\n }\n\n const cached = sandboxCache.get(sandboxId);\n if (cached) {\n return cached;\n }\n\n try {\n const sandbox = await Sandbox.connect(sandboxId);\n sandboxCache.set(sandboxId, sandbox);\n return sandbox;\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to connect to sandbox ${sandboxId}: ${message}`);\n }\n}\n\nfunction removeSandboxFromCache(sandboxId: string): void {\n sandboxCache.delete(sandboxId);\n}\n\n// ============================================================================\n// Tools\n// ============================================================================\n\n/**\n * Create a new E2B sandbox\n */\nexport const createSandbox = tool({\n description:\n 'Create a new E2B cloud sandbox from a template. Sandboxes are isolated Linux environments for AI code execution. Defaults to \"base\" template with 5 minute timeout if not specified. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<CreateSandboxInput>({\n type: 'object',\n properties: {\n template: {\n type: 'string',\n description: 'Template ID to use (default: \"base\" for Code Interpreter)',\n },\n timeoutMs: {\n type: 'number',\n description: 'Sandbox timeout in milliseconds (default: 300000 = 5 minutes)',\n },\n metadata: {\n type: 'object',\n description: 'Custom metadata key-value pairs to attach to sandbox',\n additionalProperties: { type: 'string' },\n },\n envVars: {\n type: 'object',\n description: 'Environment variables to set in the sandbox',\n additionalProperties: { type: 'string' },\n },\n },\n required: [],\n additionalProperties: false,\n }),\n async execute(input: CreateSandboxInput): Promise<E2BSandbox> {\n const templateId = input.template || 'base';\n const timeoutMs = input.timeoutMs || 300000; // Default 5 minutes\n\n try {\n const sandbox = await Sandbox.create(templateId, {\n timeoutMs,\n metadata: input.metadata,\n envs: input.envVars,\n });\n\n sandboxCache.set(sandbox.sandboxId, sandbox);\n\n return {\n sandboxId: sandbox.sandboxId,\n templateId,\n status: 'running',\n startedAt: new Date().toISOString(),\n clientId: sandbox.sandboxId,\n metadata: input.metadata,\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to create sandbox with template \"${templateId}\": ${message}`);\n }\n },\n});\n\n/**\n * Get sandbox details\n */\nexport const getSandbox = tool({\n description:\n 'Connect to and verify an existing E2B sandbox is running. Returns sandbox ID and connection status. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<SandboxIdInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox to retrieve',\n },\n },\n required: ['sandboxId'],\n additionalProperties: false,\n }),\n async execute(input: SandboxIdInput): Promise<E2BSandbox> {\n try {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n return {\n sandboxId: sandbox.sandboxId,\n templateId: (sandbox as unknown as { templateId?: string }).templateId || 'base',\n status: 'running',\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to get sandbox ${input.sandboxId}: ${message}`);\n }\n },\n});\n\n/**\n * List all sandboxes\n */\nexport const listSandboxes = tool({\n description:\n 'List all running E2B sandboxes in your account with their status and metadata. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<ListSandboxesInput>({\n type: 'object',\n properties: {\n templateId: {\n type: 'string',\n description: 'Filter sandboxes by template ID',\n },\n },\n required: [],\n additionalProperties: false,\n }),\n async execute(_input: ListSandboxesInput): Promise<E2BSandboxList> {\n const sandboxes = await Sandbox.list();\n return {\n sandboxes: sandboxes.map((s) => ({\n sandboxId: s.sandboxId,\n templateId: s.templateId || 'unknown',\n status: 'running',\n startedAt: s.startedAt?.toISOString(),\n clientId: s.clientId,\n metadata: s.metadata,\n })),\n count: sandboxes.length,\n };\n },\n});\n\n/**\n * Kill a sandbox\n */\nexport const killSandbox = tool({\n description:\n 'Terminate a running E2B sandbox immediately. All data and processes are destroyed. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<SandboxIdInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox to terminate',\n },\n },\n required: ['sandboxId'],\n additionalProperties: false,\n }),\n async execute(input: SandboxIdInput): Promise<{ killed: boolean; sandboxId: string }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n await sandbox.kill();\n removeSandboxFromCache(input.sandboxId);\n return { killed: true, sandboxId: input.sandboxId };\n },\n});\n\n/**\n * Set sandbox timeout\n */\nexport const setTimeout = tool({\n description:\n 'Set or extend the timeout for an E2B sandbox. The sandbox will be automatically killed when the timeout expires. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<SetTimeoutInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n timeoutMs: {\n type: 'number',\n description: 'New timeout in milliseconds from now',\n },\n },\n required: ['sandboxId', 'timeoutMs'],\n additionalProperties: false,\n }),\n async execute(input: SetTimeoutInput): Promise<{ success: boolean; expiresAt: string }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n await sandbox.setTimeout(input.timeoutMs);\n const expiresAt = new Date(Date.now() + input.timeoutMs).toISOString();\n return { success: true, expiresAt };\n },\n});\n\n/**\n * Run code in sandbox\n */\nexport const runCode = tool({\n description:\n 'Execute code in an E2B sandbox. Supports Python (default), JavaScript, TypeScript, R, Java, and Bash with streaming output and result capture. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<RunCodeInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox to execute in',\n },\n code: {\n type: 'string',\n description: 'Code to execute',\n },\n language: {\n type: 'string',\n description: 'Language: python (default), javascript, typescript, r, java, bash',\n },\n timeoutMs: {\n type: 'number',\n description: 'Execution timeout in milliseconds (default: 60000)',\n },\n },\n required: ['sandboxId', 'code'],\n additionalProperties: false,\n }),\n async execute(input: RunCodeInput): Promise<E2BExecResult> {\n const startTime = Date.now();\n const language = input.language || 'python';\n const timeoutMs = input.timeoutMs || 60000;\n\n try {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n\n const execution = await sandbox.runCode(input.code, {\n language: language as 'python' | 'javascript' | 'typescript' | 'r' | 'java',\n timeoutMs,\n });\n\n const duration = Date.now() - startTime;\n\n return {\n stdout: execution.logs.stdout.join('\\n'),\n stderr: execution.logs.stderr.join('\\n'),\n results: execution.results.map((r) => r.toJSON()),\n error: execution.error\n ? {\n name: execution.error.name,\n message: execution.error.value,\n traceback: execution.error.traceback,\n }\n : undefined,\n duration,\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to execute code in sandbox ${input.sandboxId}: ${message}`);\n }\n },\n});\n\n/**\n * Run shell command\n */\nexport const runCommand = tool({\n description:\n 'Execute a shell command in an E2B sandbox with full shell access. Supports background processes and working directory. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<RunCommandInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n command: {\n type: 'string',\n description: 'Shell command to execute',\n },\n cwd: {\n type: 'string',\n description: 'Working directory for the command',\n },\n background: {\n type: 'boolean',\n description: 'Run command in background (default: false)',\n },\n timeoutMs: {\n type: 'number',\n description: 'Command timeout in milliseconds (default: 60000)',\n },\n },\n required: ['sandboxId', 'command'],\n additionalProperties: false,\n }),\n async execute(\n input: RunCommandInput\n ): Promise<{ stdout: string; stderr: string; exitCode: number; processId?: string }> {\n const timeoutMs = input.timeoutMs || 60000;\n\n try {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n\n if (input.background) {\n const process = await sandbox.commands.run(input.command, {\n cwd: input.cwd,\n background: true,\n timeoutMs,\n });\n return {\n stdout: '',\n stderr: '',\n exitCode: 0,\n processId: String(process.pid),\n };\n }\n\n const result = await sandbox.commands.run(input.command, {\n cwd: input.cwd,\n timeoutMs,\n });\n\n return {\n stdout: result.stdout,\n stderr: result.stderr,\n exitCode: result.exitCode,\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to run command in sandbox ${input.sandboxId}: ${message}`);\n }\n },\n});\n\n/**\n * Write file to sandbox\n */\nexport const writeFile = tool({\n description:\n 'Write content to a file in the E2B sandbox filesystem. Creates directories as needed. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<WriteFileInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n path: {\n type: 'string',\n description: 'Absolute path in sandbox (e.g., /home/user/file.txt)',\n },\n content: {\n type: 'string',\n description: 'File content as string',\n },\n },\n required: ['sandboxId', 'path', 'content'],\n additionalProperties: false,\n }),\n async execute(input: WriteFileInput): Promise<{ success: boolean; path: string; size: number }> {\n try {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n await sandbox.files.write(input.path, input.content);\n\n return {\n success: true,\n path: input.path,\n size: input.content.length,\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to write file ${input.path} in sandbox ${input.sandboxId}: ${message}`);\n }\n },\n});\n\n/**\n * Read file from sandbox\n */\nexport const readFile = tool({\n description: 'Read content from a file in the E2B sandbox filesystem. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<ReadFileInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n path: {\n type: 'string',\n description: 'Absolute path to file in sandbox',\n },\n },\n required: ['sandboxId', 'path'],\n additionalProperties: false,\n }),\n async execute(input: ReadFileInput): Promise<{ content: string; path: string; size: number }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n const content = await sandbox.files.read(input.path);\n\n const textContent = typeof content === 'string' ? content : new TextDecoder().decode(content);\n\n return {\n content: textContent,\n path: input.path,\n size: textContent.length,\n };\n },\n});\n\n/**\n * List files in sandbox\n */\nexport const listFiles = tool({\n description: 'List files and directories at a path in the E2B sandbox. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<ListFilesInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n path: {\n type: 'string',\n description: 'Absolute path to list (e.g., /home/user)',\n },\n },\n required: ['sandboxId', 'path'],\n additionalProperties: false,\n }),\n async execute(input: ListFilesInput): Promise<{ entries: E2BFileInfo[]; count: number }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n const entries = await sandbox.files.list(input.path);\n\n return {\n entries: entries.map((e) => ({\n name: e.name,\n path: `${input.path}/${e.name}`,\n type: e.type as 'file' | 'directory',\n })),\n count: entries.length,\n };\n },\n});\n\n/**\n * Upload file to sandbox\n */\nexport const uploadFile = tool({\n description:\n 'Upload a file to the E2B sandbox from base64 content or a URL. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<UploadFileInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n path: {\n type: 'string',\n description: 'Destination path in sandbox',\n },\n content: {\n type: 'string',\n description: 'Base64 encoded file content',\n },\n url: {\n type: 'string',\n description: 'URL to fetch file from (alternative to content)',\n },\n },\n required: ['sandboxId', 'path'],\n additionalProperties: false,\n }),\n async execute(input: UploadFileInput): Promise<{ success: boolean; path: string; size: number }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n\n let fileContent: ArrayBuffer;\n if (input.url) {\n const response = await fetch(input.url);\n fileContent = await response.arrayBuffer();\n } else if (input.content) {\n const binaryString = atob(input.content);\n const bytes = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n bytes[i] = binaryString.charCodeAt(i);\n }\n fileContent = bytes.buffer;\n } else {\n throw new Error('Either content or url must be provided');\n }\n\n await sandbox.files.write(input.path, fileContent);\n\n return {\n success: true,\n path: input.path,\n size: fileContent.byteLength,\n };\n },\n});\n\n/**\n * Download file from sandbox\n */\nexport const downloadFile = tool({\n description: 'Download a file from the E2B sandbox as base64 content. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<DownloadFileInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n path: {\n type: 'string',\n description: 'Path to file in sandbox',\n },\n },\n required: ['sandboxId', 'path'],\n additionalProperties: false,\n }),\n async execute(\n input: DownloadFileInput\n ): Promise<{ content: string; filename: string; size: number; mimeType: string }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n const content = await sandbox.files.read(input.path);\n\n const filename = input.path.split('/').pop() || 'file';\n const ext = filename.split('.').pop()?.toLowerCase() || '';\n\n // Convert to base64 and calculate size\n let base64Content: string;\n let contentLength: number;\n\n if (typeof content === 'string') {\n base64Content = btoa(content);\n contentLength = content.length;\n } else {\n const bytes = new Uint8Array(content as ArrayBuffer);\n contentLength = bytes.length;\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]!);\n }\n base64Content = btoa(binary);\n }\n\n // Simple MIME type detection\n const mimeTypes: Record<string, string> = {\n txt: 'text/plain',\n json: 'application/json',\n js: 'text/javascript',\n ts: 'text/typescript',\n py: 'text/x-python',\n html: 'text/html',\n css: 'text/css',\n png: 'image/png',\n jpg: 'image/jpeg',\n jpeg: 'image/jpeg',\n gif: 'image/gif',\n pdf: 'application/pdf',\n zip: 'application/zip',\n };\n\n return {\n content: base64Content,\n filename,\n size: contentLength,\n mimeType: mimeTypes[ext] || 'application/octet-stream',\n };\n },\n});\n\n/**\n * Create directory in sandbox\n */\nexport const makeDirectory = tool({\n description:\n 'Create a directory in the E2B sandbox filesystem. Creates parent directories as needed. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<MakeDirectoryInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n path: {\n type: 'string',\n description: 'Absolute path of directory to create',\n },\n },\n required: ['sandboxId', 'path'],\n additionalProperties: false,\n }),\n async execute(input: MakeDirectoryInput): Promise<{ success: boolean; path: string }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n await sandbox.files.makeDir(input.path);\n return { success: true, path: input.path };\n },\n});\n\n/**\n * Watch directory for changes\n */\nexport const watchDirectory = tool({\n description:\n 'Watch a directory in the E2B sandbox for file changes. Returns the initial state. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<WatchDirectoryInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n path: {\n type: 'string',\n description: 'Directory path to watch',\n },\n },\n required: ['sandboxId', 'path'],\n additionalProperties: false,\n }),\n async execute(\n input: WatchDirectoryInput\n ): Promise<{ entries: E2BFileInfo[]; watcherId: string }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n const entries = await sandbox.files.list(input.path);\n\n return {\n entries: entries.map((e) => ({\n name: e.name,\n path: `${input.path}/${e.name}`,\n type: e.type as 'file' | 'directory',\n })),\n watcherId: `watch-${input.sandboxId}-${Date.now()}`,\n };\n },\n});\n\n/**\n * Pause sandbox (using keepalive approach)\n */\nexport const pauseSandbox = tool({\n description:\n 'Disconnect from an E2B sandbox while keeping it running. The sandbox continues running and can be reconnected later using resumeSandbox. State is preserved in the sandbox. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<SandboxIdInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox to disconnect from',\n },\n },\n required: ['sandboxId'],\n additionalProperties: false,\n }),\n async execute(input: SandboxIdInput): Promise<{ success: boolean; sandboxId: string; status: string }> {\n if (!input.sandboxId) {\n throw new Error('sandboxId is required');\n }\n\n // Verify sandbox exists by attempting to connect first\n try {\n await getOrConnectSandbox(input.sandboxId);\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Cannot pause sandbox ${input.sandboxId}: ${message}`);\n }\n\n // Disconnect from sandbox while keeping it running\n removeSandboxFromCache(input.sandboxId);\n return {\n success: true,\n sandboxId: input.sandboxId,\n status: 'disconnected',\n };\n },\n});\n\n/**\n * Resume (reconnect to) sandbox\n */\nexport const resumeSandbox = tool({\n description:\n 'Reconnect to a running E2B sandbox that was previously disconnected using pauseSandbox. Optionally set a new timeout. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<ResumeInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox to reconnect to',\n },\n timeoutMs: {\n type: 'number',\n description: 'New timeout for the sandbox in milliseconds (optional)',\n },\n },\n required: ['sandboxId'],\n additionalProperties: false,\n }),\n async execute(input: ResumeInput): Promise<{ sandboxId: string; status: string }> {\n try {\n const sandbox = await Sandbox.connect(input.sandboxId);\n if (input.timeoutMs) {\n await sandbox.setTimeout(input.timeoutMs);\n }\n sandboxCache.set(sandbox.sandboxId, sandbox);\n return { sandboxId: sandbox.sandboxId, status: 'running' };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to reconnect to sandbox ${input.sandboxId}: ${message}`);\n }\n },\n});\n\n/**\n * Set environment variables\n */\nexport const setEnvVars = tool({\n description:\n 'Set environment variables in an E2B sandbox. These persist for subsequent code executions in the same sandbox session. Special characters are safely escaped. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<SetEnvVarsInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n envVars: {\n type: 'object',\n description: 'Key-value pairs of environment variables to set',\n additionalProperties: { type: 'string' },\n },\n },\n required: ['sandboxId', 'envVars'],\n additionalProperties: false,\n }),\n async execute(input: SetEnvVarsInput): Promise<{ success: boolean; count: number }> {\n try {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n\n // Escape shell special characters in values\n const escapeForShell = (str: string): string => {\n return str\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\$/g, '\\\\$')\n .replace(/`/g, '\\\\`')\n .replace(/!/g, '\\\\!');\n };\n\n // Set each environment variable using shell export\n for (const [key, value] of Object.entries(input.envVars)) {\n await sandbox.commands.run(`export ${key}=\"${escapeForShell(value)}\"`);\n }\n\n return { success: true, count: Object.keys(input.envVars).length };\n } catch (error) {\n const message = error instanceof Error ? error.message : 'Unknown error';\n throw new Error(`Failed to set environment variables in sandbox ${input.sandboxId}: ${message}`);\n }\n },\n});\n\n/**\n * Get sandbox metrics\n */\nexport const getMetrics = tool({\n description:\n 'Get resource usage metrics for an E2B sandbox including CPU, memory, and network usage. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<SandboxIdInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n },\n required: ['sandboxId'],\n additionalProperties: false,\n }),\n async execute(input: SandboxIdInput): Promise<E2BMetrics> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n\n // Get metrics using /proc filesystem\n const cpuResult = await sandbox.commands.run(\n \"cat /proc/stat | grep 'cpu ' | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage}'\"\n );\n const memResult = await sandbox.commands.run(\"free -m | grep Mem | awk '{print $3}'\");\n\n return {\n cpuPct: parseFloat(cpuResult.stdout) || 0,\n memUsedMB: parseInt(memResult.stdout) || 0,\n networkIngressMB: 0,\n networkEgressMB: 0,\n };\n },\n});\n\n/**\n * Install Python packages\n */\nexport const installPackages = tool({\n description:\n 'Install Python packages in an E2B Code Interpreter sandbox using pip. Requires E2B_API_KEY.',\n inputSchema: jsonSchema<InstallPackagesInput>({\n type: 'object',\n properties: {\n sandboxId: {\n type: 'string',\n description: 'ID of the sandbox',\n },\n packages: {\n type: 'array',\n items: { type: 'string' },\n description: \"Array of package names to install (e.g., ['numpy', 'pandas==2.0.0'])\",\n },\n },\n required: ['sandboxId', 'packages'],\n additionalProperties: false,\n }),\n async execute(\n input: InstallPackagesInput\n ): Promise<{ success: boolean; installed: string[]; errors?: string[] }> {\n const sandbox = await getOrConnectSandbox(input.sandboxId);\n\n const installed: string[] = [];\n const errors: string[] = [];\n\n for (const pkg of input.packages) {\n try {\n const result = await sandbox.commands.run(`pip install ${pkg}`, { timeoutMs: 120000 });\n if (result.exitCode === 0) {\n installed.push(pkg);\n } else {\n errors.push(`${pkg}: ${result.stderr}`);\n }\n } catch (error) {\n errors.push(`${pkg}: ${error instanceof Error ? error.message : 'Unknown error'}`);\n }\n }\n\n return {\n success: errors.length === 0,\n installed,\n errors: errors.length > 0 ? errors : undefined,\n };\n },\n});\n\n// ============================================================================\n// Default Export\n// ============================================================================\n\nexport default {\n createSandbox,\n getSandbox,\n listSandboxes,\n killSandbox,\n setTimeout,\n runCode,\n runCommand,\n writeFile,\n readFile,\n listFiles,\n uploadFile,\n downloadFile,\n makeDirectory,\n watchDirectory,\n pauseSandbox,\n resumeSandbox,\n setEnvVars,\n getMetrics,\n installPackages,\n};\n"],"m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A,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,140 @@
1
+ {
2
+ "name": "@tpmjs/tools-e2b",
3
+ "version": "0.1.0",
4
+ "description": "E2B cloud sandbox tools for AI code execution. Create sandboxes, run code in multiple languages, manage files, and control sandbox lifecycle.",
5
+ "type": "module",
6
+ "keywords": [
7
+ "tpmjs",
8
+ "e2b",
9
+ "sandbox",
10
+ "code-interpreter",
11
+ "ai",
12
+ "code-execution",
13
+ "cloud"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "dev": "tsup --watch",
27
+ "type-check": "tsc --noEmit",
28
+ "clean": "rm -rf dist .turbo"
29
+ },
30
+ "devDependencies": {
31
+ "@tpmjs/tsconfig": "workspace:*",
32
+ "tsup": "^8.5.1",
33
+ "typescript": "^5.9.3"
34
+ },
35
+ "dependencies": {
36
+ "ai": "6.0.23",
37
+ "@e2b/code-interpreter": "^1.0.4"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/tpmjs/tpmjs.git",
45
+ "directory": "packages/tools/official/e2b"
46
+ },
47
+ "homepage": "https://tpmjs.com",
48
+ "license": "MIT",
49
+ "tpmjs": {
50
+ "category": "sandbox",
51
+ "frameworks": [
52
+ "vercel-ai"
53
+ ],
54
+ "env": [
55
+ {
56
+ "name": "E2B_API_KEY",
57
+ "description": "API key for E2B authentication. Get yours at https://e2b.dev/dashboard",
58
+ "required": true
59
+ }
60
+ ],
61
+ "tools": [
62
+ {
63
+ "name": "createSandbox",
64
+ "description": "Create a new E2B cloud sandbox from a template with configurable resources and timeout."
65
+ },
66
+ {
67
+ "name": "getSandbox",
68
+ "description": "Get details of an existing E2B sandbox by ID."
69
+ },
70
+ {
71
+ "name": "listSandboxes",
72
+ "description": "List all running E2B sandboxes in your account."
73
+ },
74
+ {
75
+ "name": "killSandbox",
76
+ "description": "Terminate a running E2B sandbox immediately."
77
+ },
78
+ {
79
+ "name": "setTimeout",
80
+ "description": "Set or extend the timeout for an E2B sandbox."
81
+ },
82
+ {
83
+ "name": "runCode",
84
+ "description": "Execute code in an E2B sandbox. Supports Python, JavaScript, TypeScript, R, Java, and Bash."
85
+ },
86
+ {
87
+ "name": "runCommand",
88
+ "description": "Execute a shell command in an E2B sandbox."
89
+ },
90
+ {
91
+ "name": "writeFile",
92
+ "description": "Write content to a file in the E2B sandbox filesystem."
93
+ },
94
+ {
95
+ "name": "readFile",
96
+ "description": "Read content from a file in the E2B sandbox filesystem."
97
+ },
98
+ {
99
+ "name": "listFiles",
100
+ "description": "List files and directories at a path in the E2B sandbox."
101
+ },
102
+ {
103
+ "name": "uploadFile",
104
+ "description": "Upload a file to the E2B sandbox from base64 content or URL."
105
+ },
106
+ {
107
+ "name": "downloadFile",
108
+ "description": "Download a file from the E2B sandbox as base64 content."
109
+ },
110
+ {
111
+ "name": "makeDirectory",
112
+ "description": "Create a directory in the E2B sandbox filesystem."
113
+ },
114
+ {
115
+ "name": "watchDirectory",
116
+ "description": "Watch a directory in the E2B sandbox for file changes."
117
+ },
118
+ {
119
+ "name": "pauseSandbox",
120
+ "description": "Pause a running E2B sandbox to preserve state."
121
+ },
122
+ {
123
+ "name": "resumeSandbox",
124
+ "description": "Resume a previously paused E2B sandbox."
125
+ },
126
+ {
127
+ "name": "setEnvVars",
128
+ "description": "Set environment variables in an E2B sandbox."
129
+ },
130
+ {
131
+ "name": "getMetrics",
132
+ "description": "Get resource usage metrics for an E2B sandbox."
133
+ },
134
+ {
135
+ "name": "installPackages",
136
+ "description": "Install Python packages in an E2B Code Interpreter sandbox."
137
+ }
138
+ ]
139
+ }
140
+ }