sandbox-agent

bởi rivet-dev

API phổ quát để điều phối nhiều tác nhân mã hóa AI trong môi trường sandbox. Hỗ trợ bốn tác nhân mã hóa (Claude Code, Codex, OpenCode, Amp) với lược đồ thống nhất cho phản hồi, sự kiện và quản lý phiên. Triển khai cục bộ hoặc lên cloud sandbox bao gồm E2B, Daytona, Docker, Vercel và Cloudflare với cấu hình theo môi trường. Truyền phát sự kiện tác nhân, quản lý duy trì phiên trên nhiều backend (in-memory, SQLite, Postgres, IndexedDB) và xử lý vòng lặp có sự tham gia của con người...

npx skills add https://github.com/rivet-dev/skills --skill sandbox-agent

Sandbox Agent

Sandbox Agent provides a universal API for orchestrating AI coding agents in sandboxed environments.

What To Do If You Get Stuck

If something is not working as intended or you are stuck, prompt the user to join the Rivet Discord or file an issue on GitHub to report an issue and get help.

Provide the user with a pre-generated report with:

  • Symptoms
    • If this is happening in local dev, deployed, or both
    • The error you're seeing
    • Relevant source code related to this
  • What you've tried to solve it
  • Environment
    • Sandbox Agent version
    • SDK in use (TypeScript, Python, or HTTP)
    • Agent in use (Claude Code, Codex, OpenCode, Amp, Mock)
    • Sandbox provider (E2B, Daytona, Docker, local)

Quickstart

Install skill (optional)

npx

npx skills add rivet-dev/skills -s sandbox-agent

bunx

bunx skills add rivet-dev/skills -s sandbox-agent

Set environment variables

Each coding agent requires API keys to connect to their respective LLM providers.

Local shell

export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."

E2B

import { Sandbox } from "@e2b/code-interpreter";

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;

const sandbox = await Sandbox.create({ envs });

Daytona

import { Daytona } from "@daytonaio/sdk";

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

const daytona = new Daytona();
const sandbox = await daytona.create({
  snapshot: "sandbox-agent-ready",
  envVars,
});

Docker

docker run -p 2468:2468 \
  -e ANTHROPIC_API_KEY="sk-ant-..." \
  -e OPENAI_API_KEY="sk-..." \
  rivetdev/sandbox-agent:0.4.2-full \
  server --no-token --host 0.0.0.0 --port 2468

Extracting API keys from current machine

Use sandbox-agent credentials extract-env --export to extract your existing API keys (Anthropic, OpenAI, etc.) from local Claude Code or Codex config files.

Testing without API keys

Use the mock agent for SDK and integration testing without provider credentials.

Multi-tenant and per-user billing

For per-tenant token tracking, budget enforcement, or usage-based billing, see LLM Credentials for gateway options like OpenRouter, LiteLLM, and Portkey.

Run the server

curl

Install and run the binary directly.

curl -fsSL https://releases.rivet.dev/sandbox-agent/0.4.x/install.sh | sh
sandbox-agent server --no-token --host 0.0.0.0 --port 2468

npx

Run without installing globally.

npx @sandbox-agent/[email protected] server --no-token --host 0.0.0.0 --port 2468

bunx

Run without installing globally.

bunx @sandbox-agent/[email protected] server --no-token --host 0.0.0.0 --port 2468

npm i -g

Install globally, then run.

npm install -g @sandbox-agent/[email protected]
sandbox-agent server --no-token --host 0.0.0.0 --port 2468

bun add -g

Install globally, then run.

bun add -g @sandbox-agent/[email protected]
# Allow Bun to run postinstall scripts for native binaries (required for SandboxAgent.start()).
bun pm -g trust @sandbox-agent/cli-linux-x64 @sandbox-agent/cli-linux-arm64 @sandbox-agent/cli-darwin-arm64 @sandbox-agent/cli-darwin-x64 @sandbox-agent/cli-win32-x64
sandbox-agent server --no-token --host 0.0.0.0 --port 2468

Node.js (local)

For local development, use SandboxAgent.start() to spawn and manage the server as a subprocess.

