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 CHANGED
@@ -1,6 +1,9 @@
1
1
  # computesdk
2
2
 
3
- The universal SDK for running code in remote sandboxes. Zero-config auto-detection with support for E2B, Modal, Railway, Daytona, Vercel, and more.
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
- ### Zero-Config Mode (Recommended)
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, use `setConfig()` to explicitly configure the provider:
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: 'your-provider',
44
- apiKey: process.env.COMPUTESDK_API_KEY,
45
- 'your-provider': {
46
- apiKey: process.env.YOUR_PROVIDER_API_KEY
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
- ComputeSDK automatically detects providers based on environment variables:
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** | `RAILWAY_TOKEN` | Full-stack deployments, persistent storage |
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** | `CLOUDFLARE_API_TOKEN` | Edge computing |
66
- | **CodeSandbox** | `CODESANDBOX_TOKEN` | Collaborative development |
96
+ | **Cloudflare** | `CLOUDFLARE_SANDBOX_URL`, `CLOUDFLARE_SANDBOX_SECRET` | Edge computing |
97
+ | **CodeSandbox** | `CSB_API_KEY` | Collaborative development |
67
98
 
68
- ### Provider Detection Order
99
+ Example imports:
69
100
 
70
- When using zero-config mode, ComputeSDK detects providers in this order:
71
-
72
- **E2B Railway Daytona → Modal → Runloop → Vercel → Cloudflare → CodeSandbox**
73
-
74
- You can force a specific provider:
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 the gateway with explicit provider settings.
114
+ Configure `compute` with `provider` or `providers`.
87
115
 
88
116
  ```typescript
89
117
  compute.setConfig({
90
- provider: 'your-provider',
91
- apiKey: process.env.COMPUTESDK_API_KEY,
92
- 'your-provider': {
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
- **Provider-specific configs:**
124
+ `compute(...)` callable mode is also supported:
99
125
 
100
126
  ```typescript
101
- // E2B
102
- compute.setConfig({
103
- provider: 'e2b',
104
- apiKey: process.env.COMPUTESDK_API_KEY,
105
- e2b: {
106
- apiKey: 'e2b_xxx',
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
- // Modal
112
- compute.setConfig({
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
- // Railway
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
- // Daytona
140
+ ```typescript
133
141
  compute.setConfig({
134
- provider: 'daytona',
135
- apiKey: process.env.COMPUTESDK_API_KEY,
136
- daytona: { apiKey: 'your_api_key' }
142
+ providers: [e2b({...}), modal({...})],
143
+ providerStrategy: 'priority', // default: 'priority'
144
+ fallbackOnError: true, // default: true
137
145
  });
146
+ ```
138
147
 
139
- // Vercel
148
+ You can also combine both `provider` and `providers`:
149
+
150
+ ```typescript
140
151
  compute.setConfig({
141
- provider: 'vercel',
142
- apiKey: process.env.COMPUTESDK_API_KEY,
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: 'e2b',
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: 'modal',
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 detected')) {
669
- console.error('Set provider credentials in environment variables');
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
- ## Direct Mode (Advanced)
682
+ ## Provider Packages (Advanced)
675
683
 
676
- For advanced use cases where you want to bypass the gateway and use provider SDKs directly, see individual provider packages:
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