
Research
/Security News
Mini Shai-Hulud Campaign Hits Red Hat Cloud Services npm Packages
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.
computesdk
Advanced tools
A free and open-source toolkit for running other people's code in your applications.
The universal SDK for running code in remote sandboxes.
Gateway/control-plane transport has been removed from
computesdk. Configurecomputewithproviderorproviders, or use provider packages directly.
npm install computesdk
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();
// Execute code
const result = await sandbox.runCommand('python -c "print(\"Hello World!\")"');
console.log(result.stdout); // "Hello World!"
// Clean up
await sandbox.destroy();
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: 'round-robin', // or 'priority'
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' });
compute.setConfig(config)Configure compute with provider or providers.
compute.setConfig({
provider: e2b({
apiKey: process.env.E2B_API_KEY,
}),
});
compute(...) callable mode is also supported:
const scopedCompute = compute({
provider: vercel({
token: process.env.VERCEL_TOKEN,
teamId: process.env.VERCEL_TEAM_ID,
projectId: process.env.VERCEL_PROJECT_ID,
}),
});
const sandbox = await scopedCompute.sandbox.create();
Multi-provider config shape:
compute.setConfig({
providers: [e2b({...}), modal({...})],
providerStrategy: 'priority', // default: 'priority'
fallbackOnError: true, // default: true
});
You can also combine both provider and providers:
compute.setConfig({
provider: e2b({...}), // primary provider (first choice)
providers: [modal({...})], // fallback/secondary providers
});
When both are present, provider is treated as the primary provider and is placed first.
compute.sandbox.create(options?)Create a new sandbox.
const sandbox = await compute.sandbox.create();
// With options
const sandbox = await compute.sandbox.create({
timeout: 300000, // 5 minutes
metadata: { userId: '123' },
namespace: 'my-org',
name: 'my-sandbox',
});
Options:
timeout?: number - Timeout in millisecondsmetadata?: Record<string, any> - Custom metadataenvs?: Record<string, string> - Environment variablesnamespace?: string - Namespace for organizing sandboxesname?: string - Human-readable name for the sandboxNote: Not every provider honors every option. Support for fields like
name,metadata, andenvsdepends on the underlying provider SDK — some pass them through, some map them to a different field, and some ignore them silently. Check your provider package's README for the exact set of options it respects.
compute.sandbox.getById(sandboxId)Get an existing sandbox by ID.
const sandbox = await compute.sandbox.getById('sandbox-id');
sandbox.runCommand(command, options?)Run a shell command.
const result = await sandbox.runCommand('npm install express');
console.log(result.stdout);
console.log(result.exitCode);
// With options
const result = await sandbox.runCommand('npm install', {
cwd: '/app',
env: { NODE_ENV: 'production' },
background: true,
});
sandbox.destroy()Destroy the sandbox and clean up resources.
await sandbox.destroy();
The sandbox provides full filesystem access:
sandbox.filesystem.writeFile(path, content)Write a file to the sandbox.
await sandbox.filesystem.writeFile('/tmp/hello.py', 'print("Hello World")');
sandbox.filesystem.readFile(path)Read a file from the sandbox.
const content = await sandbox.filesystem.readFile('/tmp/hello.py');
console.log(content); // 'print("Hello World")'
sandbox.filesystem.mkdir(path)Create a directory.
await sandbox.filesystem.mkdir('/tmp/mydir');
sandbox.filesystem.readdir(path)List directory contents.
const files = await sandbox.filesystem.readdir('/tmp');
console.log(files); // [{ name: 'hello.py', type: 'file', size: 123 }, ...]
sandbox.filesystem.exists(path)Check if a file or directory exists.
const exists = await sandbox.filesystem.exists('/tmp/hello.py');
console.log(exists); // true
sandbox.filesystem.remove(path)Remove a file or directory.
await sandbox.filesystem.remove('/tmp/hello.py');
import { compute } from 'computesdk';
const sandbox = await compute.sandbox.create();
// Create project structure
await sandbox.filesystem.mkdir('/app');
await sandbox.filesystem.mkdir('/app/src');
// Write package.json
await sandbox.filesystem.writeFile('/app/package.json', JSON.stringify({
name: 'my-app',
version: '1.0.0',
dependencies: {
'express': '^4.18.0'
}
}, null, 2));
// Write source code
await sandbox.filesystem.writeFile('/app/src/index.js', `
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.json({ message: 'Hello World!' });
});
console.log('Server ready!');
`);
// Install dependencies
const installResult = await sandbox.runCommand('npm install', { cwd: '/app' });
console.log('Install:', installResult.stdout);
// Run the app
const runResult = await sandbox.runCommand('node src/index.js', { cwd: '/app' });
console.log(runResult.stdout);
await sandbox.destroy();
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; print(pd.__version__)"');
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();
try {
const sandbox = await compute.sandbox.create();
const result = await sandbox.runCommand('invalid python code');
} catch (error) {
console.error('Execution failed:', error.message);
// Check for specific error types
if (error.message.includes('No provider instance configured')) {
console.error('Configure compute.setConfig({ provider: e2b({...}) }) first');
}
}
For advanced use cases where you want to use provider SDKs directly, see individual provider packages:
Example direct mode usage:
import { e2b } from '@computesdk/e2b';
const compute = e2b({ apiKey: 'your_api_key' });
const sandbox = await compute.sandbox.create();
Want to add support for a new compute provider? See @computesdk/provider for the provider framework and documentation on building custom providers.
Full TypeScript support with comprehensive type definitions:
import type {
Sandbox,
SandboxInfo,
CodeResult,
CommandResult,
CreateSandboxOptions
} from 'computesdk';
MIT
FAQs
A free and open-source toolkit for running other people's code in your applications.
The npm package computesdk receives a total of 6,816 weekly downloads. As such, computesdk popularity was classified as popular.
We found that computesdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.

Research
/Security News
The North Korean malware loader hides in a Packagist-listed package and its GitHub branch to fetch and execute remote code in a likely Contagious Interview-style lure.

Security News
The Rust project is moving toward formal rules on LLM use in contributions after months of internal debate over maintainer burden, code quality, and contributor experience.