Quick Start
Get a sandbox running in under five minutes.
1. Get your API key
Join the waitlist. We'll email you an API key when your spot is ready.
2. Install the SDK
- TypeScript
- Python
npm install @codecapsules/sandbox
Requires Node.js 18 or later.
pip install codecapsules-sandbox
Requires Python 3.9 or later.
3. Set your API key
export CODECAPSULES_API_KEY=your_api_key_here
Both SDKs read CODECAPSULES_API_KEY automatically. You can also pass it explicitly; see the API reference for each SDK.
4. Run your first command
- TypeScript
- Python
import { Sandbox } from '@codecapsules/sandbox';
await Sandbox.using(async (sb) => {
const r = await sb.exec('python --version');
console.log(r.stdout); // "Python 3.12.3\n"
console.log(r.exitCode); // 0
});
// sandbox deleted automatically
from codecapsules_sandbox import Sandbox
with Sandbox.create() as sb:
result = sb.exec("python --version")
print(result.stdout) # "Python 3.12.3\n"
print(result.exit_code) # 0
5. Install packages and run a script
- TypeScript
- Python
import { Sandbox } from '@codecapsules/sandbox';
import { readFileSync } from 'fs';
await Sandbox.using(async (sb) => {
// Install a dependency
await sb.exec('pip install httpx');
// Upload a script
await sb.upload('/workspace/fetch.py', readFileSync('./fetch.py'));
// Run it
const r = await sb.exec('python /workspace/fetch.py');
console.log(r.stdout);
// Download the output
const output = await sb.download('/workspace/result.json');
console.log(JSON.parse(Buffer.from(output).toString()));
});
from codecapsules_sandbox import Sandbox
import json
with Sandbox.create() as sb:
# Install a dependency
sb.exec("pip install httpx")
# Upload a script
sb.upload("/workspace/fetch.py", open("fetch.py", "rb").read())
# Run it
sb.exec("python /workspace/fetch.py")
# Download the output
raw = sb.download("/workspace/result.json")
result = json.loads(raw)
print(result)
Next steps
- Environments: choose the right flavor for your workload
- TypeScript SDK reference
- Python SDK reference