Skip to content

Repository files navigation

ComputeSDK
A unified SDK for running code in remote sandboxes.

npm versionTypeScriptLicense: MITDocumentation


What is ComputeSDK?

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

Quick Start

npm install computesdk

Set your provider credentials:

export E2B_API_KEY=your_api_key

Use 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.

Features

  • 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

Supported Providers

ComputeSDK automatically detects providers based on environment variables:

ProviderEnvironment Variables
E2BE2B_API_KEY
ModalMODAL_TOKEN_ID, MODAL_TOKEN_SECRET
RailwayRAILWAY_TOKEN
DaytonaDAYTONA_API_KEY
HopXHOPX_API_KEY
RunloopRUNLOOP_API_KEY
VercelVERCEL_TOKEN or VERCEL_OIDC_TOKEN
CloudflareCLOUDFLARE_API_TOKEN
CodeSandboxCODESANDBOX_TOKEN
just-bash(none - always available)

Detection order: E2B → Railway → Daytona → Modal → Runloop → Vercel → Cloudflare → CodeSandbox → just-bash

Configuration

Zero-Config Mode (Recommended)

Just set environment variables and ComputeSDK auto-detects everything:

export E2B_API_KEY=your_api_key
import{compute}from'computesdk';constsandbox=awaitcompute.sandbox.create();

Explicit Configuration

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();

Core API

Sandbox Management

// 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();

Code Execution

// 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']);

Filesystem Operations

// 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');

Example: Data Science Workflow

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();

Provider Packages

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:

Building Custom Providers

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}}});

Examples

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

Documentation

TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{Sandbox,SandboxInfo,CodeResult,CommandResult,CreateSandboxOptions}from'computesdk';

Contributing

ComputeSDK is open source and welcomes contributions!

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Community & Support

License

MIT License - see the LICENSE file for details.


Built with ❤️ by the ComputeSDK team

computesdk.com

About

A free and open-source toolkit for running other people's code in your applications.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages