computesdk 1.0.1 → 1.0.2

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 (2) hide show
  1. package/README.md +358 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,358 @@
1
+ # ComputeSDK
2
+
3
+ A unified abstraction layer for executing code in secure, isolated sandboxed environments across multiple cloud providers.
4
+
5
+ Similar to how Vercel's AI SDK abstracts different LLM providers, ComputeSDK abstracts different compute sandbox providers into a single, consistent TypeScript interface.
6
+
7
+ ## Features
8
+
9
+ - **Unified API** - Single interface for multiple sandbox providers
10
+ - **Auto-detection** - Automatically detects and uses available providers
11
+ - **Provider-agnostic** - Switch between providers without code changes
12
+ - **Type-safe** - Full TypeScript support with comprehensive type definitions
13
+ - **Extensible** - Easy to add new providers
14
+ - **Production-ready** - Built for real-world applications
15
+
16
+ ## Supported Providers
17
+
18
+ - **E2B** - Python-focused code execution with templates
19
+ - **Vercel** - Node.js and Python execution on Vercel infrastructure
20
+ - **Cloudflare** - Edge computing with Cloudflare Workers and Durable Objects
21
+ - **Fly.io** - Fast boot containers (community contribution target)
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install computesdk
27
+ ```
28
+
29
+ ### Install Provider Packages
30
+
31
+ ```bash
32
+ # Install the providers you need
33
+ npm install @computesdk/e2b # E2B provider
34
+ npm install @computesdk/vercel # Vercel provider
35
+ npm install @computesdk/cloudflare # Cloudflare provider
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### Auto-detection (Recommended)
41
+
42
+ ```typescript
43
+ import { ComputeSDK } from 'computesdk';
44
+
45
+ // Automatically detects and uses available providers
46
+ const sdk = new ComputeSDK();
47
+ const sandbox = await sdk.createSandbox();
48
+
49
+ const result = await sandbox.execute('print("Hello from ComputeSDK!")');
50
+ console.log(result.stdout); // "Hello from ComputeSDK!"
51
+
52
+ await sandbox.kill();
53
+ ```
54
+
55
+ ### Provider-specific Usage
56
+
57
+ ```typescript
58
+ import { executeSandbox } from 'computesdk';
59
+ import { e2b } from '@computesdk/e2b';
60
+
61
+ // Execute with specific provider
62
+ const result = await executeSandbox({
63
+ sandbox: e2b(),
64
+ code: 'print("Hello from E2B!")',
65
+ runtime: 'python'
66
+ });
67
+
68
+ console.log(result.stdout);
69
+ ```
70
+
71
+ ### Multiple Providers
72
+
73
+ ```typescript
74
+ import { executeSandbox } from 'computesdk';
75
+ import { e2b } from '@computesdk/e2b';
76
+ import { vercel } from '@computesdk/vercel';
77
+ import { cloudflare } from '@computesdk/cloudflare';
78
+
79
+ // Try different providers for different use cases
80
+ const providers = [
81
+ { name: 'E2B', provider: e2b() },
82
+ { name: 'Vercel', provider: vercel() },
83
+ { name: 'Cloudflare', provider: cloudflare({ env }) }
84
+ ];
85
+
86
+ for (const { name, provider } of providers) {
87
+ try {
88
+ const result = await executeSandbox({
89
+ sandbox: provider,
90
+ code: 'print("Hello from ' + name + '!")'
91
+ });
92
+ console.log(`${name}:`, result.stdout);
93
+ } catch (error) {
94
+ console.error(`${name} failed:`, error.message);
95
+ }
96
+ }
97
+ ```
98
+
99
+ ## API Reference
100
+
101
+ ### `ComputeSDK`
102
+
103
+ Main SDK class for auto-detection and management.
104
+
105
+ ```typescript
106
+ const sdk = new ComputeSDK(options?: ComputeSDKOptions);
107
+ ```
108
+
109
+ #### Methods
110
+
111
+ - `createSandbox(config?: SandboxConfig)` - Creates a sandbox using auto-detection
112
+ - `getAvailableProviders()` - Returns list of available providers
113
+ - `registerProvider(name: string, provider: ComputeSpecification)` - Registers a custom provider
114
+
115
+ ### `executeSandbox(config: ExecutionConfig)`
116
+
117
+ Utility function for one-off code execution.
118
+
119
+ ```typescript
120
+ interface ExecutionConfig {
121
+ sandbox: ComputeSpecification;
122
+ code: string;
123
+ runtime?: 'python' | 'node';
124
+ timeout?: number;
125
+ }
126
+ ```
127
+
128
+ ### `ExecutionResult`
129
+
130
+ Result object returned by all execution methods.
131
+
132
+ ```typescript
133
+ interface ExecutionResult {
134
+ stdout: string;
135
+ stderr: string;
136
+ exitCode: number;
137
+ executionTime: number;
138
+ sandboxId: string;
139
+ provider: string;
140
+ }
141
+ ```
142
+
143
+ ### `SandboxInfo`
144
+
145
+ Information about a sandbox instance.
146
+
147
+ ```typescript
148
+ interface SandboxInfo {
149
+ id: string;
150
+ provider: string;
151
+ runtime: string;
152
+ status: 'running' | 'stopped';
153
+ createdAt: Date;
154
+ timeout: number;
155
+ metadata?: Record<string, any>;
156
+ }
157
+ ```
158
+
159
+ ## Configuration
160
+
161
+ ### Environment Variables
162
+
163
+ Each provider requires specific environment variables:
164
+
165
+ ```bash
166
+ # E2B
167
+ E2B_API_KEY=your_e2b_api_key
168
+
169
+ # Vercel
170
+ VERCEL_TOKEN=your_vercel_token
171
+ VERCEL_TEAM_ID=your_team_id
172
+ VERCEL_PROJECT_ID=your_project_id
173
+
174
+ # Cloudflare (Workers environment only)
175
+ # Requires Durable Object bindings in wrangler.toml
176
+ ```
177
+
178
+ ### Provider Configuration
179
+
180
+ ```typescript
181
+ import { ComputeSDK } from 'computesdk';
182
+ import { e2b } from '@computesdk/e2b';
183
+ import { vercel } from '@computesdk/vercel';
184
+
185
+ const sdk = new ComputeSDK({
186
+ preferredProviders: ['e2b', 'vercel'], // Order of preference
187
+ timeout: 300000, // Global timeout (5 minutes)
188
+ retryAttempts: 3 // Retry failed executions
189
+ });
190
+
191
+ // Or configure providers individually
192
+ const customSandbox = e2b({
193
+ timeout: 600000, // 10 minutes
194
+ template: 'python-data-science'
195
+ });
196
+ ```
197
+
198
+ ## Examples
199
+
200
+ ### Data Processing
201
+
202
+ ```typescript
203
+ import { executeSandbox } from 'computesdk';
204
+ import { e2b } from '@computesdk/e2b';
205
+
206
+ const result = await executeSandbox({
207
+ sandbox: e2b(),
208
+ code: `
209
+ import pandas as pd
210
+ import numpy as np
211
+
212
+ # Create sample data
213
+ data = pd.DataFrame({
214
+ 'sales': [100, 150, 200, 120, 180],
215
+ 'profit': [20, 30, 45, 25, 40]
216
+ })
217
+
218
+ # Calculate metrics
219
+ total_sales = data['sales'].sum()
220
+ avg_profit = data['profit'].mean()
221
+ profit_margin = (data['profit'].sum() / total_sales) * 100
222
+
223
+ print(f"Total Sales: ${total_sales}")
224
+ print(f"Average Profit: ${avg_profit:.2f}")
225
+ print(f"Profit Margin: {profit_margin:.1f}%")
226
+ `
227
+ });
228
+
229
+ console.log(result.stdout);
230
+ ```
231
+
232
+ ### Web API Simulation
233
+
234
+ ```typescript
235
+ import { executeSandbox } from 'computesdk';
236
+ import { vercel } from '@computesdk/vercel';
237
+
238
+ const result = await executeSandbox({
239
+ sandbox: vercel({ runtime: 'node' }),
240
+ code: `
241
+ const express = require('express');
242
+ const app = express();
243
+
244
+ // Simulate API routes
245
+ const routes = {
246
+ '/api/users': { users: ['Alice', 'Bob', 'Charlie'] },
247
+ '/api/stats': { active: 150, total: 1000 }
248
+ };
249
+
250
+ // Process request
251
+ const path = '/api/users';
252
+ const response = routes[path] || { error: 'Not found' };
253
+
254
+ console.log('API Response:', JSON.stringify(response, null, 2));
255
+ `
256
+ });
257
+
258
+ console.log(result.stdout);
259
+ ```
260
+
261
+ ### Edge Computing
262
+
263
+ ```typescript
264
+ import { executeSandbox } from 'computesdk';
265
+ import { cloudflare } from '@computesdk/cloudflare';
266
+
267
+ // Within a Cloudflare Worker
268
+ export default {
269
+ async fetch(request: Request, env: Env): Promise<Response> {
270
+ const result = await executeSandbox({
271
+ sandbox: cloudflare({ env }),
272
+ code: `
273
+ import json
274
+ from datetime import datetime
275
+
276
+ # Process request data
277
+ data = {
278
+ "timestamp": datetime.now().isoformat(),
279
+ "region": "auto",
280
+ "processed": True
281
+ }
282
+
283
+ print(json.dumps(data))
284
+ `
285
+ });
286
+
287
+ return new Response(result.stdout, {
288
+ headers: { 'Content-Type': 'application/json' }
289
+ });
290
+ }
291
+ };
292
+ ```
293
+
294
+ ## Error Handling
295
+
296
+ ComputeSDK provides comprehensive error handling:
297
+
298
+ ```typescript
299
+ import {
300
+ ExecutionError,
301
+ TimeoutError,
302
+ AuthenticationError,
303
+ QuotaExceededError
304
+ } from 'computesdk';
305
+
306
+ try {
307
+ const result = await executeSandbox({
308
+ sandbox: e2b(),
309
+ code: 'print("Hello World")'
310
+ });
311
+ } catch (error) {
312
+ if (error instanceof TimeoutError) {
313
+ console.error('Execution timed out');
314
+ } else if (error instanceof AuthenticationError) {
315
+ console.error('Check your API credentials');
316
+ } else if (error instanceof QuotaExceededError) {
317
+ console.error('API quota exceeded');
318
+ } else if (error instanceof ExecutionError) {
319
+ console.error('Code execution failed:', error.stderr);
320
+ } else {
321
+ console.error('Unknown error:', error.message);
322
+ }
323
+ }
324
+ ```
325
+
326
+ ## Provider Comparison
327
+
328
+ | Provider | Runtimes | Max Timeout | Use Cases |
329
+ |----------|----------|-------------|-----------|
330
+ | E2B | Python | 5 minutes | Data science, AI/ML |
331
+ | Vercel | Node.js, Python | 45 minutes | Web apps, APIs |
332
+ | Cloudflare | Python, Node.js | 30 seconds | Edge computing, real-time |
333
+ | Fly.io | Custom | Variable | Custom containers |
334
+
335
+ ## Contributing
336
+
337
+ We welcome contributions! Please see our [Contributing Guide](https://github.com/computesdk/computesdk/blob/main/CONTRIBUTING.md) for details.
338
+
339
+ ### Adding New Providers
340
+
341
+ 1. Implement the `ComputeSpecification` interface
342
+ 2. Add comprehensive tests
343
+ 3. Include documentation and examples
344
+ 4. Submit a pull request
345
+
346
+ ## License
347
+
348
+ MIT - see [LICENSE](https://github.com/computesdk/computesdk/blob/main/LICENSE) for details.
349
+
350
+ ## Support
351
+
352
+ - [GitHub Issues](https://github.com/computesdk/computesdk/issues)
353
+ - [Documentation](https://github.com/computesdk/computesdk)
354
+ - [Examples](https://github.com/computesdk/computesdk/tree/main/examples)
355
+
356
+ ---
357
+
358
+ Made with ❤️ by the ComputeSDK team
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "computesdk",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Unified abstraction layer for executing code in secure, isolated sandboxed environments across multiple cloud providers",
5
5
  "author": "Garrison",
6
6
  "license": "MIT",
@@ -15,7 +15,8 @@
15
15
  }
16
16
  },
17
17
  "files": [
18
- "dist"
18
+ "dist",
19
+ "README.md"
19
20
  ],
20
21
  "scripts": {
21
22
  "build": "tsup",