computesdk 2.5.4 → 2.6.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 +92 -84
- package/dist/index.d.mts +103 -429
- package/dist/index.d.ts +103 -429
- package/dist/index.js +281 -1017
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +280 -998
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# computesdk
|
|
2
2
|
|
|
3
|
-
The universal SDK for running code in remote sandboxes.
|
|
3
|
+
The universal SDK for running code in remote sandboxes.
|
|
4
|
+
|
|
5
|
+
> Gateway/control-plane transport has been removed from `computesdk`.
|
|
6
|
+
> Configure `compute` with `provider` or `providers`, or use provider packages directly.
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
@@ -10,18 +13,18 @@ npm install computesdk
|
|
|
10
13
|
|
|
11
14
|
## Quick Start
|
|
12
15
|
|
|
13
|
-
###
|
|
14
|
-
|
|
15
|
-
Set your provider credentials as environment variables and ComputeSDK automatically detects and configures everything:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
export E2B_API_KEY=your_e2b_api_key
|
|
19
|
-
```
|
|
16
|
+
### Direct Provider Mode (Recommended)
|
|
20
17
|
|
|
21
18
|
```typescript
|
|
22
19
|
import { compute } from 'computesdk';
|
|
20
|
+
import { e2b } from '@computesdk/e2b';
|
|
21
|
+
|
|
22
|
+
compute.setConfig({
|
|
23
|
+
provider: e2b({
|
|
24
|
+
apiKey: process.env.E2B_API_KEY,
|
|
25
|
+
}),
|
|
26
|
+
});
|
|
23
27
|
|
|
24
|
-
// Auto-detects E2B from environment
|
|
25
28
|
const sandbox = await compute.sandbox.create();
|
|
26
29
|
|
|
27
30
|
// Execute code
|
|
@@ -34,47 +37,72 @@ await sandbox.destroy();
|
|
|
34
37
|
|
|
35
38
|
### Explicit Configuration
|
|
36
39
|
|
|
37
|
-
For more control,
|
|
40
|
+
For more control, configure `compute` with an explicit provider:
|
|
38
41
|
|
|
39
42
|
```typescript
|
|
40
43
|
import { compute } from 'computesdk';
|
|
44
|
+
import { modal } from '@computesdk/modal';
|
|
41
45
|
|
|
42
46
|
compute.setConfig({
|
|
43
|
-
provider:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
provider: modal({
|
|
48
|
+
tokenId: process.env.MODAL_TOKEN_ID,
|
|
49
|
+
tokenSecret: process.env.MODAL_TOKEN_SECRET,
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const sandbox = await compute.sandbox.create();
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Multi-Provider Configuration
|
|
57
|
+
|
|
58
|
+
Configure multiple providers for resilience and routing:
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { compute } from 'computesdk';
|
|
62
|
+
import { e2b } from '@computesdk/e2b';
|
|
63
|
+
import { modal } from '@computesdk/modal';
|
|
64
|
+
|
|
65
|
+
compute.setConfig({
|
|
66
|
+
providers: [
|
|
67
|
+
e2b({ apiKey: process.env.E2B_API_KEY }),
|
|
68
|
+
modal({
|
|
69
|
+
tokenId: process.env.MODAL_TOKEN_ID,
|
|
70
|
+
tokenSecret: process.env.MODAL_TOKEN_SECRET,
|
|
71
|
+
}),
|
|
72
|
+
],
|
|
73
|
+
providerStrategy: 'round-robin', // or 'priority'
|
|
74
|
+
fallbackOnError: true,
|
|
48
75
|
});
|
|
49
76
|
|
|
77
|
+
// Uses configured strategy
|
|
50
78
|
const sandbox = await compute.sandbox.create();
|
|
79
|
+
|
|
80
|
+
// Force a specific provider for one call
|
|
81
|
+
const modalSandbox = await compute.sandbox.create({ provider: 'modal' });
|
|
51
82
|
```
|
|
52
83
|
|
|
53
84
|
## Supported Providers
|
|
54
85
|
|
|
55
|
-
|
|
86
|
+
Use provider packages directly to create provider instances:
|
|
56
87
|
|
|
57
88
|
| Provider | Environment Variables | Use Cases |
|
|
58
89
|
|----------|----------------------|-----------|
|
|
59
90
|
| **E2B** | `E2B_API_KEY` | Data science, Python/Node.js, interactive terminals |
|
|
60
91
|
| **Modal** | `MODAL_TOKEN_ID`, `MODAL_TOKEN_SECRET` | GPU computing, ML inference, Python workloads |
|
|
61
|
-
| **Railway** | `
|
|
92
|
+
| **Railway** | `RAILWAY_API_KEY`, `RAILWAY_PROJECT_ID`, `RAILWAY_ENVIRONMENT_ID` | Full-stack deployments, persistent storage |
|
|
62
93
|
| **Daytona** | `DAYTONA_API_KEY` | Development workspaces, custom environments |
|
|
63
94
|
| **Runloop** | `RUNLOOP_API_KEY` | Code execution, automation |
|
|
64
95
|
| **Vercel** | `VERCEL_TOKEN` or `VERCEL_OIDC_TOKEN` | Serverless functions, web apps |
|
|
65
|
-
| **Cloudflare** | `
|
|
66
|
-
| **CodeSandbox** | `
|
|
96
|
+
| **Cloudflare** | `CLOUDFLARE_SANDBOX_URL`, `CLOUDFLARE_SANDBOX_SECRET` | Edge computing |
|
|
97
|
+
| **CodeSandbox** | `CSB_API_KEY` | Collaborative development |
|
|
67
98
|
|
|
68
|
-
|
|
99
|
+
Example imports:
|
|
69
100
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```bash
|
|
77
|
-
export COMPUTESDK_PROVIDER=modal
|
|
101
|
+
```typescript
|
|
102
|
+
import { e2b } from '@computesdk/e2b';
|
|
103
|
+
import { modal } from '@computesdk/modal';
|
|
104
|
+
import { vercel } from '@computesdk/vercel';
|
|
105
|
+
import { daytona } from '@computesdk/daytona';
|
|
78
106
|
```
|
|
79
107
|
|
|
80
108
|
## API Reference
|
|
@@ -83,71 +111,51 @@ export COMPUTESDK_PROVIDER=modal
|
|
|
83
111
|
|
|
84
112
|
#### `compute.setConfig(config)`
|
|
85
113
|
|
|
86
|
-
Configure
|
|
114
|
+
Configure `compute` with `provider` or `providers`.
|
|
87
115
|
|
|
88
116
|
```typescript
|
|
89
117
|
compute.setConfig({
|
|
90
|
-
provider:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
apiKey: process.env.YOUR_PROVIDER_API_KEY
|
|
94
|
-
}
|
|
118
|
+
provider: e2b({
|
|
119
|
+
apiKey: process.env.E2B_API_KEY,
|
|
120
|
+
}),
|
|
95
121
|
});
|
|
96
122
|
```
|
|
97
123
|
|
|
98
|
-
|
|
124
|
+
`compute(...)` callable mode is also supported:
|
|
99
125
|
|
|
100
126
|
```typescript
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
templateId: 'optional_template'
|
|
108
|
-
}
|
|
127
|
+
const scopedCompute = compute({
|
|
128
|
+
provider: vercel({
|
|
129
|
+
token: process.env.VERCEL_TOKEN,
|
|
130
|
+
teamId: process.env.VERCEL_TEAM_ID,
|
|
131
|
+
projectId: process.env.VERCEL_PROJECT_ID,
|
|
132
|
+
}),
|
|
109
133
|
});
|
|
110
134
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
provider: 'modal',
|
|
114
|
-
apiKey: process.env.COMPUTESDK_API_KEY,
|
|
115
|
-
modal: {
|
|
116
|
-
tokenId: 'ak-xxx',
|
|
117
|
-
tokenSecret: 'as-xxx'
|
|
118
|
-
}
|
|
119
|
-
});
|
|
135
|
+
const sandbox = await scopedCompute.sandbox.create();
|
|
136
|
+
```
|
|
120
137
|
|
|
121
|
-
|
|
122
|
-
compute.setConfig({
|
|
123
|
-
provider: 'railway',
|
|
124
|
-
apiKey: process.env.COMPUTESDK_API_KEY,
|
|
125
|
-
railway: {
|
|
126
|
-
apiToken: 'your_token',
|
|
127
|
-
projectId: 'project_id',
|
|
128
|
-
environmentId: 'env_id'
|
|
129
|
-
}
|
|
130
|
-
});
|
|
138
|
+
Multi-provider config shape:
|
|
131
139
|
|
|
132
|
-
|
|
140
|
+
```typescript
|
|
133
141
|
compute.setConfig({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
providers: [e2b({...}), modal({...})],
|
|
143
|
+
providerStrategy: 'priority', // default: 'priority'
|
|
144
|
+
fallbackOnError: true, // default: true
|
|
137
145
|
});
|
|
146
|
+
```
|
|
138
147
|
|
|
139
|
-
|
|
148
|
+
You can also combine both `provider` and `providers`:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
140
151
|
compute.setConfig({
|
|
141
|
-
provider:
|
|
142
|
-
|
|
143
|
-
vercel: {
|
|
144
|
-
token: 'your_token',
|
|
145
|
-
teamId: 'team_xxx',
|
|
146
|
-
projectId: 'prj_xxx'
|
|
147
|
-
}
|
|
152
|
+
provider: e2b({...}), // primary provider (first choice)
|
|
153
|
+
providers: [modal({...})], // fallback/secondary providers
|
|
148
154
|
});
|
|
149
155
|
```
|
|
150
156
|
|
|
157
|
+
When both are present, `provider` is treated as the primary provider and is placed first.
|
|
158
|
+
|
|
151
159
|
### Sandbox Management
|
|
152
160
|
|
|
153
161
|
#### `compute.sandbox.create(options?)`
|
|
@@ -630,11 +638,12 @@ console.log('Complete output:', output);
|
|
|
630
638
|
|
|
631
639
|
```typescript
|
|
632
640
|
import { compute } from 'computesdk';
|
|
641
|
+
import { e2b } from '@computesdk/e2b';
|
|
642
|
+
import { modal } from '@computesdk/modal';
|
|
633
643
|
|
|
634
644
|
// Use E2B for data science
|
|
635
645
|
compute.setConfig({
|
|
636
|
-
provider:
|
|
637
|
-
e2b: { apiKey: process.env.E2B_API_KEY }
|
|
646
|
+
provider: e2b({ apiKey: process.env.E2B_API_KEY }),
|
|
638
647
|
});
|
|
639
648
|
|
|
640
649
|
const e2bSandbox = await compute.sandbox.create();
|
|
@@ -643,11 +652,10 @@ await e2bSandbox.destroy();
|
|
|
643
652
|
|
|
644
653
|
// Switch to Modal for GPU workloads
|
|
645
654
|
compute.setConfig({
|
|
646
|
-
provider:
|
|
647
|
-
modal: {
|
|
655
|
+
provider: modal({
|
|
648
656
|
tokenId: process.env.MODAL_TOKEN_ID,
|
|
649
|
-
tokenSecret: process.env.MODAL_TOKEN_SECRET
|
|
650
|
-
}
|
|
657
|
+
tokenSecret: process.env.MODAL_TOKEN_SECRET,
|
|
658
|
+
}),
|
|
651
659
|
});
|
|
652
660
|
|
|
653
661
|
const modalSandbox = await compute.sandbox.create();
|
|
@@ -665,15 +673,15 @@ try {
|
|
|
665
673
|
console.error('Execution failed:', error.message);
|
|
666
674
|
|
|
667
675
|
// Check for specific error types
|
|
668
|
-
if (error.message.includes('No provider
|
|
669
|
-
console.error('
|
|
676
|
+
if (error.message.includes('No provider instance configured')) {
|
|
677
|
+
console.error('Configure compute.setConfig({ provider: e2b({...}) }) first');
|
|
670
678
|
}
|
|
671
679
|
}
|
|
672
680
|
```
|
|
673
681
|
|
|
674
|
-
##
|
|
682
|
+
## Provider Packages (Advanced)
|
|
675
683
|
|
|
676
|
-
For advanced use cases where you want to
|
|
684
|
+
For advanced use cases where you want to use provider SDKs directly, see individual provider packages:
|
|
677
685
|
|
|
678
686
|
- **[@computesdk/e2b](../e2b)** - E2B provider
|
|
679
687
|
- **[@computesdk/modal](../modal)** - Modal provider
|