computesdk 1.1.0 → 1.2.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.
- package/README.md +434 -547
- package/dist/index.d.mts +68 -259
- package/dist/index.d.ts +68 -259
- package/dist/index.js +325 -710
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +322 -708
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://www.computesdk.com/_astro/hv_main_logo_light.CpYMD9-V.svg" alt="ComputeSDK" width="300" />
|
|
3
|
+
</div>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<div align="center">
|
|
6
|
+
<strong>A free and open-source toolkit for running other people's code in your applications.</strong>
|
|
7
|
+
</div>
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
<div align="center">
|
|
10
|
+
|
|
11
|
+
[](https://badge.fury.io/js/computesdk)
|
|
12
|
+
[](https://www.typescriptlang.org/)
|
|
13
|
+
[](https://opensource.org/licenses/MIT)
|
|
14
|
+
[](https://computesdk.com)
|
|
15
|
+
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## What is ComputeSDK?
|
|
21
|
+
|
|
22
|
+
ComputeSDK is a free and open-source toolkit for running other people's code in your applications. Think of it as the "AI SDK for compute" - providing a consistent TypeScript interface whether you're using E2B, Vercel, or Daytona.
|
|
23
|
+
|
|
24
|
+
**Why ComputeSDK?**
|
|
25
|
+
- 🔄 **Provider-agnostic** - Switch between E2B, Vercel, Daytona and more (coming soon) without code changes
|
|
26
|
+
- 🛡️ **Security-first** - Isolated sandboxes protect your infrastructure
|
|
27
|
+
- ⚡ **Developer experience** - Simple, TypeScript-native API
|
|
28
|
+
- 🌍 **Production-ready** - Used by teams building the next generation of developer tools
|
|
29
|
+
|
|
30
|
+
**Perfect for building:**
|
|
31
|
+
- **Code execution platforms** - Run user-submitted code safely
|
|
32
|
+
- **Educational tools** - Interactive coding environments
|
|
33
|
+
- **Data analysis applications** - Process code with full filesystem access
|
|
34
|
+
- **AI-powered development tools** - Let AI agents write and execute code
|
|
35
|
+
- **Testing & CI/CD systems** - Isolated test environments
|
|
6
36
|
|
|
7
37
|
## Features
|
|
8
38
|
|
|
@@ -10,256 +40,207 @@ Similar to how Vercel's AI SDK abstracts different LLM providers, ComputeSDK abs
|
|
|
10
40
|
- 📁 **Filesystem operations** - Read, write, create directories across providers
|
|
11
41
|
- 🖥️ **Terminal support** - Interactive PTY terminals (E2B)
|
|
12
42
|
- ⚡ **Command execution** - Run shell commands directly
|
|
13
|
-
- 🔄 **Auto-detection** - Automatically selects providers based on environment variables
|
|
14
43
|
- 🛡️ **Type-safe** - Full TypeScript support with comprehensive error handling
|
|
15
44
|
- 📦 **Modular** - Install only the providers you need
|
|
16
45
|
- 🔧 **Extensible** - Easy to add custom providers
|
|
46
|
+
- 🌐 **Web Framework Integration** - Built-in request handlers for Next.js, Nuxt, SvelteKit, etc.
|
|
47
|
+
- 🎨 **Frontend Integration** - Client-side hooks and utilities via @computesdk/ui
|
|
17
48
|
|
|
18
|
-
##
|
|
19
|
-
|
|
20
|
-
| Provider | Code Execution | Filesystem | Terminal | Use Cases |
|
|
21
|
-
|----------|----------------|------------|----------|-----------|
|
|
22
|
-
| **E2B** | Python | ✅ Full | ✅ PTY | Data science, AI/ML, interactive development |
|
|
23
|
-
| **Vercel** | Node.js, Python | ✅ Full | ❌ | Web apps, APIs, serverless functions |
|
|
24
|
-
| **Daytona** | Python, Node.js | ✅ Full | ❌ | Development workspaces, custom environments |
|
|
25
|
-
|
|
26
|
-
## Installation
|
|
49
|
+
## Get Started in 30 Seconds
|
|
27
50
|
|
|
28
51
|
```bash
|
|
29
|
-
#
|
|
52
|
+
# Install the core SDK
|
|
30
53
|
npm install computesdk
|
|
31
54
|
|
|
32
|
-
#
|
|
33
|
-
npm install @computesdk/e2b #
|
|
34
|
-
npm install @computesdk/vercel #
|
|
35
|
-
npm install @computesdk/daytona #
|
|
55
|
+
# Add your preferred provider
|
|
56
|
+
npm install @computesdk/e2b # For data science and Python
|
|
57
|
+
npm install @computesdk/vercel # For web-scale Node.js/Python
|
|
58
|
+
npm install @computesdk/daytona # For development workspaces
|
|
59
|
+
|
|
60
|
+
# Frontend integration (optional)
|
|
61
|
+
npm install @computesdk/ui # React hooks and utilities
|
|
36
62
|
```
|
|
37
63
|
|
|
38
|
-
|
|
64
|
+
Set your environment variables and you're ready to go:
|
|
39
65
|
|
|
40
|
-
|
|
66
|
+
```bash
|
|
67
|
+
export E2B_API_KEY=your_api_key
|
|
68
|
+
# or VERCEL_TOKEN=your_token
|
|
69
|
+
# or DAYTONA_API_KEY=your_key
|
|
70
|
+
```
|
|
41
71
|
|
|
42
|
-
|
|
72
|
+
## Quick Start
|
|
43
73
|
|
|
44
74
|
```typescript
|
|
45
|
-
import {
|
|
75
|
+
import { compute } from 'computesdk';
|
|
76
|
+
import { e2b } from '@computesdk/e2b';
|
|
46
77
|
|
|
47
|
-
//
|
|
48
|
-
|
|
78
|
+
// Set default provider
|
|
79
|
+
compute.setConfig({
|
|
80
|
+
provider: e2b({ apiKey: process.env.E2B_API_KEY })
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Create a sandbox
|
|
84
|
+
const sandbox = await compute.sandbox.create({});
|
|
49
85
|
|
|
50
|
-
|
|
86
|
+
// Execute code
|
|
87
|
+
const result = await sandbox.runCode('print("Hello World!")');
|
|
51
88
|
console.log(result.stdout); // "Hello World!"
|
|
52
89
|
|
|
53
|
-
|
|
90
|
+
// Clean up
|
|
91
|
+
await compute.sandbox.destroy(sandbox.sandboxId);
|
|
54
92
|
```
|
|
55
93
|
|
|
56
|
-
|
|
94
|
+
## Provider Setup
|
|
57
95
|
|
|
58
|
-
|
|
59
|
-
import { executeSandbox } from 'computesdk';
|
|
60
|
-
import { e2b } from '@computesdk/e2b';
|
|
96
|
+
### E2B - Full Development Environment
|
|
61
97
|
|
|
62
|
-
|
|
63
|
-
const result = await executeSandbox({
|
|
64
|
-
sandbox: e2b(),
|
|
65
|
-
code: 'print("Hello from E2B!")',
|
|
66
|
-
runtime: 'python'
|
|
67
|
-
});
|
|
98
|
+
E2B provides full filesystem and terminal support:
|
|
68
99
|
|
|
69
|
-
|
|
100
|
+
```bash
|
|
101
|
+
export E2B_API_KEY=e2b_your_api_key_here
|
|
70
102
|
```
|
|
71
103
|
|
|
72
|
-
|
|
104
|
+
```typescript
|
|
105
|
+
import { compute } from 'computesdk';
|
|
106
|
+
import { e2b } from '@computesdk/e2b';
|
|
73
107
|
|
|
74
|
-
|
|
108
|
+
compute.setConfig({
|
|
109
|
+
provider: e2b({ apiKey: process.env.E2B_API_KEY })
|
|
110
|
+
});
|
|
75
111
|
|
|
76
|
-
|
|
77
|
-
import { ComputeSDK, FilesystemComputeSandbox, TerminalComputeSandbox } from 'computesdk';
|
|
112
|
+
const sandbox = await compute.sandbox.create({});
|
|
78
113
|
|
|
79
|
-
|
|
114
|
+
// Execute Python with data science libraries
|
|
115
|
+
const result = await sandbox.runCode(`
|
|
116
|
+
import pandas as pd
|
|
117
|
+
import numpy as np
|
|
80
118
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
await fsSandbox.filesystem.writeFile('/tmp/data.txt', 'Hello World!');
|
|
87
|
-
const content = await fsSandbox.filesystem.readFile('/tmp/data.txt');
|
|
88
|
-
console.log(content); // "Hello World!"
|
|
89
|
-
}
|
|
119
|
+
data = {'A': [1, 2, 3], 'B': [4, 5, 6]}
|
|
120
|
+
df = pd.DataFrame(data)
|
|
121
|
+
print(df)
|
|
122
|
+
print(f"Sum: {df.sum().sum()}")
|
|
123
|
+
`);
|
|
90
124
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
cols: 80,
|
|
98
|
-
rows: 24
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
await terminal.write('echo "Interactive terminal!"\n');
|
|
102
|
-
await terminal.kill();
|
|
103
|
-
}
|
|
125
|
+
// Interactive terminal support
|
|
126
|
+
const terminal = await sandbox.terminal.create({
|
|
127
|
+
command: 'bash',
|
|
128
|
+
cols: 80,
|
|
129
|
+
rows: 24
|
|
130
|
+
});
|
|
104
131
|
```
|
|
105
132
|
|
|
106
|
-
|
|
133
|
+
### Vercel - Scalable Serverless Execution
|
|
107
134
|
|
|
108
|
-
|
|
135
|
+
Vercel provides reliable execution with filesystem support:
|
|
109
136
|
|
|
110
|
-
### E2B (Full Features)
|
|
111
137
|
```bash
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Get your API key from [e2b.dev](https://e2b.dev/)
|
|
138
|
+
# Method 1: OIDC Token (Recommended)
|
|
139
|
+
vercel env pull # Downloads VERCEL_OIDC_TOKEN
|
|
115
140
|
|
|
116
|
-
|
|
117
|
-
```bash
|
|
141
|
+
# Method 2: Traditional
|
|
118
142
|
export VERCEL_TOKEN=your_vercel_token_here
|
|
119
143
|
export VERCEL_TEAM_ID=your_team_id_here
|
|
120
144
|
export VERCEL_PROJECT_ID=your_project_id_here
|
|
121
145
|
```
|
|
122
|
-
Get your token from [Vercel Account Tokens](https://vercel.com/account/tokens)
|
|
123
|
-
|
|
124
|
-
### Daytona (Development Workspaces)
|
|
125
|
-
```bash
|
|
126
|
-
export DAYTONA_API_KEY=your_daytona_api_key_here
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
## API Reference
|
|
132
|
-
|
|
133
|
-
### Core SDK
|
|
134
|
-
|
|
135
|
-
#### `ComputeSDK.createSandbox(config?)`
|
|
136
|
-
|
|
137
|
-
Creates a sandbox using auto-detection or specified configuration.
|
|
138
146
|
|
|
139
147
|
```typescript
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
// With configuration
|
|
144
|
-
const sandbox = ComputeSDK.createSandbox({
|
|
145
|
-
provider: 'e2b',
|
|
146
|
-
runtime: 'python',
|
|
147
|
-
timeout: 600000 // 10 minutes
|
|
148
|
-
});
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
**Parameters:**
|
|
152
|
-
- `config` (optional): Sandbox configuration object
|
|
148
|
+
import { compute } from 'computesdk';
|
|
149
|
+
import { vercel } from '@computesdk/vercel';
|
|
153
150
|
|
|
154
|
-
|
|
151
|
+
compute.setConfig({
|
|
152
|
+
provider: vercel({ runtime: 'node' })
|
|
153
|
+
});
|
|
155
154
|
|
|
156
|
-
|
|
155
|
+
const sandbox = await compute.sandbox.create({});
|
|
157
156
|
|
|
158
|
-
|
|
157
|
+
// Execute Node.js or Python
|
|
158
|
+
const result = await sandbox.runCode(`
|
|
159
|
+
console.log('Node.js version:', process.version);
|
|
160
|
+
console.log('Hello from Vercel!');
|
|
161
|
+
`);
|
|
159
162
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
console.log('Available providers:', providers); // ['e2b', 'vercel']
|
|
163
|
+
// Up to 45 minutes execution time
|
|
164
|
+
// Global infrastructure deployment
|
|
163
165
|
```
|
|
164
166
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
### Utility Functions
|
|
167
|
+
### Daytona - Development Workspaces
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
Daytona provides development workspace environments:
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
```bash
|
|
172
|
+
export DAYTONA_API_KEY=your_daytona_api_key_here
|
|
173
|
+
```
|
|
172
174
|
|
|
173
175
|
```typescript
|
|
174
|
-
import {
|
|
175
|
-
import {
|
|
176
|
+
import { compute } from 'computesdk';
|
|
177
|
+
import { daytona } from '@computesdk/daytona';
|
|
176
178
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
code: 'console.log("Hello from Node.js!");',
|
|
180
|
-
runtime: 'node'
|
|
179
|
+
compute.setConfig({
|
|
180
|
+
provider: daytona({ apiKey: process.env.DAYTONA_API_KEY })
|
|
181
181
|
});
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
**Parameters:**
|
|
185
|
-
```typescript
|
|
186
|
-
interface ExecuteSandboxParams {
|
|
187
|
-
sandbox: ComputeSandbox;
|
|
188
|
-
code: string;
|
|
189
|
-
runtime?: Runtime;
|
|
190
|
-
}
|
|
191
|
-
```
|
|
192
182
|
|
|
193
|
-
|
|
183
|
+
const sandbox = await compute.sandbox.create({});
|
|
194
184
|
|
|
195
|
-
|
|
185
|
+
// Execute in development workspace
|
|
186
|
+
const result = await sandbox.runCode(`
|
|
187
|
+
print('Hello from Daytona!')
|
|
188
|
+
import sys
|
|
189
|
+
print(f'Python version: {sys.version}')
|
|
190
|
+
`);
|
|
191
|
+
```
|
|
196
192
|
|
|
197
|
-
|
|
193
|
+
## Core API
|
|
198
194
|
|
|
199
|
-
|
|
195
|
+
### Configuration
|
|
200
196
|
|
|
201
197
|
```typescript
|
|
202
|
-
|
|
203
|
-
provider: string;
|
|
204
|
-
sandboxId: string;
|
|
205
|
-
|
|
206
|
-
execute(code: string, runtime?: Runtime): Promise<ExecutionResult>;
|
|
207
|
-
runCode(code: string, runtime?: Runtime): Promise<ExecutionResult>;
|
|
208
|
-
runCommand(command: string, args?: string[]): Promise<ExecutionResult>;
|
|
209
|
-
kill(): Promise<void>;
|
|
210
|
-
getInfo(): Promise<SandboxInfo>;
|
|
211
|
-
}
|
|
212
|
-
```
|
|
198
|
+
import { compute } from 'computesdk';
|
|
213
199
|
|
|
214
|
-
|
|
200
|
+
// Set default provider
|
|
201
|
+
compute.setConfig({ provider: myProvider });
|
|
215
202
|
|
|
216
|
-
|
|
203
|
+
// Get current config
|
|
204
|
+
const config = compute.getConfig();
|
|
217
205
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
readonly filesystem: SandboxFileSystem;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
interface SandboxFileSystem {
|
|
224
|
-
readFile(path: string): Promise<string>;
|
|
225
|
-
writeFile(path: string, content: string): Promise<void>;
|
|
226
|
-
mkdir(path: string): Promise<void>;
|
|
227
|
-
readdir(path: string): Promise<FileEntry[]>;
|
|
228
|
-
exists(path: string): Promise<boolean>;
|
|
229
|
-
remove(path: string): Promise<void>;
|
|
230
|
-
}
|
|
206
|
+
// Clear config
|
|
207
|
+
compute.clearConfig();
|
|
231
208
|
```
|
|
232
209
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
Extends base capabilities with terminal operations (E2B only):
|
|
210
|
+
### Sandbox Management
|
|
236
211
|
|
|
237
212
|
```typescript
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
213
|
+
// Create sandbox with explicit provider
|
|
214
|
+
const sandbox = await compute.sandbox.create({
|
|
215
|
+
provider: e2b({ apiKey: 'your-key' }),
|
|
216
|
+
options: { runtime: 'python', timeout: 300000 }
|
|
217
|
+
});
|
|
241
218
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
```
|
|
219
|
+
// Create sandbox with default provider
|
|
220
|
+
const sandbox = await compute.sandbox.create({
|
|
221
|
+
options: { runtime: 'python' }
|
|
222
|
+
});
|
|
247
223
|
|
|
248
|
-
|
|
224
|
+
// Get existing sandbox
|
|
225
|
+
const sandbox = await compute.sandbox.getById('sandbox-id');
|
|
249
226
|
|
|
250
|
-
|
|
227
|
+
// List all sandboxes
|
|
228
|
+
const sandboxes = await compute.sandbox.list();
|
|
251
229
|
|
|
252
|
-
|
|
253
|
-
|
|
230
|
+
// Destroy sandbox
|
|
231
|
+
await compute.sandbox.destroy('sandbox-id');
|
|
254
232
|
```
|
|
255
233
|
|
|
256
|
-
###
|
|
234
|
+
### Code Execution
|
|
257
235
|
|
|
258
|
-
|
|
236
|
+
```typescript
|
|
237
|
+
// Run code
|
|
238
|
+
const result = await sandbox.runCode('print("Hello")', 'python');
|
|
259
239
|
|
|
260
|
-
|
|
240
|
+
// Run shell command
|
|
241
|
+
const result = await sandbox.runCommand('ls', ['-la']);
|
|
261
242
|
|
|
262
|
-
|
|
243
|
+
// Result structure
|
|
263
244
|
interface ExecutionResult {
|
|
264
245
|
stdout: string;
|
|
265
246
|
stderr: string;
|
|
@@ -270,477 +251,383 @@ interface ExecutionResult {
|
|
|
270
251
|
}
|
|
271
252
|
```
|
|
272
253
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
Information about a sandbox instance:
|
|
254
|
+
### Filesystem Operations
|
|
276
255
|
|
|
277
256
|
```typescript
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
provider: string;
|
|
281
|
-
runtime: Runtime;
|
|
282
|
-
status: 'running' | 'stopped' | 'error';
|
|
283
|
-
createdAt: Date;
|
|
284
|
-
timeout: number;
|
|
285
|
-
metadata?: Record<string, any>;
|
|
286
|
-
}
|
|
287
|
-
```
|
|
257
|
+
// Write file
|
|
258
|
+
await sandbox.filesystem.writeFile('/tmp/hello.py', 'print("Hello")');
|
|
288
259
|
|
|
289
|
-
|
|
260
|
+
// Read file
|
|
261
|
+
const content = await sandbox.filesystem.readFile('/tmp/hello.py');
|
|
290
262
|
|
|
291
|
-
|
|
263
|
+
// Create directory
|
|
264
|
+
await sandbox.filesystem.mkdir('/tmp/mydir');
|
|
292
265
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
name: string;
|
|
296
|
-
path: string;
|
|
297
|
-
isDirectory: boolean;
|
|
298
|
-
size: number;
|
|
299
|
-
lastModified: Date;
|
|
300
|
-
}
|
|
301
|
-
```
|
|
266
|
+
// List directory
|
|
267
|
+
const files = await sandbox.filesystem.readdir('/tmp');
|
|
302
268
|
|
|
303
|
-
|
|
269
|
+
// Check if exists
|
|
270
|
+
const exists = await sandbox.filesystem.exists('/tmp/hello.py');
|
|
304
271
|
|
|
305
|
-
|
|
272
|
+
// Remove file/directory
|
|
273
|
+
await sandbox.filesystem.remove('/tmp/hello.py');
|
|
274
|
+
```
|
|
306
275
|
|
|
307
|
-
|
|
308
|
-
import { ComputeSDK, FilesystemComputeSandbox } from 'computesdk';
|
|
276
|
+
### Terminal Operations
|
|
309
277
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// Create project structure
|
|
318
|
-
await fsSandbox.filesystem.mkdir('/project/data');
|
|
319
|
-
await fsSandbox.filesystem.mkdir('/project/output');
|
|
320
|
-
|
|
321
|
-
// Write input data
|
|
322
|
-
const data = JSON.stringify([
|
|
323
|
-
{ name: 'Alice', sales: 1000 },
|
|
324
|
-
{ name: 'Bob', sales: 1500 },
|
|
325
|
-
{ name: 'Charlie', sales: 800 }
|
|
326
|
-
]);
|
|
327
|
-
|
|
328
|
-
await fsSandbox.filesystem.writeFile('/project/data/sales.json', data);
|
|
329
|
-
|
|
330
|
-
// Process data based on provider
|
|
331
|
-
let code: string;
|
|
332
|
-
if (sandbox.provider === 'e2b') {
|
|
333
|
-
// Python processing for E2B
|
|
334
|
-
code = `
|
|
335
|
-
import json
|
|
336
|
-
import pandas as pd
|
|
337
|
-
|
|
338
|
-
# Read data
|
|
339
|
-
with open('/project/data/sales.json', 'r') as f:
|
|
340
|
-
data = json.load(f)
|
|
278
|
+
```typescript
|
|
279
|
+
// Create terminal (E2B only)
|
|
280
|
+
const terminal = await sandbox.terminal.create({
|
|
281
|
+
command: 'bash',
|
|
282
|
+
cols: 80,
|
|
283
|
+
rows: 24
|
|
284
|
+
});
|
|
341
285
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
total_sales = df['sales'].sum()
|
|
345
|
-
avg_sales = df['sales'].mean()
|
|
286
|
+
// Write to terminal
|
|
287
|
+
await terminal.write('ls -la\n');
|
|
346
288
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
'total_sales': total_sales,
|
|
350
|
-
'average_sales': avg_sales,
|
|
351
|
-
'top_performer': df.loc[df['sales'].idxmax(), 'name']
|
|
352
|
-
}
|
|
289
|
+
// Resize terminal
|
|
290
|
+
await terminal.resize(120, 30);
|
|
353
291
|
|
|
354
|
-
|
|
355
|
-
|
|
292
|
+
// Kill terminal
|
|
293
|
+
await terminal.kill();
|
|
356
294
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
print(f"Top Performer: {results['top_performer']}")
|
|
360
|
-
`;
|
|
361
|
-
} else {
|
|
362
|
-
// JavaScript processing for Vercel/Daytona
|
|
363
|
-
code = `
|
|
364
|
-
const fs = require('fs');
|
|
365
|
-
|
|
366
|
-
// Read data
|
|
367
|
-
const data = JSON.parse(fs.readFileSync('/project/data/sales.json', 'utf8'));
|
|
368
|
-
|
|
369
|
-
// Process data
|
|
370
|
-
const totalSales = data.reduce((sum, person) => sum + person.sales, 0);
|
|
371
|
-
const avgSales = totalSales / data.length;
|
|
372
|
-
const topPerformer = data.reduce((top, person) =>
|
|
373
|
-
person.sales > top.sales ? person : top
|
|
374
|
-
);
|
|
375
|
-
|
|
376
|
-
// Write results
|
|
377
|
-
const results = {
|
|
378
|
-
total_sales: totalSales,
|
|
379
|
-
average_sales: avgSales,
|
|
380
|
-
top_performer: topPerformer.name
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
fs.writeFileSync('/project/output/results.json', JSON.stringify(results, null, 2));
|
|
384
|
-
|
|
385
|
-
console.log(\`Total Sales: $\${totalSales}\`);
|
|
386
|
-
console.log(\`Average Sales: $\${avgSales.toFixed(2)}\`);
|
|
387
|
-
console.log(\`Top Performer: \${results.top_performer}\`);
|
|
388
|
-
`;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Execute processing
|
|
392
|
-
const result = await fsSandbox.execute(code);
|
|
393
|
-
console.log('Processing Output:', result.stdout);
|
|
394
|
-
|
|
395
|
-
// Read results
|
|
396
|
-
const results = await fsSandbox.filesystem.readFile('/project/output/results.json');
|
|
397
|
-
console.log('Results:', JSON.parse(results));
|
|
398
|
-
|
|
399
|
-
// List generated files
|
|
400
|
-
const outputFiles = await fsSandbox.filesystem.readdir('/project/output');
|
|
401
|
-
console.log('Generated files:', outputFiles.map(f => f.name));
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
await sandbox.kill();
|
|
405
|
-
}
|
|
295
|
+
// List terminals
|
|
296
|
+
const terminals = await sandbox.terminal.list();
|
|
406
297
|
|
|
407
|
-
|
|
298
|
+
// Get terminal by ID
|
|
299
|
+
const terminal = await sandbox.terminal.getById('terminal-id');
|
|
408
300
|
```
|
|
409
301
|
|
|
410
|
-
|
|
302
|
+
## Web Framework Integration
|
|
303
|
+
|
|
304
|
+
ComputeSDK provides built-in request handlers for web frameworks:
|
|
411
305
|
|
|
412
306
|
```typescript
|
|
307
|
+
import { handleComputeRequest } from 'computesdk';
|
|
413
308
|
import { e2b } from '@computesdk/e2b';
|
|
414
|
-
import { TerminalComputeSandbox, FilesystemComputeSandbox } from 'computesdk';
|
|
415
309
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
await sandbox.filesystem.writeFile('/workspace/requirements.txt',
|
|
422
|
-
'pandas\nnumpy\nmatplotlib\nscikit-learn'
|
|
423
|
-
);
|
|
424
|
-
|
|
425
|
-
// Create interactive terminal
|
|
426
|
-
const terminal = await sandbox.terminal.create({
|
|
427
|
-
command: 'bash',
|
|
428
|
-
cols: 120,
|
|
429
|
-
rows: 30
|
|
310
|
+
// Next.js API route
|
|
311
|
+
export async function POST(request: Request) {
|
|
312
|
+
return handleComputeRequest({
|
|
313
|
+
request,
|
|
314
|
+
provider: e2b({ apiKey: process.env.E2B_API_KEY })
|
|
430
315
|
});
|
|
431
|
-
|
|
432
|
-
// Set up output handler
|
|
433
|
-
terminal.onData = (data: Uint8Array) => {
|
|
434
|
-
const output = new TextDecoder().decode(data);
|
|
435
|
-
console.log('Terminal:', output);
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
// Install dependencies
|
|
439
|
-
await terminal.write('cd /workspace\n');
|
|
440
|
-
await terminal.write('pip install -r requirements.txt\n');
|
|
441
|
-
|
|
442
|
-
// Start interactive Python session
|
|
443
|
-
await terminal.write('python3\n');
|
|
444
|
-
await terminal.write('import pandas as pd\n');
|
|
445
|
-
await terminal.write('import numpy as np\n');
|
|
446
|
-
await terminal.write('print("Development environment ready!")\n');
|
|
447
|
-
|
|
448
|
-
// Simulate interactive development
|
|
449
|
-
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
450
|
-
|
|
451
|
-
// Clean up
|
|
452
|
-
await terminal.kill();
|
|
453
|
-
await sandbox.kill();
|
|
454
316
|
}
|
|
455
317
|
|
|
456
|
-
|
|
318
|
+
// Client usage
|
|
319
|
+
const response = await fetch('/api/compute', {
|
|
320
|
+
method: 'POST',
|
|
321
|
+
headers: { 'Content-Type': 'application/json' },
|
|
322
|
+
body: JSON.stringify({
|
|
323
|
+
action: 'compute.sandbox.runCode',
|
|
324
|
+
code: 'print("Hello from web!")',
|
|
325
|
+
runtime: 'python'
|
|
326
|
+
})
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
const result = await response.json();
|
|
330
|
+
console.log(result.result.stdout);
|
|
457
331
|
```
|
|
458
332
|
|
|
459
|
-
###
|
|
333
|
+
### Supported Actions
|
|
334
|
+
|
|
335
|
+
- `compute.sandbox.create` - Create new sandbox
|
|
336
|
+
- `compute.sandbox.destroy` - Destroy sandbox
|
|
337
|
+
- `compute.sandbox.getInfo` - Get sandbox information
|
|
338
|
+
- `compute.sandbox.list` - List all sandboxes
|
|
339
|
+
- `compute.sandbox.runCode` - Execute code
|
|
340
|
+
- `compute.sandbox.runCommand` - Run shell command
|
|
341
|
+
- `compute.sandbox.filesystem.readFile` - Read file
|
|
342
|
+
- `compute.sandbox.filesystem.writeFile` - Write file
|
|
343
|
+
- `compute.sandbox.filesystem.mkdir` - Create directory
|
|
344
|
+
- `compute.sandbox.filesystem.readdir` - List directory
|
|
345
|
+
- `compute.sandbox.filesystem.exists` - Check if path exists
|
|
346
|
+
- `compute.sandbox.filesystem.remove` - Remove file/directory
|
|
347
|
+
- `compute.sandbox.terminal.create` - Create terminal
|
|
348
|
+
- `compute.sandbox.terminal.list` - List terminals
|
|
349
|
+
- `compute.sandbox.terminal.getById` - Get terminal by ID
|
|
350
|
+
- `compute.sandbox.terminal.destroy` - Destroy terminal
|
|
351
|
+
- `compute.sandbox.terminal.write` - Write to terminal
|
|
352
|
+
- `compute.sandbox.terminal.resize` - Resize terminal
|
|
353
|
+
- `compute.sandbox.terminal.kill` - Kill terminal
|
|
354
|
+
|
|
355
|
+
## Frontend Integration
|
|
356
|
+
|
|
357
|
+
Use `@computesdk/ui` for framework-agnostic factory functions:
|
|
460
358
|
|
|
461
359
|
```typescript
|
|
462
|
-
import {
|
|
463
|
-
import { e2b } from '@computesdk/e2b';
|
|
464
|
-
import { vercel } from '@computesdk/vercel';
|
|
465
|
-
import { daytona } from '@computesdk/daytona';
|
|
466
|
-
|
|
467
|
-
async function compareProviders() {
|
|
468
|
-
const testCode = `
|
|
469
|
-
import json
|
|
470
|
-
import time
|
|
471
|
-
start = time.time()
|
|
472
|
-
|
|
473
|
-
# Simple computation
|
|
474
|
-
result = sum(range(1000))
|
|
475
|
-
elapsed = time.time() - start
|
|
476
|
-
|
|
477
|
-
output = {
|
|
478
|
-
"result": result,
|
|
479
|
-
"elapsed_ms": round(elapsed * 1000, 2),
|
|
480
|
-
"provider": "will_be_set"
|
|
481
|
-
}
|
|
360
|
+
import { createCompute, createSandboxConsole } from '@computesdk/ui';
|
|
482
361
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
{ name: 'Vercel', factory: () => vercel({ runtime: 'python' }) },
|
|
489
|
-
{ name: 'Daytona', factory: () => daytona({ runtime: 'python' }) },
|
|
490
|
-
];
|
|
362
|
+
function CodeExecutor() {
|
|
363
|
+
const compute = createCompute({
|
|
364
|
+
apiEndpoint: '/api/compute',
|
|
365
|
+
defaultRuntime: 'python'
|
|
366
|
+
});
|
|
491
367
|
|
|
492
|
-
|
|
493
|
-
|
|
368
|
+
const executeCode = async () => {
|
|
369
|
+
const sandbox = await compute.sandbox.create();
|
|
370
|
+
const result = await sandbox.runCode('print("Hello World!")');
|
|
371
|
+
console.log(result.result?.stdout);
|
|
372
|
+
await sandbox.destroy();
|
|
373
|
+
};
|
|
494
374
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
code: testCode,
|
|
501
|
-
runtime: 'python'
|
|
502
|
-
});
|
|
503
|
-
const totalTime = Date.now() - start;
|
|
504
|
-
|
|
505
|
-
const output = JSON.parse(result.stdout);
|
|
506
|
-
console.log(`${name}:`);
|
|
507
|
-
console.log(` Computation: ${output.result}`);
|
|
508
|
-
console.log(` Execution time: ${output.elapsed_ms}ms`);
|
|
509
|
-
console.log(` Total time: ${totalTime}ms`);
|
|
510
|
-
console.log(` Provider overhead: ${totalTime - output.elapsed_ms}ms`);
|
|
511
|
-
console.log();
|
|
512
|
-
|
|
513
|
-
} catch (error) {
|
|
514
|
-
console.log(`${name}: Failed - ${error.message}`);
|
|
515
|
-
console.log();
|
|
516
|
-
}
|
|
517
|
-
}
|
|
375
|
+
return (
|
|
376
|
+
<button onClick={executeCode}>
|
|
377
|
+
Execute Code
|
|
378
|
+
</button>
|
|
379
|
+
);
|
|
518
380
|
}
|
|
519
|
-
|
|
520
|
-
compareProviders().catch(console.error);
|
|
521
381
|
```
|
|
522
382
|
|
|
523
383
|
## Error Handling
|
|
524
384
|
|
|
525
|
-
ComputeSDK provides comprehensive error handling with specific error types:
|
|
526
|
-
|
|
527
385
|
```typescript
|
|
528
|
-
import { ComputeSDK } from 'computesdk';
|
|
529
|
-
|
|
530
386
|
try {
|
|
531
|
-
const sandbox =
|
|
532
|
-
const result = await sandbox.
|
|
387
|
+
const sandbox = await compute.sandbox.create({});
|
|
388
|
+
const result = await sandbox.runCode('invalid code');
|
|
533
389
|
} catch (error) {
|
|
534
|
-
|
|
535
|
-
console.error('Authentication Error: Check your environment variables');
|
|
536
|
-
console.error('Required: E2B_API_KEY, VERCEL_TOKEN, etc.');
|
|
537
|
-
} else if (error.message.includes('timeout')) {
|
|
538
|
-
console.error('Timeout Error: Execution took too long');
|
|
539
|
-
} else if (error.message.includes('quota') || error.message.includes('limit')) {
|
|
540
|
-
console.error('Quota Error: API usage limits exceeded');
|
|
541
|
-
} else if (error.message.includes('not installed')) {
|
|
542
|
-
console.error('Configuration Error: Provider package not installed');
|
|
543
|
-
console.error('Run: npm install @computesdk/[provider-name]');
|
|
544
|
-
} else {
|
|
545
|
-
console.error('Execution Error:', error.message);
|
|
546
|
-
}
|
|
390
|
+
console.error('Execution failed:', error.message);
|
|
547
391
|
}
|
|
548
392
|
```
|
|
549
393
|
|
|
550
|
-
##
|
|
551
|
-
|
|
552
|
-
### E2B - Full Development Environment
|
|
394
|
+
## Examples
|
|
553
395
|
|
|
554
|
-
|
|
396
|
+
### Data Science with E2B
|
|
555
397
|
|
|
556
398
|
```typescript
|
|
399
|
+
import { compute } from 'computesdk';
|
|
557
400
|
import { e2b } from '@computesdk/e2b';
|
|
558
401
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
// Full Python environment with data science libraries
|
|
562
|
-
const result = await sandbox.execute(`
|
|
563
|
-
import pandas as pd
|
|
564
|
-
import matplotlib.pyplot as plt
|
|
565
|
-
import numpy as np
|
|
402
|
+
compute.setConfig({ provider: e2b({ apiKey: process.env.E2B_API_KEY }) });
|
|
566
403
|
|
|
567
|
-
|
|
568
|
-
data = np.random.randn(1000)
|
|
569
|
-
plt.hist(data, bins=50)
|
|
570
|
-
plt.savefig('/tmp/histogram.png')
|
|
571
|
-
print("Histogram saved!")
|
|
572
|
-
`);
|
|
404
|
+
const sandbox = await compute.sandbox.create({});
|
|
573
405
|
|
|
574
|
-
//
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
406
|
+
// Create project structure
|
|
407
|
+
await sandbox.filesystem.mkdir('/analysis');
|
|
408
|
+
await sandbox.filesystem.mkdir('/analysis/data');
|
|
409
|
+
await sandbox.filesystem.mkdir('/analysis/output');
|
|
578
410
|
|
|
579
|
-
|
|
411
|
+
// Write input data
|
|
412
|
+
const csvData = `name,age,city
|
|
413
|
+
Alice,25,New York
|
|
414
|
+
Bob,30,San Francisco
|
|
415
|
+
Charlie,35,Chicago`;
|
|
580
416
|
|
|
581
|
-
|
|
417
|
+
await sandbox.filesystem.writeFile('/analysis/data/people.csv', csvData);
|
|
582
418
|
|
|
583
|
-
|
|
584
|
-
|
|
419
|
+
// Process data with Python
|
|
420
|
+
const result = await sandbox.runCode(`
|
|
421
|
+
import pandas as pd
|
|
422
|
+
import matplotlib.pyplot as plt
|
|
585
423
|
|
|
586
|
-
|
|
424
|
+
# Read data
|
|
425
|
+
df = pd.read_csv('/analysis/data/people.csv')
|
|
426
|
+
print("Data loaded:")
|
|
427
|
+
print(df)
|
|
428
|
+
|
|
429
|
+
# Calculate statistics
|
|
430
|
+
avg_age = df['age'].mean()
|
|
431
|
+
print(f"\\nAverage age: {avg_age}")
|
|
432
|
+
|
|
433
|
+
# Create visualization
|
|
434
|
+
plt.figure(figsize=(8, 6))
|
|
435
|
+
plt.bar(df['name'], df['age'])
|
|
436
|
+
plt.title('Age by Person')
|
|
437
|
+
plt.xlabel('Name')
|
|
438
|
+
plt.ylabel('Age')
|
|
439
|
+
plt.savefig('/analysis/output/age_chart.png')
|
|
440
|
+
print("\\nChart saved to /analysis/output/age_chart.png")
|
|
441
|
+
|
|
442
|
+
# Save results
|
|
443
|
+
results = {
|
|
444
|
+
'total_people': len(df),
|
|
445
|
+
'average_age': avg_age,
|
|
446
|
+
'cities': df['city'].unique().tolist()
|
|
447
|
+
}
|
|
587
448
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
const path = require('path');
|
|
449
|
+
import json
|
|
450
|
+
with open('/analysis/output/results.json', 'w') as f:
|
|
451
|
+
json.dump(results, f, indent=2)
|
|
592
452
|
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
users: 1000,
|
|
596
|
-
active: 750,
|
|
597
|
-
revenue: 50000
|
|
598
|
-
};
|
|
453
|
+
print("Results saved!")
|
|
454
|
+
`);
|
|
599
455
|
|
|
600
|
-
|
|
601
|
-
fs.writeFileSync('/tmp/api-data.json', JSON.stringify(apiData, null, 2));
|
|
456
|
+
console.log(result.stdout);
|
|
602
457
|
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
458
|
+
// Read the results
|
|
459
|
+
const results = await sandbox.filesystem.readFile('/analysis/output/results.json');
|
|
460
|
+
console.log('Analysis results:', JSON.parse(results));
|
|
606
461
|
|
|
607
|
-
|
|
608
|
-
const data = await sandbox.filesystem.readFile('/tmp/api-data.json');
|
|
609
|
-
console.log('Generated data:', JSON.parse(data));
|
|
462
|
+
await compute.sandbox.destroy(sandbox.sandboxId);
|
|
610
463
|
```
|
|
611
464
|
|
|
612
|
-
###
|
|
613
|
-
|
|
614
|
-
Daytona provides development workspace environments with full filesystem support:
|
|
465
|
+
### Cross-Provider Data Processing
|
|
615
466
|
|
|
616
467
|
```typescript
|
|
468
|
+
import { compute } from 'computesdk';
|
|
469
|
+
import { vercel } from '@computesdk/vercel';
|
|
617
470
|
import { daytona } from '@computesdk/daytona';
|
|
618
471
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
const
|
|
472
|
+
async function processData(provider: any) {
|
|
473
|
+
compute.setConfig({ provider });
|
|
474
|
+
|
|
475
|
+
const sandbox = await compute.sandbox.create({});
|
|
476
|
+
|
|
477
|
+
// Create workspace
|
|
478
|
+
await sandbox.filesystem.mkdir('/workspace');
|
|
479
|
+
|
|
480
|
+
// Write input data
|
|
481
|
+
await sandbox.filesystem.writeFile('/workspace/input.json',
|
|
482
|
+
JSON.stringify({ numbers: [1, 2, 3, 4, 5] })
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
// Process with code execution
|
|
486
|
+
const result = await sandbox.runCode(`
|
|
623
487
|
import json
|
|
624
|
-
import os
|
|
625
488
|
|
|
626
|
-
#
|
|
627
|
-
|
|
628
|
-
|
|
489
|
+
# Read input
|
|
490
|
+
with open('/workspace/input.json', 'r') as f:
|
|
491
|
+
data = json.load(f)
|
|
629
492
|
|
|
630
|
-
#
|
|
631
|
-
|
|
632
|
-
|
|
493
|
+
# Process
|
|
494
|
+
numbers = data['numbers']
|
|
495
|
+
result = {
|
|
496
|
+
'sum': sum(numbers),
|
|
497
|
+
'average': sum(numbers) / len(numbers),
|
|
498
|
+
'count': len(numbers)
|
|
499
|
+
}
|
|
633
500
|
|
|
634
|
-
|
|
635
|
-
|
|
501
|
+
# Write output
|
|
502
|
+
with open('/workspace/output.json', 'w') as f:
|
|
503
|
+
json.dump(result, f, indent=2)
|
|
636
504
|
|
|
637
|
-
print("
|
|
638
|
-
|
|
639
|
-
|
|
505
|
+
print("Processing complete!")
|
|
506
|
+
`);
|
|
507
|
+
|
|
508
|
+
// Read results
|
|
509
|
+
const output = await sandbox.filesystem.readFile('/workspace/output.json');
|
|
510
|
+
await compute.sandbox.destroy(sandbox.sandboxId);
|
|
511
|
+
|
|
512
|
+
return JSON.parse(output);
|
|
513
|
+
}
|
|
640
514
|
|
|
641
|
-
//
|
|
642
|
-
const
|
|
643
|
-
console.log('
|
|
515
|
+
// Use with different providers
|
|
516
|
+
const vercelResult = await processData(vercel({ runtime: 'python' }));
|
|
517
|
+
console.log('Vercel result:', vercelResult);
|
|
644
518
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
console.log('main.py content:', mainPy);
|
|
519
|
+
const daytonaResult = await processData(daytona({ runtime: 'python' }));
|
|
520
|
+
console.log('Daytona result:', daytonaResult);
|
|
648
521
|
```
|
|
649
522
|
|
|
523
|
+
## Provider Packages
|
|
650
524
|
|
|
525
|
+
ComputeSDK uses separate provider packages:
|
|
651
526
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
527
|
+
```bash
|
|
528
|
+
npm install @computesdk/e2b # E2B provider
|
|
529
|
+
npm install @computesdk/vercel # Vercel provider
|
|
530
|
+
npm install @computesdk/daytona # Daytona provider
|
|
531
|
+
```
|
|
657
532
|
|
|
658
|
-
|
|
659
|
-
- **Vercel**: Web applications, APIs, serverless functions, long-running tasks
|
|
660
|
-
- **Daytona**: Development workspaces, custom environments, team collaboration
|
|
533
|
+
Each provider implements the same interface but may support different capabilities (filesystem, terminal, etc.).
|
|
661
534
|
|
|
662
|
-
|
|
535
|
+
## Custom Providers
|
|
663
536
|
|
|
664
|
-
|
|
537
|
+
Create custom providers using the factory:
|
|
665
538
|
|
|
666
539
|
```typescript
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
540
|
+
import { createProvider } from 'computesdk';
|
|
541
|
+
|
|
542
|
+
const myProvider = createProvider({
|
|
543
|
+
name: 'my-provider',
|
|
544
|
+
methods: {
|
|
545
|
+
sandbox: {
|
|
546
|
+
create: async (config, options) => {
|
|
547
|
+
// Implementation
|
|
548
|
+
},
|
|
549
|
+
getById: async (config, id) => {
|
|
550
|
+
// Implementation
|
|
551
|
+
},
|
|
552
|
+
list: async (config) => {
|
|
553
|
+
// Implementation
|
|
554
|
+
},
|
|
555
|
+
destroy: async (config, id) => {
|
|
556
|
+
// Implementation
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
});
|
|
675
561
|
```
|
|
676
562
|
|
|
677
|
-
|
|
563
|
+
## TypeScript Support
|
|
678
564
|
|
|
679
|
-
|
|
565
|
+
ComputeSDK is fully typed with comprehensive TypeScript definitions:
|
|
680
566
|
|
|
681
567
|
```typescript
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
throw error;
|
|
690
|
-
} finally {
|
|
691
|
-
if (sandbox) {
|
|
692
|
-
await sandbox.kill();
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
}
|
|
568
|
+
import type {
|
|
569
|
+
Sandbox,
|
|
570
|
+
Provider,
|
|
571
|
+
ExecutionResult,
|
|
572
|
+
ComputeConfig,
|
|
573
|
+
Runtime
|
|
574
|
+
} from 'computesdk';
|
|
696
575
|
```
|
|
697
576
|
|
|
698
|
-
|
|
577
|
+
## Provider Comparison
|
|
699
578
|
|
|
700
|
-
|
|
579
|
+
| Provider | Code Execution | Filesystem | Terminal | Use Cases |
|
|
580
|
+
|----------|----------------|------------|----------|-----------|
|
|
581
|
+
| **E2B** | Python, Node.js | ✅ Full | ✅ PTY | Data science, AI/ML, interactive development |
|
|
582
|
+
| **Vercel** | Node.js, Python | ✅ Full | ❌ | Web apps, APIs, serverless functions |
|
|
583
|
+
| **Daytona** | Python, Node.js | ✅ Full | ❌ | Development workspaces, custom environments |
|
|
701
584
|
|
|
702
|
-
|
|
703
|
-
import { FilesystemComputeSandbox, TerminalComputeSandbox } from 'computesdk';
|
|
585
|
+
### Key Differences
|
|
704
586
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
}
|
|
587
|
+
- **E2B**: Full development environment with data science libraries and interactive terminals
|
|
588
|
+
- **Vercel**: Ephemeral sandboxes optimized for serverless execution (up to 45 minutes)
|
|
589
|
+
- **Daytona**: Development workspaces with persistent environments
|
|
709
590
|
|
|
710
|
-
|
|
711
|
-
// TypeScript ensures terminal operations are available
|
|
712
|
-
return sandbox.terminal.create({ command: 'bash' });
|
|
713
|
-
}
|
|
714
|
-
```
|
|
591
|
+
## Examples
|
|
715
592
|
|
|
716
|
-
|
|
593
|
+
Check out the [examples directory](./examples) for complete implementations with different web frameworks:
|
|
717
594
|
|
|
718
|
-
|
|
595
|
+
- [Next.js](./examples/nextjs)
|
|
596
|
+
- [Nuxt](./examples/nuxt)
|
|
597
|
+
- [SvelteKit](./examples/sveltekit)
|
|
598
|
+
- [Remix](./examples/remix)
|
|
599
|
+
- [Astro](./examples/astro)
|
|
719
600
|
|
|
720
|
-
|
|
601
|
+
## Resources
|
|
721
602
|
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
- `FullComputeSpecification` for complete functionality
|
|
603
|
+
- 📖 **[Full Documentation](https://computesdk.com)** - Complete guides and API reference
|
|
604
|
+
- 🚀 **[Getting Started](https://computesdk.com/getting-started)** - Quick setup guide
|
|
605
|
+
- 💡 **[Examples](./examples)** - Real-world usage examples
|
|
606
|
+
- 🎯 **[Providers](https://computesdk.com/providers)** - Provider-specific guides
|
|
727
607
|
|
|
728
|
-
|
|
608
|
+
## Contributing
|
|
729
609
|
|
|
730
|
-
|
|
610
|
+
ComputeSDK is open source and welcomes contributions! Whether you're fixing bugs, adding features, or improving documentation, we'd love your help.
|
|
731
611
|
|
|
732
|
-
|
|
612
|
+
1. Fork the repository
|
|
613
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
614
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
615
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
616
|
+
5. Open a Pull Request
|
|
733
617
|
|
|
734
|
-
##
|
|
618
|
+
## Community & Support
|
|
735
619
|
|
|
736
|
-
|
|
620
|
+
- 💬 **[GitHub Discussions](https://github.com/computesdk/computesdk/discussions)** - Ask questions and share ideas
|
|
621
|
+
- 🐛 **[GitHub Issues](https://github.com/computesdk/computesdk/issues)** - Report bugs and request features
|
|
622
|
+
- 📧 **[Contact Us](https://computesdk.com/contact)** - Get in touch with the team
|
|
737
623
|
|
|
738
|
-
##
|
|
624
|
+
## License
|
|
739
625
|
|
|
740
|
-
- [
|
|
741
|
-
- [Documentation](https://github.com/computesdk/computesdk)
|
|
742
|
-
- [Examples](https://github.com/computesdk/computesdk/tree/main/examples)
|
|
626
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
743
627
|
|
|
744
628
|
---
|
|
745
629
|
|
|
746
|
-
|
|
630
|
+
<div align="center">
|
|
631
|
+
<strong>Built with ❤️ by the ComputeSDK team</strong><br>
|
|
632
|
+
<a href="https://computesdk.com">computesdk.com</a>
|
|
633
|
+
</div>
|