ComputeSDK provides a consistent TypeScript interface for executing code in remote sandboxes. Whether you're using E2B for data science, Modal for GPU workloads, or Vercel for serverless functions - ComputeSDK provides one unified API.
Perfect for:
- 🤖 AI code execution agents
- 📊 Data science platforms
- 🎓 Educational coding environments
- 🧪 Testing & CI/CD systems
- 🔧 Developer tools
npm install computesdkSet your provider credentials:
export E2B_API_KEY=your_api_keyUse the SDK:
import{compute}from'computesdk';// Auto-detects E2B from environmentconstsandbox=awaitcompute.sandbox.create();constresult=awaitsandbox.runCode('print("Hello World!")');console.log(result.stdout);// "Hello World!"awaitsandbox.destroy();That's it! No provider configuration needed.
- ⚡ Zero-config mode - Auto-detect provider from environment variables
- 🔄 Multi-provider support - E2B, Modal, Railway, Daytona, Vercel, and more
- 📁 Filesystem operations - Read, write, create directories across providers
- 🖥️ Command execution - Run shell commands in sandboxes
- 🛡️ Type-safe - Full TypeScript support with comprehensive error handling
- 🔧 Extensible - Easy to add custom providers via @computesdk/provider
ComputeSDK automatically detects providers based on environment variables:
| Provider | Environment Variables |
|---|---|
| E2B | E2B_API_KEY |
| Modal | MODAL_TOKEN_ID, MODAL_TOKEN_SECRET |
| Railway | RAILWAY_TOKEN |
| Daytona | DAYTONA_API_KEY |
| HopX | HOPX_API_KEY |
| Runloop | RUNLOOP_API_KEY |
| Vercel | VERCEL_TOKEN or VERCEL_OIDC_TOKEN |
| Cloudflare | CLOUDFLARE_API_TOKEN |
| CodeSandbox | CODESANDBOX_TOKEN |
| just-bash | (none - always available) |
Detection order: E2B → Railway → Daytona → Modal → Runloop → Vercel → Cloudflare → CodeSandbox → just-bash
Just set environment variables and ComputeSDK auto-detects everything:
export E2B_API_KEY=your_api_keyimport{compute}from'computesdk';constsandbox=awaitcompute.sandbox.create();For more control, use setConfig():
import{compute}from'computesdk';compute.setConfig({computesdkApiKey: 'your_computesdk_api_key',provider: 'e2b',e2b: {apiKey: 'your_api_key'}});constsandbox=awaitcompute.sandbox.create();Switch providers at runtime:
// Use E2B for data sciencecompute.setConfig({computesdkApiKey: 'your_computesdk_api_key',provider: 'e2b',e2b: {apiKey: process.env.E2B_API_KEY}});conste2bSandbox=awaitcompute.sandbox.create();awaite2bSandbox.runCode('import pandas as pd');awaite2bSandbox.destroy();// Switch to Modal for GPU workloadscompute.setConfig({computesdkApiKey: 'your_computesdk_api_key',provider: 'modal',modal: {tokenId: process.env.MODAL_TOKEN_ID,tokenSecret: process.env.MODAL_TOKEN_SECRET}});constmodalSandbox=awaitcompute.sandbox.create();awaitmodalSandbox.runCode('import torch; print(torch.cuda.is_available())');awaitmodalSandbox.destroy();// Create sandboxconstsandbox=awaitcompute.sandbox.create();// Create with optionsconstsandbox=awaitcompute.sandbox.create({runtime: 'python',timeout: 300000,metadata: {userId: '123'}});// Get existing sandboxconstsandbox=awaitcompute.sandbox.getById('sandbox-id');// List sandboxesconstsandboxes=awaitcompute.sandbox.list();// Destroy sandboxawaitsandbox.destroy();// Execute codeconstresult=awaitsandbox.runCode('print("Hello")','python');console.log(result.stdout);console.log(result.stderr);console.log(result.exitCode);// Run shell commandsconstresult=awaitsandbox.runCommand('npm',['install','express']);// Write fileawaitsandbox.filesystem.writeFile('/tmp/hello.py','print("Hello")');// Read fileconstcontent=awaitsandbox.filesystem.readFile('/tmp/hello.py');// Create directoryawaitsandbox.filesystem.mkdir('/tmp/data');// List directoryconstfiles=awaitsandbox.filesystem.readdir('/tmp');// Check if existsconstexists=awaitsandbox.filesystem.exists('/tmp/hello.py');// Removeawaitsandbox.filesystem.remove('/tmp/hello.py');import{compute}from'computesdk';constsandbox=awaitcompute.sandbox.create({runtime: 'python'});// Create project structureawaitsandbox.filesystem.mkdir('/analysis');awaitsandbox.filesystem.mkdir('/analysis/data');// Write input dataconstcsvData=`name,age,cityAlice,25,New YorkBob,30,San Francisco`;awaitsandbox.filesystem.writeFile('/analysis/data/people.csv',csvData);// Process dataconstresult=awaitsandbox.runCode(`import pandas as pddf = pd.read_csv('/analysis/data/people.csv')print(f"Average age: {df['age'].mean()}")# Save resultsresults = {'average_age': df['age'].mean()}import jsonwith open('/analysis/results.json', 'w') as f: json.dump(results, f)`);console.log(result.stdout);// Read resultsconstresults=awaitsandbox.filesystem.readFile('/analysis/results.json');console.log('Results:',JSON.parse(results));awaitsandbox.destroy();For direct SDK usage without the gateway, install individual provider packages:
npm install @computesdk/e2b # E2B provider
npm install @computesdk/modal # Modal provider
npm install @computesdk/railway # Railway provider
npm install @computesdk/daytona # Daytona provider
npm install @computesdk/vercel # Vercel provider
npm install @computesdk/just-bash # Local bash sandbox (no auth needed)Direct mode usage:
import{e2b}from'@computesdk/e2b';constcompute=e2b({apiKey: 'your_api_key'});constsandbox=awaitcompute.sandbox.create();See individual provider READMEs for details:
- @computesdk/e2b - Data science, Python/Node.js, terminals
- @computesdk/modal - GPU computing, ML inference
- @computesdk/railway - Full-stack deployments
- @computesdk/daytona - Development workspaces
- @computesdk/vercel - Serverless functions
- @computesdk/just-bash - Local bash sandbox with virtual filesystem (no auth required)
Want to add support for a new compute provider? See @computesdk/provider for the provider framework:
import{defineProvider}from'@computesdk/provider';exportconstmyProvider=defineProvider({name: 'my-provider',defaultMode: 'direct',methods: {sandbox: {create: async(config,options)=>{// Your implementation},// ... other methods}}});Check out the examples directory for complete implementations:
- Next.js - API routes with ComputeSDK
- Nuxt - Server API integration
- SvelteKit - Endpoints with ComputeSDK
- Remix - Loader/action integration
- Astro - API endpoints
- 📖 Full Documentation - Complete guides and API reference
- 🚀 Getting Started - Quick setup guide
- 🎯 Providers - Provider-specific documentation
Full TypeScript support with comprehensive type definitions:
importtype{Sandbox,SandboxInfo,CodeResult,CommandResult,CreateSandboxOptions}from'computesdk';ComputeSDK is open source and welcomes contributions!
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- 💬 GitHub Discussions - Ask questions and share ideas
- 🐛 GitHub Issues - Report bugs and request features
MIT License - see the LICENSE file for details.
Built with ❤️ by the ComputeSDK team