@voidrun/sdk 0.0.15 → 0.0.17

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 (110) hide show
  1. package/README.md +115 -62
  2. package/dist/CodeInterpreter.d.ts +77 -0
  3. package/dist/CodeInterpreter.d.ts.map +1 -0
  4. package/dist/CodeInterpreter.js +323 -0
  5. package/dist/CodeInterpreter.js.map +1 -0
  6. package/dist/PtySession.d.ts +1 -1
  7. package/dist/PtySession.d.ts.map +1 -1
  8. package/dist/PtySession.js +46 -7
  9. package/dist/PtySession.js.map +1 -1
  10. package/dist/Sandbox.d.ts +5 -0
  11. package/dist/Sandbox.d.ts.map +1 -1
  12. package/dist/Sandbox.js +5 -0
  13. package/dist/Sandbox.js.map +1 -1
  14. package/dist/api-client/apis/AuthenticationApi.d.ts +2 -2
  15. package/dist/api-client/apis/AuthenticationApi.d.ts.map +1 -1
  16. package/dist/api-client/apis/AuthenticationApi.js +2 -2
  17. package/dist/api-client/apis/AuthenticationApi.js.map +1 -1
  18. package/dist/api-client/apis/ExecutionApi.d.ts +2 -2
  19. package/dist/api-client/apis/ExecutionApi.d.ts.map +1 -1
  20. package/dist/api-client/apis/ExecutionApi.js +2 -2
  21. package/dist/api-client/apis/ExecutionApi.js.map +1 -1
  22. package/dist/api-client/apis/FileSystemApi.d.ts +2 -2
  23. package/dist/api-client/apis/FileSystemApi.d.ts.map +1 -1
  24. package/dist/api-client/apis/FileSystemApi.js +2 -2
  25. package/dist/api-client/apis/FileSystemApi.js.map +1 -1
  26. package/dist/api-client/apis/ImagesApi.d.ts +2 -2
  27. package/dist/api-client/apis/ImagesApi.d.ts.map +1 -1
  28. package/dist/api-client/apis/ImagesApi.js +2 -2
  29. package/dist/api-client/apis/ImagesApi.js.map +1 -1
  30. package/dist/api-client/apis/OrganizationsApi.d.ts +2 -2
  31. package/dist/api-client/apis/OrganizationsApi.d.ts.map +1 -1
  32. package/dist/api-client/apis/OrganizationsApi.js +2 -2
  33. package/dist/api-client/apis/OrganizationsApi.js.map +1 -1
  34. package/dist/api-client/apis/SandboxesApi.d.ts +2 -2
  35. package/dist/api-client/apis/SandboxesApi.d.ts.map +1 -1
  36. package/dist/api-client/apis/SandboxesApi.js +2 -2
  37. package/dist/api-client/apis/SandboxesApi.js.map +1 -1
  38. package/dist/api-client/apis/index.d.ts +6 -6
  39. package/dist/api-client/apis/index.d.ts.map +1 -1
  40. package/dist/api-client/apis/index.js +6 -6
  41. package/dist/api-client/apis/index.js.map +1 -1
  42. package/dist/api-client/index.d.ts +3 -3
  43. package/dist/api-client/index.d.ts.map +1 -1
  44. package/dist/api-client/index.js +3 -3
  45. package/dist/api-client/index.js.map +1 -1
  46. package/dist/api-client/models/ApiResponseSandbox.d.ts +1 -1
  47. package/dist/api-client/models/ApiResponseSandbox.d.ts.map +1 -1
  48. package/dist/api-client/models/ApiResponseSandbox.js +1 -1
  49. package/dist/api-client/models/ApiResponseSandbox.js.map +1 -1
  50. package/dist/api-client/models/ApiResponseSandboxesList.d.ts +2 -2
  51. package/dist/api-client/models/ApiResponseSandboxesList.d.ts.map +1 -1
  52. package/dist/api-client/models/ApiResponseSandboxesList.js +2 -2
  53. package/dist/api-client/models/ApiResponseSandboxesList.js.map +1 -1
  54. package/dist/api-client/models/CreatePTYSession200Response.d.ts +1 -1
  55. package/dist/api-client/models/CreatePTYSession200Response.d.ts.map +1 -1
  56. package/dist/api-client/models/CreatePTYSession200Response.js +1 -1
  57. package/dist/api-client/models/CreatePTYSession200Response.js.map +1 -1
  58. package/dist/api-client/models/CreateSandbox201Response.d.ts +1 -1
  59. package/dist/api-client/models/CreateSandbox201Response.d.ts.map +1 -1
  60. package/dist/api-client/models/CreateSandbox201Response.js +1 -1
  61. package/dist/api-client/models/CreateSandbox201Response.js.map +1 -1
  62. package/dist/api-client/models/CreateSandboxRequest.d.ts +8 -0
  63. package/dist/api-client/models/CreateSandboxRequest.d.ts.map +1 -1
  64. package/dist/api-client/models/CreateSandboxRequest.js +2 -0
  65. package/dist/api-client/models/CreateSandboxRequest.js.map +1 -1
  66. package/dist/api-client/models/ExecResponse.d.ts +1 -1
  67. package/dist/api-client/models/ExecResponse.d.ts.map +1 -1
  68. package/dist/api-client/models/ExecResponse.js +1 -1
  69. package/dist/api-client/models/ExecResponse.js.map +1 -1
  70. package/dist/api-client/models/GetPTYBuffer200Response.d.ts +1 -1
  71. package/dist/api-client/models/GetPTYBuffer200Response.d.ts.map +1 -1
  72. package/dist/api-client/models/GetPTYBuffer200Response.js +1 -1
  73. package/dist/api-client/models/GetPTYBuffer200Response.js.map +1 -1
  74. package/dist/api-client/models/ListFiles200Response.d.ts +1 -1
  75. package/dist/api-client/models/ListFiles200Response.d.ts.map +1 -1
  76. package/dist/api-client/models/ListFiles200Response.js +1 -1
  77. package/dist/api-client/models/ListFiles200Response.js.map +1 -1
  78. package/dist/api-client/models/ListFiles200ResponseData.d.ts +1 -1
  79. package/dist/api-client/models/ListFiles200ResponseData.d.ts.map +1 -1
  80. package/dist/api-client/models/ListFiles200ResponseData.js +1 -1
  81. package/dist/api-client/models/ListFiles200ResponseData.js.map +1 -1
  82. package/dist/api-client/models/ListPTYSessions200Response.d.ts +1 -1
  83. package/dist/api-client/models/ListPTYSessions200Response.d.ts.map +1 -1
  84. package/dist/api-client/models/ListPTYSessions200Response.js +1 -1
  85. package/dist/api-client/models/ListPTYSessions200Response.js.map +1 -1
  86. package/dist/api-client/models/ListPTYSessions200ResponseAllOfData.d.ts +1 -1
  87. package/dist/api-client/models/ListPTYSessions200ResponseAllOfData.d.ts.map +1 -1
  88. package/dist/api-client/models/ListPTYSessions200ResponseAllOfData.js +1 -1
  89. package/dist/api-client/models/ListPTYSessions200ResponseAllOfData.js.map +1 -1
  90. package/dist/api-client/models/RegisterResponse.d.ts +1 -1
  91. package/dist/api-client/models/RegisterResponse.d.ts.map +1 -1
  92. package/dist/api-client/models/RegisterResponse.js +1 -1
  93. package/dist/api-client/models/RegisterResponse.js.map +1 -1
  94. package/dist/api-client/models/Sandbox.d.ts +8 -0
  95. package/dist/api-client/models/Sandbox.d.ts.map +1 -1
  96. package/dist/api-client/models/Sandbox.js +2 -0
  97. package/dist/api-client/models/Sandbox.js.map +1 -1
  98. package/dist/api-client/models/StartWatch200Response.d.ts +1 -1
  99. package/dist/api-client/models/StartWatch200Response.d.ts.map +1 -1
  100. package/dist/api-client/models/StartWatch200Response.js +1 -1
  101. package/dist/api-client/models/StartWatch200Response.js.map +1 -1
  102. package/dist/api-client/models/index.d.ts +44 -44
  103. package/dist/api-client/models/index.d.ts.map +1 -1
  104. package/dist/api-client/models/index.js +44 -44
  105. package/dist/api-client/models/index.js.map +1 -1
  106. package/dist/index.d.ts +2 -0
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +1 -0
  109. package/dist/index.js.map +1 -1
  110. package/package.json +1 -1