npm install [email protected]
import { SandboxAgent } from "sandbox-agent";

const sdk = await SandboxAgent.start();

Bun (local)

For local development, use SandboxAgent.start() to spawn and manage the server as a subprocess.

bun add [email protected]
# Allow Bun to run postinstall scripts for native binaries (required for SandboxAgent.start()).
bun pm trust @sandbox-agent/cli-linux-x64 @sandbox-agent/cli-linux-arm64 @sandbox-agent/cli-darwin-arm64 @sandbox-agent/cli-darwin-x64 @sandbox-agent/cli-win32-x64
import { SandboxAgent } from "sandbox-agent";

const sdk = await SandboxAgent.start();

Build from source

If you're running from source instead of the installed CLI.

cargo run -p sandbox-agent -- server --no-token --host 0.0.0.0 --port 2468

Binding to 0.0.0.0 allows the server to accept connections from any network interface, which is required when running inside a sandbox where clients connect remotely.

Configuring token

Tokens are usually not required. Most sandbox providers (E2B, Daytona, etc.) already secure networking at the infrastructure layer.

If you expose the server publicly, use --token "$SANDBOX_TOKEN" to require authentication:

sandbox-agent server --token "$SANDBOX_TOKEN" --host 0.0.0.0 --port 2468

Then pass the token when connecting:

TypeScript

import { SandboxAgent } from "sandbox-agent";

const sdk = await SandboxAgent.connect({
  baseUrl: "http://your-server:2468",
  token: process.env.SANDBOX_TOKEN,
});

curl

curl "http://your-server:2468/v1/health" \
  -H "Authorization: Bearer $SANDBOX_TOKEN"

CLI

sandbox-agent --token "$SANDBOX_TOKEN" api agents list \
  --endpoint http://your-server:2468

CORS

If you're calling the server from a browser, see the CORS configuration guide.

Install agents (optional)

To preinstall agents:

sandbox-agent install-agent --all

If agents are not installed up front, they are lazily installed when creating a session.

Install desktop dependencies (optional, Linux only)

