Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,3 @@ npm-debug.log*
# Rust
Cargo.lock
**/*.rs.bk

# CLI binaries (downloaded during npm publish)
sdks/cli/platforms/*/bin/
107 changes: 107 additions & 0 deletions docs/deploy/computesdk.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: "ComputeSDK"
description: "Deploy the daemon inside a ComputeSDK sandbox."
---

## Overview

ComputeSDK is a meta-SDK that provides a unified interface across multiple sandbox providers (E2B, Vercel, Modal, Railway, Daytona, and more). You can switch providers by changing environment variables without modifying your code.

## Prerequisites

- `COMPUTESDK_API_KEY` environment variable (get one at [console.computesdk.com](https://console.computesdk.com/register))
- A provider API key (e.g., `E2B_API_KEY`, `VERCEL_TOKEN`, `DAYTONA_API_KEY`)
- `ANTHROPIC_API_KEY` or `OPENAI_API_KEY` for the coding agents

## TypeScript Example

```typescript
import { compute } from "computesdk";
import { SandboxAgent } from "sandbox-agent";

// Pass API keys to the sandbox
const envs: Record<string, string> = {};
if (process.env.ANTHROPIC_API_KEY) envs.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
if (process.env.OPENAI_API_KEY) envs.OPENAI_API_KEY = process.env.OPENAI_API_KEY;

// Create sandbox with sandbox-agent server pre-configured
const sandbox = await compute.sandbox.create({
envs,
servers: [
{
slug: "sandbox-agent",
install:
"curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh && " +
"sandbox-agent install-agent claude && " +
"sandbox-agent install-agent codex",
start: "sandbox-agent server --no-token --host 0.0.0.0 --port 3000",
port: 3000,
environment: envs,
health_check: {
path: "/v1/health",
interval_ms: 2000,
},
},
],
});

// Connect to the server
const baseUrl = await sandbox.getUrl({ port: 3000 });
const client = await SandboxAgent.connect({ baseUrl });

// Wait for server to be ready
await client.waitForHealth();

// Create a session and start coding
await client.createSession("my-session", {
agent: "claude",
permissionMode: "default",
});

await client.postMessage("my-session", {
message: "Summarize this repository",
});

for await (const event of client.streamEvents("my-session")) {
console.log(event.type, event.data);
}

// Cleanup
await sandbox.destroy();
```

## Provider Flexibility

ComputeSDK automatically detects your provider based on environment variables. To switch providers, simply change which API key you set:

```bash
# Use E2B
export E2B_API_KEY=your_e2b_key

# Or use Vercel
export VERCEL_TOKEN=your_vercel_token
export VERCEL_TEAM_ID=your_team_id
export VERCEL_PROJECT_ID=your_project_id

# Or use Daytona
export DAYTONA_API_KEY=your_daytona_key

# And always set ComputeSDK key
export COMPUTESDK_API_KEY=your_computesdk_key
```

Your code stays the same regardless of which provider you choose.

## Supported Providers

ComputeSDK supports the following providers:
- E2B
- Vercel
- Daytona
- Modal
- Railway
- Render
- Blaxel
- Namespace

See the [ComputeSDK documentation](https://computesdk.com/docs) for provider-specific setup instructions.
21 changes: 21 additions & 0 deletions examples/computesdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@sandbox-agent/example-computesdk",
"private": true,
"type": "module",
"scripts": {
"start": "tsx src/computesdk.ts",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"computesdk": "latest",
"dotenv": "^16.0.0",
"@sandbox-agent/example-shared": "workspace:*",
"sandbox-agent": "workspace:*"
},
"devDependencies": {
"@types/node": "latest",
"tsx": "latest",
"typescript": "latest",
"vitest": "^3.0.0"
}
}
47 changes: 47 additions & 0 deletions examples/computesdk/src/computesdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import "dotenv/config";
import { compute } from "computesdk";
import { runPrompt, waitForHealth } from "@sandbox-agent/example-shared";

const envs: Record<string, string> = {};
if (process.env.ANTHROPIC_API_KEY) envs.ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY;
if (process.env.OPENAI_API_KEY) envs.OPENAI_API_KEY = process.env.OPENAI_API_KEY;

console.log("Creating ComputeSDK sandbox...");
const sandbox = await compute.sandbox.create({
envs,
servers: [
{
slug: "sandbox-agent",
install:
"curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh && " +
"sandbox-agent install-agent claude && " +
"sandbox-agent install-agent codex",
start: "sandbox-agent server --no-token --host 0.0.0.0 --port 3000",
port: 3000,
environment: envs,
health_check: {
path: "/v1/health",
interval_ms: 2000,
timeout_ms: 5000,
delay_ms: 3000,
},
restart_policy: "on-failure",
max_restarts: 3,
},
],
});

const baseUrl = await sandbox.getUrl({ port: 3000 });

console.log("Waiting for server...");
await waitForHealth({ baseUrl });

const cleanup = async () => {
await sandbox.destroy();
process.exit(0);
};
process.once("SIGINT", cleanup);
process.once("SIGTERM", cleanup);

await runPrompt(baseUrl);
await cleanup();
28 changes: 28 additions & 0 deletions examples/computesdk/tests/computesdk.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, it, expect } from "vitest";
import { buildHeaders } from "@sandbox-agent/example-shared";
import { setupComputeSDKSandboxAgent } from "../src/computesdk.ts";

const shouldRun = Boolean(process.env.COMPUTESDK_API_KEY);
const timeoutMs = Number.parseInt(process.env.SANDBOX_TEST_TIMEOUT_MS || "", 10) || 300_000;

const testFn = shouldRun ? it : it.skip;

describe("computesdk example", () => {
testFn(
"starts sandbox-agent and responds to /v1/health",
async () => {
const { baseUrl, token, cleanup } = await setupComputeSDKSandboxAgent();
try {
const response = await fetch(`${baseUrl}/v1/health`, {
headers: buildHeaders({ token }),
});
expect(response.ok).toBe(true);
const data = await response.json();
expect(data.status).toBe("ok");
} finally {
await cleanup();
}
},
timeoutMs
);
});
16 changes: 16 additions & 0 deletions examples/computesdk/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"allowImportingTsExtensions": true,
"noEmit": true,
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
Loading