package/README.md CHANGED
@@ -12,6 +12,7 @@ A powerful, type-safe SDK for interacting with VoidRun AI Sandboxes. Execute cod
12
12
  - 📁 **File Operations** - Create, read, delete, compress, and extract files
13
13
  - 👀 **File Watching** - Monitor file changes in real-time via WebSocket
14
14
  - 💻 **Pseudo-Terminal (PTY)** - Interactive terminal sessions (ephemeral & persistent)
15
+ - 🧠 **Code Interpreter** - Easy multi-language code execution (Python, JavaScript, Bash, etc.)
15
16
  - 🔐 **Type-Safe** - Full TypeScript support with generated types from OpenAPI
16
17
  - ⚡ **WebSocket Support** - Real-time streaming for PTY, file watches, and execution
17
18
  - 🎯 **Promise-Based** - Modern async/await API
@@ -41,7 +42,7 @@ export API_KEY="your-api-key-here"
41
42
  ### Basic Usage
42
43
 
43
44
  ```typescript
44
- import { VoidRun } from '@voidrun/sdk';
45
+ import { VoidRun } from "@voidrun/sdk";
45
46
 
46
47
  // Initialize the SDK
47
48
  const vr = new VoidRun({});
@@ -66,8 +67,8 @@ An isolated environment where you can execute code, manage files, and run termin
66
67
  ```typescript