If you want to use /v1/desktop/*, install the desktop runtime packages first:

sandbox-agent install desktop --yes

Then use GET /v1/desktop/status or sdk.getDesktopStatus() to verify the runtime is ready before calling desktop screenshot or input APIs.

Create a session

import { SandboxAgent } from "sandbox-agent";

const sdk = await SandboxAgent.connect({
  baseUrl: "http://127.0.0.1:2468",
});

const session = await sdk.createSession({
  agent: "claude",
  sessionInit: {
    cwd: "/",
    mcpServers: [],
  },
});

console.log(session.id);

Send a message

const result = await session.prompt([
  { type: "text", text: "Summarize the repository and suggest next steps." },
]);

console.log(result.stopReason);

Read events

const off = session.onEvent((event) => {
  console.log(event.sender, event.payload);
});

const page = await sdk.getEvents({
  sessionId: session.id,
  limit: 50,
});

console.log(page.items.length);
off();

Test with Inspector

Open the Inspector UI at /ui/ on your server (for example, http://localhost:2468/ui/) to inspect sessions and events in a GUI.

Sandbox Agent Inspector

Next steps

  • Session Persistence — Configure in-memory, Rivet Actor state, IndexedDB, SQLite, and Postgres persistence.

  • Deploy to a Sandbox — Deploy your agent to E2B, Daytona, Docker, Vercel, or Cloudflare.

  • SDK Overview — Use the latest TypeScript SDK API.

Reference Map

Agents

AI

Deploy

General

Thêm skills từ rivet-dev

rivetkit-actors
rivet-dev
Xây dựng backend có trạng thái với Rivet Actors: các tiến trình hiệu suất cao, tồn tại lâu dài, trong bộ nhớ, được duy trì. Sử dụng khi bạn vượt quá giới hạn của HTTP, cơ sở dữ liệu hoặc hàng đợi.…
official
agent-browser
rivet-dev
Tự động hóa các tương tác trình duyệt để kiểm thử web, điền biểu mẫu, chụp ảnh màn hình và trích xuất dữ liệu. Sử dụng khi người dùng cần điều hướng trang web, tương tác với web…
official
multiplayer-game
rivet-dev
Các mẫu thiết kế thực tế để xây dựng trò chơi nhiều người chơi: ghép trận, vòng lặp tick, trạng thái thời gian thực, quản lý tương tác và xác thực. Bao gồm mã khởi đầu và các mẫu kiến trúc cho 10 thể loại trò chơi (battle royale, đấu trường, phong cách IO, thế giới mở, tiệc, vật lý 2D/3D, xếp hạng, theo lượt, nhàn rỗi) với cấu trúc tác nhân, sơ đồ vòng đời và chiến lược mạng. Đề cập đến các nguyên tắc cơ bản của mô phỏng máy chủ: vòng lặp thời gian thực cố định so với cập nhật theo
official
rivetkit
rivet-dev
Tính toán có trạng thái, tồn tại lâu dài cho các tác nhân AI, ứng dụng đa người chơi và tự động hóa quy trình làm việc. Các tác nhân là các tiến trình trong bộ nhớ liên tục duy trì trạng thái qua các yêu cầu mà không cần truy vấn cơ sở dữ liệu, với khả năng tự động mở rộng từ 0 đến hàng triệu phiên bản đồng thời. Tích hợp sẵn giao tiếp thời gian thực qua WebSockets và sự kiện, hàng đợi bền vững để xử lý tin nhắn theo thứ tự, và SQLite cho các truy vấn dữ liệu có cấu trúc. Trạng thái tồn tại qua các lần khởi động lại và sự cố th
official
rivetkit-actors
rivet-dev
Xây dựng backend có trạng thái với Rivet Actors: các tiến trình hiệu suất cao, tồn tại lâu dài, trong bộ nhớ, được duy trì. Sử dụng khi bạn vượt quá giới hạn của HTTP, cơ sở dữ liệu hoặc hàng đợi.…
official
rivetkit-client-javascript
rivet-dev
Máy khách JavaScript để kết nối với Rivet Actors qua kết nối không trạng thái hoặc có trạng thái. Hỗ trợ môi trường trình duyệt, Node.js và Bun với tính năng tự động phát hiện điểm cuối qua biến môi trường hoặc cấu hình tường minh. Cung cấp hai chế độ tương tác: gọi hành động không trạng thái cho các yêu cầu độc lập và kết nối có trạng thái với đăng ký sự kiện thời gian thực. Bao gồm truy cập HTTP và WebSocket cấp thấp cho các actor triển khai trình xử lý onRequest hoặc onWebSocket. Cung cấp mảng dựa trên hợp chất...
official
rivetkit-client-react
rivet-dev
Trình kết nối React để kết nối với Rivet Actors bằng hooks và quản lý trạng thái thời gian thực. Tạo hooks có kiểu với createRivetKit() và kết nối đến các phiên bản actor bằng useActor() với khóa và tham số tùy chọn. Đăng ký sự kiện actor với useEvent() và theo dõi vòng đời kết nối qua các trạng thái connStatus và error. Sử dụng createClient() cho các lệnh gọi một lần không trạng thái, các phương thức khám phá actor (get, getOrCreate, create, getForId), và truy cập HTTP/WebSocket cấp thấp. Hỗ trợ khóa mảng phức hợp...
official
rivetkit-client-swift
rivet-dev
Trình kết nối Swift để kết nối với Rivet Actors với các chế độ kết nối không trạng thái và có trạng thái. Hỗ trợ cả lệnh gọi hành động không trạng thái và kết nối WebSocket liên tục với luồng sự kiện thời gian thực qua AsyncStream. Cung cấp lệnh gọi hành động có kiểu với 0–5 đối số vị trí, cùng với dự phòng JSON thô cho số lượng đối số lớn hơn. Bao gồm giám sát vòng đời kết nối thông qua các luồng thay đổi trạng thái, lỗi, mở và đóng. Hỗ trợ truy cập HTTP và WebSocket cấp thấp cho onRequest tùy chỉnh và...
official