RepositoryTypeScriptUSUnited States
computesdk

computesdk/computesdk

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

304stars
161forks
18issues
3views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: ai-runtime

#1 Repository of the week

1
TINIX TRENDING·Topic: ai-sandboxes

#1 Repository of the week

3
TINIX TRENDING·Topic: code-execution

#3 Repository of the week

ComputeSDK
A unified SDK for running code in remote sandboxes.

npm version TypeScript License: MIT Documentation


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 @computesdk/e2b

Configure a provider and use the SDK:

import { compute } from 'computesdk';
import { e2b } from '@computesdk/e2b';

compute.setConfig({
  provider: e2b({ apiKey: process.env.E2B_API_KEY }),
});

const sandbox = await compute.sandbox.create();

const result = await sandbox.runCommand('python -c "print(\'Hello World!\')"');
console.log(result.stdout); // "Hello World!"

await sandbox.destroy();

Features

  • 🔄 Multi-provider support - E2B, Modal, Daytona, Vercel, and more
  • 📁 Filesystem operations - Read, write, create directories across providers
  • 🖥️ Command execution - Run shell commands in sandboxes
  • 🧵 Terminals - Interactive (PTY) and exec-mode command tracking
  • 🛡️ Type-safe - Full TypeScript support with comprehensive error handling
  • 🔧 Extensible - Easy to add custom providers via @computesdk/provider

Supported Providers

Install provider packages and pass instances into compute.setConfig:

ProviderEnvironment VariablesUse Cases
E2BE2B_API_KEYData science, Python/Node.js, interactive terminals
ModalMODAL_TOKEN_ID, MODAL_TOKEN_SECRETGPU computing, ML inference
DaytonaDAYTONA_API_KEYDevelopment workspaces
RunloopRUNLOOP_API_KEYCode execution, automation
VercelVERCEL_TOKEN or VERCEL_OIDC_TOKENServerless functions
CloudflareCLOUDFLARE_SANDBOX_URL, CLOUDFLARE_SANDBOX_SECRETEdge computing
CodeSandboxCSB_API_KEYCollaborative development
TensorlakeTENSORLAKE_API_KEYStateful MicroVM sandboxes
RailwayRAILWAY_API_TOKEN, RAILWAY_ENVIRONMENT_IDEphemeral command execution sandboxes

Configuration

Direct Provider Mode

Pass a provider instance directly to setConfig():

import { compute } from 'computesdk';
import { e2b } from '@computesdk/e2b';

compute.setConfig({
  provider: e2b({ apiKey: process.env.E2B_API_KEY }),
});

const sandbox = await compute.sandbox.create();

Multi-Provider Configuration

Configure multiple providers for resilience and routing:

import { compute } from 'computesdk';
import { e2b } from '@computesdk/e2b';
import { modal } from '@computesdk/modal';

compute.setConfig({
  providers: [
    e2b({ apiKey: process.env.E2B_API_KEY }),
    modal({
      tokenId: process.env.MODAL_TOKEN_ID,
      tokenSecret: process.env.MODAL_TOKEN_SECRET,
    }),
  ],
  providerStrategy: 'priority', // or 'round-robin'
  fallbackOnError: true,
});

// Uses configured strategy
const sandbox = await compute.sandbox.create();

// Force a specific provider for one call
const modalSandbox = await compute.sandbox.create({ provider: 'modal' });

Switching Providers at Runtime

import { compute } from 'computesdk';
import { e2b } from '@computesdk/e2b';
import { modal } from '@computesdk/modal';

// Use E2B for data science
compute.setConfig({
  provider: e2b({ apiKey: process.env.E2B_API_KEY }),
});

const e2bSandbox = await compute.sandbox.create();
await e2bSandbox.runCommand('python -c "import pandas as pd"');
await e2bSandbox.destroy();

// Switch to Modal for GPU workloads
compute.setConfig({
  provider: modal({
    tokenId: process.env.MODAL_TOKEN_ID,
    tokenSecret: process.env.MODAL_TOKEN_SECRET,
  }),
});

const modalSandbox = await compute.sandbox.create();
await modalSandbox.runCommand('python -c "import torch; print(torch.cuda.is_available())"');
await modalSandbox.destroy();

Core API

Sandbox Management

// Create sandbox
const sandbox = await compute.sandbox.create();