67
68
  // Create a sandbox
68
69
  const sandbox = await vr.createSandbox({
69
- mem: 1024, // Memory in MB (optional, has defaults)
70
- cpu: 1 // CPU cores (optional, has defaults)
70
+ mem: 1024, // Memory in MB (optional, has defaults)
71
+ cpu: 1, // CPU cores (optional, has defaults)
71
72
  });
72
73
 
73
74
  // List all sandboxes
@@ -86,52 +87,85 @@ await sandbox.remove();
86
87
  Execute commands and capture output, errors, and exit codes.
87
88
 
88
89
  ```typescript
89
- const result = await sandbox.exec({ command: 'ls -la /home' });
90
+ const result = await sandbox.exec({ command: "ls -la /home" });
90
91
 
91
- console.log(result.data?.stdout); // stdout
92
- console.log(result.data?.stderr); // stderr
93
- console.log(result.data?.exitCode); // exit code
92
+ console.log(result.data?.stdout); // stdout
93
+ console.log(result.data?.stderr); // stderr
94
+ console.log(result.data?.exitCode); // exit code
94
95
  ```
95
96
 
97
+ ### Code Interpreter
98
+
99
+ Execute code in multiple programming languages with a simple, intuitive API (similar to e2b or Daytona).
100
+
101
+ ```typescript
102
+ // Initialize interpreter with your language
103
+ await sandbox.interpreter.initialize("python");
104
+
105
+ // Execute code
106
+ const result = await sandbox.interpreter.execute("print(2 + 2)");
107
+ if (result.success) {
108
+ console.log(result.output); // "4"
109
+ }
110
+
111
+ // Execute multiple snippets
112
+ const results = await sandbox.interpreter.executeMultiple([
113
+ "x = 10",
114
+ "y = 20",
115
+ "print(x + y)",
116
+ ]);
117
+
118
+ // Switch languages
119
+ await sandbox.interpreter.reset("javascript");
120
+ const jsResult = await sandbox.interpreter.execute("console.log(2 + 2)");
121
+
122
+ // Clean up
123
+ await sandbox.interpreter.close();
124
+ ```
125
+
126
+ Supported languages: **Python**, **JavaScript**, **Node.js**, **Bash**, **Go**, **Ruby**, **Java**, **C#**
127
+
128
+ See [Code Interpreter API](./CODE_INTERPRETER_API.md) for comprehensive documentation.
129
+
96
130
  ### File Operations
97
131
 
98
132
  Create, read, update, and manage files in the sandbox.
99
133
 
