@computesdk/e2b 1.0.0 → 1.1.1
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.
- package/README.md +350 -124
- package/dist/index.d.mts +17 -16
- package/dist/index.d.ts +17 -16
- package/dist/index.js +271 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +271 -102
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @computesdk/e2b
|
|
2
2
|
|
|
3
|
-
E2B provider for ComputeSDK - Execute
|
|
3
|
+
E2B provider for ComputeSDK - Execute code in secure, isolated E2B sandboxes with full filesystem and terminal support.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -19,223 +19,449 @@ export E2B_API_KEY=e2b_your_api_key_here
|
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
|
-
###
|
|
22
|
+
### With ComputeSDK
|
|
23
23
|
|
|
24
24
|
```typescript
|
|
25
|
+
import { compute } from 'computesdk';
|
|
25
26
|
import { e2b } from '@computesdk/e2b';
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
// Set as default provider
|
|
29
|
+
compute.setConfig({
|
|
30
|
+
provider: e2b({ apiKey: process.env.E2B_API_KEY })
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Create sandbox
|
|
34
|
+
const sandbox = await compute.sandbox.create({});
|
|
28
35
|
|
|
29
36
|
// Execute Python code
|
|
30
|
-
const result = await
|
|
31
|
-
|
|
37
|
+
const result = await sandbox.runCode(`
|
|
38
|
+
import pandas as pd
|
|
39
|
+
import numpy as np
|
|
40
|
+
|
|
41
|
+
data = {'A': [1, 2, 3], 'B': [4, 5, 6]}
|
|
42
|
+
df = pd.DataFrame(data)
|
|
43
|
+
print(df)
|
|
44
|
+
print(f"Sum: {df.sum().sum()}")
|
|
45
|
+
`);
|
|
46
|
+
|
|
47
|
+
console.log(result.stdout);
|
|
48
|
+
// Output:
|
|
49
|
+
// A B
|
|
50
|
+
// 0 1 4
|
|
51
|
+
// 1 2 5
|
|
52
|
+
// 2 3 6
|
|
53
|
+
// Sum: 21
|
|
54
|
+
|
|
55
|
+
// Clean up
|
|
56
|
+
await compute.sandbox.destroy(sandbox.sandboxId);
|
|
32
57
|
```
|
|
33
58
|
|
|
34
|
-
###
|
|
59
|
+
### Direct Usage
|
|
35
60
|
|
|
36
61
|
```typescript
|
|
37
|
-
import { executeSandbox } from 'computesdk';
|
|
38
62
|
import { e2b } from '@computesdk/e2b';
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
// Create provider
|
|
65
|
+
const provider = e2b({
|
|
66
|
+
apiKey: 'e2b_your_api_key',
|
|
67
|
+
timeout: 600000 // 10 minutes
|
|
44
68
|
});
|
|
69
|
+
|
|
70
|
+
// Use with compute singleton
|
|
71
|
+
const sandbox = await compute.sandbox.create({ provider });
|
|
45
72
|
```
|
|
46
73
|
|
|
47
|
-
|
|
74
|
+
## Configuration
|
|
48
75
|
|
|
49
|
-
|
|
50
|
-
import { e2b } from '@computesdk/e2b';
|
|
76
|
+
### Environment Variables
|
|
51
77
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
runtime: 'python' // Only Python is supported
|
|
55
|
-
});
|
|
78
|
+
```bash
|
|
79
|
+
export E2B_API_KEY=e2b_your_api_key_here
|
|
56
80
|
```
|
|
57
81
|
|
|
58
|
-
|
|
82
|
+
### Configuration Options
|
|
59
83
|
|
|
60
|
-
|
|
84
|
+
```typescript
|
|
85
|
+
interface E2BConfig {
|
|
86
|
+
/** E2B API key - if not provided, will use E2B_API_KEY env var */
|
|
87
|
+
apiKey?: string;
|
|
88
|
+
/** Default runtime environment */
|
|
89
|
+
runtime?: 'python' | 'node';
|
|
90
|
+
/** Execution timeout in milliseconds */
|
|
91
|
+
timeout?: number;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
61
94
|
|
|
62
|
-
|
|
95
|
+
## Features
|
|
63
96
|
|
|
64
|
-
|
|
97
|
+
- ✅ **Code Execution** - Python and Node.js runtime support
|
|
98
|
+
- ✅ **Command Execution** - Run shell commands in sandbox
|
|
99
|
+
- ✅ **Filesystem Operations** - Full file system access via E2B API
|
|
100
|
+
- ✅ **Terminal Support** - Interactive PTY terminals
|
|
101
|
+
- ✅ **Auto Runtime Detection** - Automatically detects Python vs Node.js
|
|
102
|
+
- ✅ **Data Science Ready** - Pre-installed pandas, numpy, matplotlib, etc.
|
|
65
103
|
|
|
66
|
-
|
|
67
|
-
- `timeout`: Execution timeout in milliseconds (default: 300000)
|
|
68
|
-
- `runtime`: Runtime environment - only `'python'` is supported
|
|
104
|
+
## API Reference
|
|
69
105
|
|
|
70
|
-
|
|
106
|
+
### Code Execution
|
|
71
107
|
|
|
72
|
-
|
|
108
|
+
```typescript
|
|
109
|
+
// Execute Python code
|
|
110
|
+
const result = await sandbox.runCode(`
|
|
111
|
+
import json
|
|
112
|
+
data = {"message": "Hello from Python"}
|
|
113
|
+
print(json.dumps(data))
|
|
114
|
+
`, 'python');
|
|
115
|
+
|
|
116
|
+
// Execute Node.js code
|
|
117
|
+
const result = await sandbox.runCode(`
|
|
118
|
+
const data = { message: "Hello from Node.js" };
|
|
119
|
+
console.log(JSON.stringify(data));
|
|
120
|
+
`, 'node');
|
|
121
|
+
|
|
122
|
+
// Auto-detection (based on code patterns)
|
|
123
|
+
const result = await sandbox.runCode('print("Auto-detected as Python")');
|
|
124
|
+
```
|
|
73
125
|
|
|
74
|
-
###
|
|
126
|
+
### Command Execution
|
|
75
127
|
|
|
76
|
-
|
|
128
|
+
```typescript
|
|
129
|
+
// List files
|
|
130
|
+
const result = await sandbox.runCommand('ls', ['-la']);
|
|
77
131
|
|
|
78
|
-
|
|
132
|
+
// Install packages
|
|
133
|
+
const result = await sandbox.runCommand('pip', ['install', 'requests']);
|
|
79
134
|
|
|
80
|
-
|
|
81
|
-
const result = await
|
|
82
|
-
// result.stdout: "2"
|
|
83
|
-
// result.stderr: ""
|
|
84
|
-
// result.exitCode: 0
|
|
135
|
+
// Run scripts
|
|
136
|
+
const result = await sandbox.runCommand('python', ['script.py']);
|
|
85
137
|
```
|
|
86
138
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Terminates the E2B sandbox session.
|
|
139
|
+
### Filesystem Operations
|
|
90
140
|
|
|
91
141
|
```typescript
|
|
92
|
-
|
|
93
|
-
|
|
142
|
+
// Write file
|
|
143
|
+
await sandbox.filesystem.writeFile('/tmp/hello.py', 'print("Hello World")');
|
|
94
144
|
|
|
95
|
-
|
|
145
|
+
// Read file
|
|
146
|
+
const content = await sandbox.filesystem.readFile('/tmp/hello.py');
|
|
96
147
|
|
|
97
|
-
|
|
148
|
+
// Create directory
|
|
149
|
+
await sandbox.filesystem.mkdir('/tmp/data');
|
|
98
150
|
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
// info.provider: "e2b"
|
|
102
|
-
// info.runtime: "python"
|
|
103
|
-
// info.status: "running" | "stopped"
|
|
104
|
-
```
|
|
151
|
+
// List directory contents
|
|
152
|
+
const files = await sandbox.filesystem.readdir('/tmp');
|
|
105
153
|
|
|
106
|
-
|
|
154
|
+
// Check if file exists
|
|
155
|
+
const exists = await sandbox.filesystem.exists('/tmp/hello.py');
|
|
107
156
|
|
|
108
|
-
|
|
157
|
+
// Remove file or directory
|
|
158
|
+
await sandbox.filesystem.remove('/tmp/hello.py');
|
|
159
|
+
```
|
|
109
160
|
|
|
110
|
-
###
|
|
161
|
+
### Terminal Operations
|
|
111
162
|
|
|
112
163
|
```typescript
|
|
113
|
-
//
|
|
114
|
-
|
|
164
|
+
// Create terminal
|
|
165
|
+
const terminal = await sandbox.terminal.create({
|
|
166
|
+
command: 'bash',
|
|
167
|
+
cols: 80,
|
|
168
|
+
rows: 24,
|
|
169
|
+
onData: (data: Uint8Array) => {
|
|
170
|
+
const output = new TextDecoder().decode(data);
|
|
171
|
+
console.log('Terminal output:', output);
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Write to terminal
|
|
176
|
+
await terminal.write('echo "Hello Terminal!"\n');
|
|
177
|
+
|
|
178
|
+
// Resize terminal
|
|
179
|
+
await terminal.resize(120, 30);
|
|
115
180
|
|
|
116
|
-
//
|
|
117
|
-
|
|
181
|
+
// Kill terminal
|
|
182
|
+
await terminal.kill();
|
|
118
183
|
|
|
119
|
-
//
|
|
120
|
-
|
|
184
|
+
// List all terminals
|
|
185
|
+
const terminals = await sandbox.terminal.list();
|
|
186
|
+
|
|
187
|
+
// Get terminal by ID
|
|
188
|
+
const existingTerminal = await sandbox.terminal.getById('terminal-id');
|
|
121
189
|
```
|
|
122
190
|
|
|
123
|
-
###
|
|
191
|
+
### Sandbox Management
|
|
124
192
|
|
|
125
193
|
```typescript
|
|
126
|
-
//
|
|
127
|
-
|
|
194
|
+
// Get sandbox info
|
|
195
|
+
const info = await sandbox.getInfo();
|
|
196
|
+
console.log(info.id, info.provider, info.status);
|
|
197
|
+
|
|
198
|
+
// Get existing sandbox (reconnect)
|
|
199
|
+
const existing = await compute.sandbox.getById(provider, 'sandbox-id');
|
|
200
|
+
|
|
201
|
+
// Destroy sandbox
|
|
202
|
+
await compute.sandbox.destroy(provider, 'sandbox-id');
|
|
203
|
+
|
|
204
|
+
// Note: E2B doesn't support listing all sandboxes
|
|
205
|
+
// Each sandbox is managed individually
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Runtime Detection
|
|
209
|
+
|
|
210
|
+
The provider automatically detects the runtime based on code patterns:
|
|
128
211
|
|
|
129
|
-
|
|
130
|
-
|
|
212
|
+
**Python indicators:**
|
|
213
|
+
- `print(` statements
|
|
214
|
+
- `import` statements
|
|
215
|
+
- `def` function definitions
|
|
216
|
+
- Python-specific syntax (`f"`, `__`, etc.)
|
|
131
217
|
|
|
132
|
-
|
|
133
|
-
|
|
218
|
+
**Default:** Node.js for all other cases
|
|
219
|
+
|
|
220
|
+
## Error Handling
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
try {
|
|
224
|
+
const result = await sandbox.runCode('invalid code');
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error.message.includes('Missing E2B API key')) {
|
|
227
|
+
console.error('Set E2B_API_KEY environment variable');
|
|
228
|
+
} else if (error.message.includes('Invalid E2B API key format')) {
|
|
229
|
+
console.error('E2B API keys should start with "e2b_"');
|
|
230
|
+
} else if (error.message.includes('authentication failed')) {
|
|
231
|
+
console.error('Check your E2B API key');
|
|
232
|
+
} else if (error.message.includes('quota exceeded')) {
|
|
233
|
+
console.error('E2B usage limits reached');
|
|
234
|
+
} else if (error.message.includes('Syntax error')) {
|
|
235
|
+
console.error('Code has syntax errors');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
134
238
|
```
|
|
135
239
|
|
|
136
|
-
|
|
240
|
+
## Web Framework Integration
|
|
241
|
+
|
|
242
|
+
Use with web frameworks via the request handler:
|
|
137
243
|
|
|
138
244
|
```typescript
|
|
139
|
-
|
|
140
|
-
|
|
245
|
+
import { handleComputeRequest } from 'computesdk';
|
|
246
|
+
import { e2b } from '@computesdk/e2b';
|
|
247
|
+
|
|
248
|
+
export async function POST(request: Request) {
|
|
249
|
+
return handleComputeRequest({
|
|
250
|
+
request,
|
|
251
|
+
provider: e2b({ apiKey: process.env.E2B_API_KEY })
|
|
252
|
+
});
|
|
253
|
+
}
|
|
141
254
|
```
|
|
142
255
|
|
|
143
256
|
## Examples
|
|
144
257
|
|
|
145
|
-
### Data
|
|
258
|
+
### Data Science Workflow
|
|
146
259
|
|
|
147
260
|
```typescript
|
|
148
|
-
|
|
261
|
+
const sandbox = await compute.sandbox.create({});
|
|
149
262
|
|
|
150
|
-
|
|
263
|
+
// Create project structure
|
|
264
|
+
await sandbox.filesystem.mkdir('/analysis');
|
|
265
|
+
await sandbox.filesystem.mkdir('/analysis/data');
|
|
266
|
+
await sandbox.filesystem.mkdir('/analysis/output');
|
|
151
267
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
268
|
+
// Write input data
|
|
269
|
+
const csvData = `name,age,city
|
|
270
|
+
Alice,25,New York
|
|
271
|
+
Bob,30,San Francisco
|
|
272
|
+
Charlie,35,Chicago`;
|
|
155
273
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
274
|
+
await sandbox.filesystem.writeFile('/analysis/data/people.csv', csvData);
|
|
275
|
+
|
|
276
|
+
// Process data with Python
|
|
277
|
+
const result = await sandbox.runCode(`
|
|
278
|
+
import pandas as pd
|
|
279
|
+
import matplotlib.pyplot as plt
|
|
159
280
|
|
|
160
|
-
|
|
281
|
+
# Read data
|
|
282
|
+
df = pd.read_csv('/analysis/data/people.csv')
|
|
283
|
+
print("Data loaded:")
|
|
161
284
|
print(df)
|
|
162
|
-
print(f"Sum of column A: {df['A'].sum()}")
|
|
163
|
-
`;
|
|
164
285
|
|
|
165
|
-
|
|
286
|
+
# Calculate statistics
|
|
287
|
+
avg_age = df['age'].mean()
|
|
288
|
+
print(f"\\nAverage age: {avg_age}")
|
|
289
|
+
|
|
290
|
+
# Create visualization
|
|
291
|
+
plt.figure(figsize=(8, 6))
|
|
292
|
+
plt.bar(df['name'], df['age'])
|
|
293
|
+
plt.title('Age by Person')
|
|
294
|
+
plt.xlabel('Name')
|
|
295
|
+
plt.ylabel('Age')
|
|
296
|
+
plt.savefig('/analysis/output/age_chart.png')
|
|
297
|
+
print("\\nChart saved to /analysis/output/age_chart.png")
|
|
298
|
+
|
|
299
|
+
# Save results
|
|
300
|
+
results = {
|
|
301
|
+
'total_people': len(df),
|
|
302
|
+
'average_age': avg_age,
|
|
303
|
+
'cities': df['city'].unique().tolist()
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
import json
|
|
307
|
+
with open('/analysis/output/results.json', 'w') as f:
|
|
308
|
+
json.dump(results, f, indent=2)
|
|
309
|
+
|
|
310
|
+
print("Results saved!")
|
|
311
|
+
`);
|
|
312
|
+
|
|
166
313
|
console.log(result.stdout);
|
|
314
|
+
|
|
315
|
+
// Read the results
|
|
316
|
+
const results = await sandbox.filesystem.readFile('/analysis/output/results.json');
|
|
317
|
+
console.log('Analysis results:', JSON.parse(results));
|
|
318
|
+
|
|
319
|
+
// Check if chart was created
|
|
320
|
+
const chartExists = await sandbox.filesystem.exists('/analysis/output/age_chart.png');
|
|
321
|
+
console.log('Chart created:', chartExists);
|
|
167
322
|
```
|
|
168
323
|
|
|
169
|
-
###
|
|
324
|
+
### Interactive Terminal Session
|
|
170
325
|
|
|
171
326
|
```typescript
|
|
172
|
-
|
|
327
|
+
const sandbox = await compute.sandbox.create({});
|
|
328
|
+
|
|
329
|
+
// Create interactive Python terminal
|
|
330
|
+
const terminal = await sandbox.terminal.create({
|
|
331
|
+
command: 'python3',
|
|
332
|
+
cols: 80,
|
|
333
|
+
rows: 24,
|
|
334
|
+
onData: (data: Uint8Array) => {
|
|
335
|
+
const output = new TextDecoder().decode(data);
|
|
336
|
+
process.stdout.write(output); // Forward to console
|
|
337
|
+
}
|
|
338
|
+
});
|
|
173
339
|
|
|
174
|
-
|
|
340
|
+
// Send Python commands
|
|
341
|
+
await terminal.write('import numpy as np\n');
|
|
342
|
+
await terminal.write('import pandas as pd\n');
|
|
343
|
+
await terminal.write('print("Libraries loaded!")\n');
|
|
344
|
+
await terminal.write('data = np.array([1, 2, 3, 4, 5])\n');
|
|
345
|
+
await terminal.write('print(f"Mean: {data.mean()}")\n');
|
|
346
|
+
await terminal.write('exit()\n');
|
|
175
347
|
|
|
176
|
-
|
|
177
|
-
|
|
348
|
+
// Wait for commands to execute
|
|
349
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
350
|
+
|
|
351
|
+
await terminal.kill();
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Machine Learning Pipeline
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
const sandbox = await compute.sandbox.create({
|
|
358
|
+
options: { timeout: 600000 } // 10 minutes for ML tasks
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
// Create ML project structure
|
|
362
|
+
await sandbox.filesystem.mkdir('/ml-project');
|
|
363
|
+
await sandbox.filesystem.mkdir('/ml-project/data');
|
|
364
|
+
await sandbox.filesystem.mkdir('/ml-project/models');
|
|
365
|
+
|
|
366
|
+
// Generate and process data
|
|
367
|
+
const result = await sandbox.runCode(`
|
|
178
368
|
import numpy as np
|
|
369
|
+
import pandas as pd
|
|
370
|
+
from sklearn.model_selection import train_test_split
|
|
371
|
+
from sklearn.linear_model import LinearRegression
|
|
372
|
+
from sklearn.metrics import mean_squared_error, r2_score
|
|
373
|
+
import joblib
|
|
374
|
+
|
|
375
|
+
# Generate sample dataset
|
|
376
|
+
np.random.seed(42)
|
|
377
|
+
X = np.random.randn(1000, 5)
|
|
378
|
+
y = X.sum(axis=1) + np.random.randn(1000) * 0.1
|
|
379
|
+
|
|
380
|
+
# Create DataFrame
|
|
381
|
+
feature_names = [f'feature_{i}' for i in range(5)]
|
|
382
|
+
df = pd.DataFrame(X, columns=feature_names)
|
|
383
|
+
df['target'] = y
|
|
384
|
+
|
|
385
|
+
print(f"Dataset shape: {df.shape}")
|
|
386
|
+
print("\\nDataset info:")
|
|
387
|
+
print(df.describe())
|
|
179
388
|
|
|
180
|
-
#
|
|
181
|
-
|
|
182
|
-
|
|
389
|
+
# Save dataset
|
|
390
|
+
df.to_csv('/ml-project/data/dataset.csv', index=False)
|
|
391
|
+
print("\\nDataset saved to /ml-project/data/dataset.csv")
|
|
392
|
+
|
|
393
|
+
# Split data
|
|
394
|
+
X_train, X_test, y_train, y_test = train_test_split(
|
|
395
|
+
df[feature_names], df['target'], test_size=0.2, random_state=42
|
|
396
|
+
)
|
|
183
397
|
|
|
184
398
|
# Train model
|
|
185
399
|
model = LinearRegression()
|
|
186
|
-
model.fit(
|
|
400
|
+
model.fit(X_train, y_train)
|
|
187
401
|
|
|
188
|
-
# Make
|
|
189
|
-
|
|
190
|
-
print(f"Prediction for x=5: {prediction[0]}")
|
|
191
|
-
`;
|
|
402
|
+
# Make predictions
|
|
403
|
+
y_pred = model.predict(X_test)
|
|
192
404
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
405
|
+
# Evaluate
|
|
406
|
+
mse = mean_squared_error(y_test, y_pred)
|
|
407
|
+
r2 = r2_score(y_test, y_pred)
|
|
196
408
|
|
|
197
|
-
|
|
409
|
+
print(f"\\nModel Performance:")
|
|
410
|
+
print(f"MSE: {mse:.4f}")
|
|
411
|
+
print(f"R²: {r2:.4f}")
|
|
198
412
|
|
|
199
|
-
|
|
200
|
-
|
|
413
|
+
# Save model
|
|
414
|
+
joblib.dump(model, '/ml-project/models/linear_model.pkl')
|
|
415
|
+
print("\\nModel saved to /ml-project/models/linear_model.pkl")
|
|
201
416
|
|
|
202
|
-
|
|
417
|
+
# Save results
|
|
418
|
+
results = {
|
|
419
|
+
'mse': mse,
|
|
420
|
+
'r2': r2,
|
|
421
|
+
'feature_importance': dict(zip(feature_names, model.coef_)),
|
|
422
|
+
'intercept': model.intercept_
|
|
423
|
+
}
|
|
203
424
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
f.write('Hello from E2B sandbox!')
|
|
425
|
+
import json
|
|
426
|
+
with open('/ml-project/results.json', 'w') as f:
|
|
427
|
+
json.dump(results, f, indent=2)
|
|
208
428
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
content = f.read()
|
|
212
|
-
print(f"File content: {content}")
|
|
213
|
-
`;
|
|
429
|
+
print("Results saved!")
|
|
430
|
+
`);
|
|
214
431
|
|
|
215
|
-
const result = await provider.doExecute(code);
|
|
216
432
|
console.log(result.stdout);
|
|
217
|
-
```
|
|
218
433
|
|
|
219
|
-
|
|
434
|
+
// Read the results
|
|
435
|
+
const results = await sandbox.filesystem.readFile('/ml-project/results.json');
|
|
436
|
+
console.log('ML Results:', JSON.parse(results));
|
|
220
437
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
438
|
+
// Verify model file exists
|
|
439
|
+
const modelExists = await sandbox.filesystem.exists('/ml-project/models/linear_model.pkl');
|
|
440
|
+
console.log('Model saved:', modelExists);
|
|
441
|
+
```
|
|
225
442
|
|
|
226
443
|
## Best Practices
|
|
227
444
|
|
|
228
|
-
1. **
|
|
229
|
-
2. **
|
|
230
|
-
3. **
|
|
231
|
-
4. **
|
|
232
|
-
5. **
|
|
445
|
+
1. **Resource Management**: Always destroy sandboxes when done to free resources
|
|
446
|
+
2. **Error Handling**: Use try-catch blocks for robust error handling
|
|
447
|
+
3. **Timeouts**: Set appropriate timeouts for long-running tasks
|
|
448
|
+
4. **File Organization**: Use the filesystem API to organize project files
|
|
449
|
+
5. **Terminal Sessions**: Clean up terminal sessions with `terminal.kill()`
|
|
450
|
+
6. **API Key Security**: Never commit API keys to version control
|
|
451
|
+
|
|
452
|
+
## Limitations
|
|
453
|
+
|
|
454
|
+
- **Sandbox Listing**: E2B doesn't support listing all sandboxes (each is managed individually)
|
|
455
|
+
- **Memory Limits**: Subject to E2B sandbox memory constraints
|
|
456
|
+
- **Network Access**: Limited outbound network access
|
|
457
|
+
- **File Persistence**: Files are not persisted between sandbox sessions
|
|
458
|
+
- **Execution Time**: Subject to E2B timeout limits
|
|
233
459
|
|
|
234
460
|
## Support
|
|
235
461
|
|
|
236
|
-
- E2B Documentation
|
|
237
|
-
- ComputeSDK Issues
|
|
238
|
-
-
|
|
462
|
+
- [E2B Documentation](https://e2b.dev/docs)
|
|
463
|
+
- [ComputeSDK Issues](https://github.com/computesdk/computesdk/issues)
|
|
464
|
+
- [E2B Support](https://e2b.dev/support)
|
|
239
465
|
|
|
240
466
|
## License
|
|
241
467
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as computesdk from 'computesdk';
|
|
2
|
+
import { Runtime } from 'computesdk';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
doExecute(code: string, runtime?: Runtime): Promise<ExecutionResult>;
|
|
14
|
-
doKill(): Promise<void>;
|
|
15
|
-
doGetInfo(): Promise<SandboxInfo>;
|
|
4
|
+
/**
|
|
5
|
+
* E2B-specific configuration options
|
|
6
|
+
*/
|
|
7
|
+
interface E2BConfig {
|
|
8
|
+
/** E2B API key - if not provided, will fallback to E2B_API_KEY environment variable */
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
/** Default runtime environment */
|
|
11
|
+
runtime?: Runtime;
|
|
12
|
+
/** Execution timeout in milliseconds */
|
|
13
|
+
timeout?: number;
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Create an E2B provider instance using the factory pattern
|
|
17
|
+
*/
|
|
18
|
+
declare const e2b: (config: E2BConfig) => computesdk.Provider;
|
|
18
19
|
|
|
19
|
-
export {
|
|
20
|
+
export { type E2BConfig, e2b };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as computesdk from 'computesdk';
|
|
2
|
+
import { Runtime } from 'computesdk';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
doExecute(code: string, runtime?: Runtime): Promise<ExecutionResult>;
|
|
14
|
-
doKill(): Promise<void>;
|
|
15
|
-
doGetInfo(): Promise<SandboxInfo>;
|
|
4
|
+
/**
|
|
5
|
+
* E2B-specific configuration options
|
|
6
|
+
*/
|
|
7
|
+
interface E2BConfig {
|
|
8
|
+
/** E2B API key - if not provided, will fallback to E2B_API_KEY environment variable */
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
/** Default runtime environment */
|
|
11
|
+
runtime?: Runtime;
|
|
12
|
+
/** Execution timeout in milliseconds */
|
|
13
|
+
timeout?: number;
|
|
16
14
|
}
|
|
17
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Create an E2B provider instance using the factory pattern
|
|
17
|
+
*/
|
|
18
|
+
declare const e2b: (config: E2BConfig) => computesdk.Provider;
|
|
18
19
|
|
|
19
|
-
export {
|
|
20
|
+
export { type E2BConfig, e2b };
|