// Create with options
const sandbox = await compute.sandbox.create({
  runtime: 'python',
  timeout: 300000,
  metadata: { userId: '123' }
});

// Get existing sandbox
const sandbox = await compute.sandbox.getById('sandbox-id');

// List sandboxes
const sandboxes = await compute.sandbox.list();

// Destroy sandbox
await sandbox.destroy();

Command Execution

// Execute Python code
const result = await sandbox.runCommand('python -c "print(\'Hello\')"');
console.log(result.stdout);
console.log(result.exitCode);

// Run shell commands
const cmd = await sandbox.runCommand('npm install express');
console.log(cmd.stdout);
console.log(cmd.exitCode);

Filesystem Operations

// Write file
await sandbox.filesystem.writeFile('/tmp/hello.py', 'print("Hello")');

// Read file
const content = await sandbox.filesystem.readFile('/tmp/hello.py');

// Create directory
await sandbox.filesystem.mkdir('/tmp/data');

// List directory
const files = await sandbox.filesystem.readdir('/tmp');

// Check if exists
const exists = await sandbox.filesystem.exists('/tmp/hello.py');

// Remove
await sandbox.filesystem.remove('/tmp/hello.py');

Example: Data Science Workflow

import { compute } from 'computesdk';

const sandbox = await compute.sandbox.create({ runtime: 'python' });

// Create project structure
await sandbox.filesystem.mkdir('/analysis');
await sandbox.filesystem.mkdir('/analysis/data');

// Write input data
const csvData = `name,age,city
Alice,25,New York
Bob,30,San Francisco`;

await sandbox.filesystem.writeFile('/analysis/data/people.csv', csvData);

// Write the analysis script
await sandbox.filesystem.writeFile('/analysis/analyze.py', `
import json
import pandas as pd

df = pd.read_csv('/analysis/data/people.csv')
print(f"Average age: {df['age'].mean()}")

results = {'average_age': df['age'].mean()}
with open('/analysis/results.json', 'w') as f:
    json.dump(results, f)
`);

// Run it
const result = await sandbox.runCommand('python /analysis/analyze.py');
console.log(result.stdout);

// Read results
const results = await sandbox.filesystem.readFile('/analysis/results.json');
console.log('Results:', JSON.parse(results));

await sandbox.destroy();

Provider Packages

Install the provider packages you need and pass their instances into compute.setConfig:

npm install @computesdk/e2b        # E2B provider
npm install @computesdk/modal      # Modal provider
npm install @computesdk/daytona    # Daytona provider
npm install @computesdk/vercel     # Vercel provider
npm install @computesdk/tensorlake # Tensorlake provider
npm install @computesdk/railway    # Railway provider
npm install @computesdk/just-bash  # Local bash sandbox (no auth needed)

You can also use a provider's callable form directly, bypassing compute.setConfig:

import { e2b } from '@computesdk/e2b';

const e2bCompute = e2b({ apiKey: process.env.E2B_API_KEY });
const sandbox = await e2bCompute.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';

export const myProvider = defineProvider({
  name: 'my-provider',
  defaultMode: 'direct',
  methods: {
    sandbox: {
      create: async (config, options) => {
        // Your implementation
      },
      // ... other methods
    }
  }
});

Documentation

TypeScript Support

Full TypeScript support with comprehensive type definitions:

import type { 
  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

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
langgenius/dify

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

162.3k
Dec 2, 2026
RepositoryTypeScript
morluto/rea

Reverse engineer anything with agents, from app behavior down to native binaries.

487.0k
Dec 2, 2026
Repository
daytonaio/daytona

Daytona is a Secure and Elastic Infrastructure for Running AI-Generated Code

71.3k
Jul 24, 2026
RepositoryPython
Significant-Gravitas/AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

188.2k
Nov 29, 2026
RepositoryTypeScript
freeCodeCamp/freeCodeCamp

freeCodeCamp.org's open-source codebase and curriculum. Learn math, programming, and computer science for free.

459.9k
Dec 2, 2026
Repository
justjavac/free-programming-books-zh_CN

:books: 免费的计算机编程类中文书籍,欢迎投稿

119.7k
Jul 29, 2026
RepositoryPython
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

379.9k
Sep 15, 2026
RepositoryPython
practical-tutorials/project-based-learning

Curated list of project-based tutorials

290.9k
Nov 30, 2026
RepositoryJavaScript
react/react

The library for web and native user interfaces.

253.0k
Nov 30, 2026