100
134
  ```typescript
101
135
  // Create a file
102
- await sandbox.fs.createFile('/tmp/hello.txt');
136
+ await sandbox.fs.createFile("/tmp/hello.txt");
103
137
 
104
138
  // Upload content to file
105
- await sandbox.fs.uploadFile('/tmp/hello.txt', 'Hello, World!');
139
+ await sandbox.fs.uploadFile("/tmp/hello.txt", "Hello, World!");
106
140
 
107
141
  // Read a file
108
- const buffer = await sandbox.fs.downloadFile('/tmp/hello.txt');
142
+ const buffer = await sandbox.fs.downloadFile("/tmp/hello.txt");
109
143
  const content = buffer.toString();
110
144
 
111
145
  // Delete a file
112
- await sandbox.fs.deleteFile('/tmp/hello.txt');
146
+ await sandbox.fs.deleteFile("/tmp/hello.txt");
113
147
 
114
148
  // List directory
115
- const result = await sandbox.fs.listFiles('/tmp');
149
+ const result = await sandbox.fs.listFiles("/tmp");
116
150
  const files = result.data?.files;
117
151
 
118
152
  // Get file stats
119
- const stats = await sandbox.fs.statFile('/tmp/hello.txt');
153
+ const stats = await sandbox.fs.statFile("/tmp/hello.txt");
120
154
 
121
155
  // Compress files
122
- await sandbox.fs.compressFile('/tmp', 'tar.gz');
156
+ await sandbox.fs.compressFile("/tmp", "tar.gz");
123
157
 
124
158
  // Extract archive
125
- await sandbox.fs.extractArchive('/tmp/archive.tar.gz', '/tmp/extracted');
159
+ await sandbox.fs.extractArchive("/tmp/archive.tar.gz", "/tmp/extracted");
126
160
 
127
161
  // Create directory
128
- await sandbox.fs.createDirectory('/tmp/mydir');
162
+ await sandbox.fs.createDirectory("/tmp/mydir");
129
163
 
130
164
  // Move file
131
- await sandbox.fs.moveFile('/tmp/file.txt', '/tmp/newfile.txt');
165
+ await sandbox.fs.moveFile("/tmp/file.txt", "/tmp/newfile.txt");
132
166
 
133
167
  // Copy file
134
- await sandbox.fs.copyFile('/tmp/file.txt', '/tmp/copy.txt');
168
+ await sandbox.fs.copyFile("/tmp/file.txt", "/tmp/copy.txt");
135
169
  ```
136
170
 
137
171
  ### File Watching
@@ -139,14 +173,14 @@ await sandbox.fs.copyFile('/tmp/file.txt', '/tmp/copy.txt');
139
173
  Monitor file changes in real-time.
140
174
 
141
175
  ```typescript
142
- const watcher = await sandbox.fs.watch('/app', {
176
+ const watcher = await sandbox.fs.watch("/app", {
143
177
  recursive: true,
144
178
  onEvent: (event) => {
145
179
  console.log(`File changed: ${event.path} - ${event.type}`);
146
180
  },
147
181
  onError: (err) => {
148
- console.error('Watch error:', err);
149
- }
182
+ console.error("Watch error:", err);
183
+ },
150
184
  });
151
185
 
152
186
  // Stop watching
@@ -166,13 +200,13 @@ const pty = await sandbox.pty.connect({
166
200
  process.stdout.write(data);
167
201
  },
168
202
  onError: (err) => {
169
- console.error('PTY error:', err);
170
- }
203
+ console.error("PTY error:", err);
204
+ },
171
205
  });
172
206
 
173
207
  // Send commands
174
208
  pty.write('echo "Hello"\n');
175
- pty.write('pwd\n');
209
+ pty.write("pwd\n");
176
210
 
177
211
  // Close connection
178
212
  pty.close();
@@ -190,7 +224,7 @@ const pty = await sandbox.pty.connect({
190
224
  sessionId,
191
225
  onData: (data) => {
192
226
  process.stdout.write(data);
193
- }
227
+ },
194
228
  });
195
229
 
196
230
  // Send commands
@@ -204,7 +238,7 @@ const reconnected = await sandbox.pty.connect({
204
238
  sessionId,
205
239
  onData: (data) => {
206
240
  process.stdout.write(data); // Includes buffered output
207
- }
241
+ },
208
242
  });
209
243
  ```
210
244
 
@@ -215,18 +249,18 @@ Run commands with automatic prompt detection:
215
249
  ```typescript
216
250
  const pty = await sandbox.pty.connect({ sessionId });
217
251
 
218
- const output = await pty.runCommand('echo $SHELL', {
252
+ const output = await pty.runCommand("echo $SHELL", {
219
253
  timeout: 5000,
220
- prompt: /[#$] $/ // Regex to detect shell prompt
254
+ prompt: /[#$] $/, // Regex to detect shell prompt
221
255
  });
222
256
 
223
- console.log('Output:', output);
257
+ console.log("Output:", output);
224
258
  ```
225
259
 
226
260
  #### Resize Terminal
227
261
 
228
262
  ```typescript
229
- pty.resize(80, 24); // columns, rows
263
+ pty.resize(80, 24); // columns, rows
230
264
  ```
231
265
 
232
266
  #### Session Management
@@ -250,11 +284,13 @@ new VoidRun(options?: VoidRunOptions)
250
284
  ```
251
285
 
252
286
  **Options:**
287
+
253
288
  - `apiKey?: string` - API key (defaults to `process.env.API_KEY`)
254
289
  - `baseUrl?: string` - Base API URL (defaults to `process.env.VOIDRUN_BASE_URL`)
255
290
  - `orgId?: string` - Organization ID (optional)
256
291
 
257
292
  **Methods:**
293
+
258
294
  - `createSandbox(options: SandboxOptions)` - Create a new sandbox
259
295
  - `name?: string` - Sandbox name
260
296
  - `templateId?: string` - Template ID
@@ -273,6 +309,7 @@ new VoidRun(options?: VoidRunOptions)
273
309
  Represents an isolated sandbox environment.
274
310
 
275
311
  **Properties:**
312
+
276
313
  - `id: string` - Sandbox ID
277
314
  - `name: string` - Sandbox name
278
315
  - `cpu: number` - CPU cores
@@ -286,6 +323,7 @@ Represents an isolated sandbox environment.
286
323
  - `pty: PTY` - PTY interface
287
324
 
288
325
  **Methods:**
326
+
289
327
  - `exec(request: ExecRequest)` - Execute a command
290
328
  - `request.command: string` - Command to execute
291
329
  - `request.cwd?: string` - Working directory (optional)
@@ -295,6 +333,7 @@ Represents an isolated sandbox environment.
295
333
  - `info()` - Get sandbox information
296
334
 
297
335
  **Exec Response:**
336
+
298
337
  ```typescript
299
338
  {
300
339
  data?: {
@@ -310,6 +349,7 @@ Represents an isolated sandbox environment.
310
349
  Manage files and directories.
311
350
 
312
351
  **Methods:**
352
+
313
353
  - `createFile(path: string)` - Create a file
314
354
  - `uploadFile(path: string, content: string)` - Upload file content
315
355
  - `uploadFileStream(path: string, stream: ReadableStream)` - Upload file as stream
@@ -335,6 +375,7 @@ Manage files and directories.
335
375
  Monitor file changes in real-time.
336
376
 
337
377
  **Methods:**
378
+
338
379
  - `watch(path: string, options: FileWatchOptions)` - Start watching a path
339
380
  - `recursive?: boolean` - Watch subdirectories
340
381
  - `onEvent(event: FileChangeEvent)` - Called on file change
@@ -342,6 +383,7 @@ Monitor file changes in real-time.
342
383
  - `onClose()` - Called when watcher closes (optional)
343
384
 
344
385
  **Watcher Methods:**
386
+
345
387
  - `close()` - Stop watching
346
388
 
347
389
  ### PTY Interface
@@ -349,6 +391,7 @@ Monitor file changes in real-time.
349
391
  Pseudo-terminal operations.
350
392
 
351
393
  **Methods:**
394
+
352
395
  - `list()` - List active sessions
353
396
  - `createSession()` - Create a persistent session
354
397
  - `connect(options: PtyOptions)` - Connect to PTY
@@ -359,6 +402,7 @@ Pseudo-terminal operations.
359
402
  - `deleteSession(sessionId: string)` - Delete a session
360
403
 
361
404
  **PtySession Methods:**
405
+
362
406
  - `write(data: string)` - Send data
363
407
  - `runCommand(cmd: string, options: RunCommandOptions)` - Execute with prompt detection
364
408
  - `resize(cols: number, rows: number)` - Resize terminal
@@ -369,20 +413,23 @@ Pseudo-terminal operations.
369
413
  ### Execute Python Script
370
414
 
371
415
  ```typescript
372
- import { VoidRun } from '@voidrun/sdk';
416
+ import { VoidRun } from "@voidrun/sdk";
373
417
 
374
418
  const vr = new VoidRun({});
375
419
  const sandbox = await vr.createSandbox({ mem: 1024, cpu: 1 });
376
420
 
377
421
  // Create Python script
378
- await sandbox.fs.createFile('/tmp/script.py');
379
- await sandbox.fs.uploadFile('/tmp/script.py', `
422
+ await sandbox.fs.createFile("/tmp/script.py");
423
+ await sandbox.fs.uploadFile(
424
+ "/tmp/script.py",
425
+ `
380
426
  import sys
381
427
  print("Python version:", sys.version)
382
428
  print("Hello from Python!")
383
- `);
429
+ `,
430
+ );
384
431
 
385
- const result = await sandbox.exec({ command: 'python3 /tmp/script.py' });
432
+ const result = await sandbox.exec({ command: "python3 /tmp/script.py" });
386
433
  console.log(result.data?.stdout);
387
434
 
388
435
  await sandbox.remove();
@@ -394,14 +441,14 @@ await sandbox.remove();
394
441
  const sandbox = await vr.createSandbox({ mem: 1024, cpu: 1 });
395
442
 
396
443
  // Watch for TypeScript file changes
397
- const watcher = await sandbox.fs.watch('/app/src', {
444
+ const watcher = await sandbox.fs.watch("/app/src", {
398
445
  recursive: true,
399
446
  onEvent: async (event) => {
400
447
  console.log(`File ${event.type}: ${event.path}`);
401
-
448
+
402
449
  // Auto-compile on change
403
- await sandbox.exec({ command: 'npm run build' });
404
- }
450
+ await sandbox.exec({ command: "npm run build" });
451
+ },
405
452
  });
406
453
 
407
454
  // Clean up
@@ -415,20 +462,20 @@ const sandbox = await vr.createSandbox({ mem: 2048, cpu: 2 });
415
462
 
416
463
  // Upload source code
417
464
  const sourceCode = `console.log('Hello World');`;
418
- await sandbox.fs.createFile('/app/main.js');
419
- await sandbox.fs.uploadFile('/app/main.js', sourceCode);
465
+ await sandbox.fs.createFile("/app/main.js");
466
+ await sandbox.fs.uploadFile("/app/main.js", sourceCode);
420
467
 
421
468
  // Install dependencies
422
- let result = await sandbox.exec({ command: 'npm install' });
423
- if (result.data?.exitCode !== 0) throw new Error('Install failed');
469
+ let result = await sandbox.exec({ command: "npm install" });
470
+ if (result.data?.exitCode !== 0) throw new Error("Install failed");
424
471
 
425
472
  // Run tests
426
- result = await sandbox.exec({ command: 'npm test' });
427
- console.log('Test output:', result.data?.stdout);
473
+ result = await sandbox.exec({ command: "npm test" });
474
+ console.log("Test output:", result.data?.stdout);
428
475
 
429
476
  // Build
430
- result = await sandbox.exec({ command: 'npm run build' });
431
- console.log('Build output:', result.data?.stdout);
477
+ result = await sandbox.exec({ command: "npm run build" });
478
+ console.log("Build output:", result.data?.stdout);
432
479
 
433
480
  await sandbox.remove();
434
481
  ```
@@ -445,18 +492,18 @@ const sessionId = sessionResp.data?.sessionId;
445
492
  const pty = await sandbox.pty.connect({
446
493
  sessionId,
447
494
  onData: (data) => process.stdout.write(data),
448
- onClose: () => console.log('Shell closed')
495
+ onClose: () => console.log("Shell closed"),
449
496
  });
450
497
 
451
498
  // Interactive commands
452
- pty.write('npm init -y\n');
453
- await new Promise(r => setTimeout(r, 1000));
499
+ pty.write("npm init -y\n");
500
+ await new Promise((r) => setTimeout(r, 1000));
454
501
 
455
- pty.write('npm install express\n');
456
- await new Promise(r => setTimeout(r, 2000));
502
+ pty.write("npm install express\n");
503
+ await new Promise((r) => setTimeout(r, 2000));
457
504
 
458
505
  pty.write('node -e "console.log(process.version)"\n');
459
- await new Promise(r => setTimeout(r, 500));
506
+ await new Promise((r) => setTimeout(r, 500));
460
507
 
461
508
  pty.close();
462
509
  await sandbox.remove();
@@ -497,12 +544,13 @@ try {
497
544
  // ...
498
545
  } catch (error) {
499
546
  if (error instanceof Error) {
500
- console.error('Error:', error.message);
547
+ console.error("Error:", error.message);
501
548
  }
502
549
  }
503
550
  ```
504
551
 
505
552
  Common errors:
553
+
506
554
  - **Validation Error** - Invalid sandbox parameters
507
555
  - **Authentication Error** - Invalid or missing API key
508
556
  - **Not Found** - Sandbox or session doesn't exist
@@ -518,6 +566,7 @@ npx tsx --env-file=.env example/test-pty-comprehensive.ts
518
566
  ```
519
567
 
520
568
  Available examples:
569
+
521
570
  - `test-pty-comprehensive.ts` - Full PTY testing (9 scenarios)
522
571
  - `test-sandbox-exec.ts` - Code execution examples
523
572
  - `test-sandbox-fs.ts` - File system operations
@@ -559,13 +608,14 @@ export API_KEY="your-api-key"
559
608
  ### "Sandbox creation failed"
560
609
 
561
610
  Ensure your sandbox parameters are valid:
611
+
562
612
  - `mem`: minimum 1024 MB
563
613
  - `cpu`: minimum 1 core
564
614
 
565
615
  ```typescript
566
- const sandbox = await vr.createSandbox({
567
- mem: 1024, // At least 1GB
568
- cpu: 1 // At least 1 core
616
+ const sandbox = await vr.createSandbox({
617
+ mem: 1024, // At least 1GB
618
+ cpu: 1, // At least 1 core
569
619
  });
570
620
  ```
571
621
 
@@ -576,12 +626,12 @@ Increase timeout for slow systems:
576
626
  ```typescript
577
627
  const pty = await sandbox.pty.connect({
578
628
  sessionId,
579
- onData: (data) => console.log(data)
629
+ onData: (data) => console.log(data),
580
630
  });
581
631
 
582
632
  // For runCommand
583
- const output = await pty.runCommand('slow-command', {
584
- timeout: 30000 // 30 seconds
633
+ const output = await pty.runCommand("slow-command", {
634
+ timeout: 30000, // 30 seconds
585
635
  });
586
636
  ```
587
637
 
@@ -591,16 +641,17 @@ Check the file path:
591
641
 
592
642
  ```typescript
593
643
  // List files to verify path
594
- const files = await sandbox.fs.listFiles('/app');
644
+ const files = await sandbox.fs.listFiles("/app");
595
645
  console.log(files.data?.files);
596
646
 
597
647
  // Then access specific file
598
- const content = await sandbox.fs.readFile('/app/file.txt');
648
+ const content = await sandbox.fs.readFile("/app/file.txt");
599
649
  ```
600
650
 
601
651
  ## API Documentation
602
652
 
603
653
  Full API documentation is available at:
654
+
604
655
  - [OpenAPI Spec](./openapi.yml)
605
656
  - [API Docs](./src/api-client/docs/)
606
657
 
@@ -621,11 +672,13 @@ ISC License - See LICENSE file for details
621
672
  ## Changelog
622
673
 
623
674
  ### v0.0.2
675
+
624
676
  - Fixed PTY session response field mapping
625
677
  - Added fallback logic for empty sessionId
626
678
  - Improved error handling and validation
627
679
 
628
680
  ### v0.0.1
681
+
629
682
  - Initial release
630
683
  - Sandbox management
631
684
  - File operations
@@ -0,0 +1,77 @@
1
+ import { Configuration } from './api-client/index.js';
2
+ export type SupportedLanguage = 'python' | 'javascript' | 'node' | 'bash' | 'go' | 'ruby' | 'java' | 'csharp';
3
+ export interface CodeExecutionOptions {
4
+ timeout?: number;
5
+ cwd?: string;
6
+ env?: Record<string, string>;
7
+ }
8
+ export interface CodeExecutionResult {
9
+ success: boolean;
10
+ output: string;
11
+ error?: string;
12
+ exitCode?: number;
13
+ }
14
+ /**
15
+ * CodeInterpreter provides a simple API to execute code in various languages
16
+ * over a PTY session, similar to e2b or Daytona
17
+ */
18
+ export declare class CodeInterpreter {
19
+ private sandboxId;
20
+ private config;
21
+ private ptySession;
22
+ private currentLanguage;
23
+ private isInitialized;
24
+ private readonly languageConfigs;
25
+ /**
26
+ * @internal
27
+ */
28
+ constructor(sandboxId: string, config: Configuration);
29
+ /**
30
+ * Initialize the code interpreter with a specific language
31
+ * @param language The programming language to use
32
+ * @param sessionId Optional existing PTY session ID
33
+ */
34
+ initialize(language: SupportedLanguage, sessionId?: string): Promise<void>;
35
+ /**
36
+ * Execute code in the initialized interpreter
37
+ * @param code The code to execute
38
+ * @param options Execution options
39
+ * @returns The execution result
40
+ */
41
+ execute(code: string, options?: CodeExecutionOptions): Promise<CodeExecutionResult>;
42
+ /**
43
+ * Execute multiple code snippets sequentially
44
+ * @param codeSnippets Array of code snippets to execute
45
+ * @param options Execution options
46
+ * @returns Array of execution results
47
+ */
48
+ executeMultiple(codeSnippets: string[], options?: CodeExecutionOptions): Promise<CodeExecutionResult[]>;
49
+ /**
50
+ * Execute code from a file
51
+ * @param filePath Path to the file containing code
52
+ * @param options Execution options
53
+ * @returns The execution result
54
+ */
55
+ executeFile(filePath: string, options?: CodeExecutionOptions): Promise<CodeExecutionResult>;
56
+ /**
57
+ * Get the current language
58
+ */
59
+ getCurrentLanguage(): SupportedLanguage | null;
60
+ /**
61
+ * Check if interpreter is initialized
62
+ */
63
+ isReady(): boolean;
64
+ /**
65
+ * Clean up the interpreter session
66
+ */
67
+ close(): Promise<void>;
68
+ /**
69
+ * Reset the interpreter for a new language
70
+ */
71
+ reset(newLanguage?: SupportedLanguage): Promise<void>;
72
+ /**
73
+ * Clean output by removing the input command and extra prompts
74
+ */
75
+ private cleanOutput;
76
+ }
77
+ //# sourceMappingURL=CodeInterpreter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodeInterpreter.d.ts","sourceRoot":"","sources":["../src/CodeInterpreter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE9G,MAAM,WAAW,oBAAoB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAWD;;;GAGG;AACH,qBAAa,eAAe;IAoEpB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,MAAM;IApElB,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,aAAa,CAAkB;IAEvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAyD9B;IAEF;;OAEG;gBAES,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,aAAa;IAGjC;;;;OAIG;IACG,UAAU,CAAC,QAAQ,EAAE,iBAAiB,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA2ChF;;;;;OAKG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA4F7F;;;;;OAKG;IACG,eAAe,CACjB,YAAY,EAAE,MAAM,EAAE,EACtB,OAAO,GAAE,oBAAyB,GACnC,OAAO,CAAC,mBAAmB,EAAE,CAAC;IAQjC;;;;;OAKG;IACG,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAuBrG;;OAEG;IACH,kBAAkB,IAAI,iBAAiB,GAAG,IAAI;IAI9C;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B;;OAEG;IACG,KAAK,CAAC,WAAW,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3D;;OAEG;IACH,OAAO,CAAC,WAAW;CA2DtB"}