sandbox-agent

โดย rivet-dev

API สากลสำหรับการจัดระเบียบเอเจนต์เขียนโค้ด AI หลายตัวในสภาพแวดล้อมแบบแซนด์บ็อกซ์ รองรับเอเจนต์เขียนโค้ดสี่ตัว (Claude Code, Codex, OpenCode, Amp) ด้วยสคีมาแบบรวมสำหรับการตอบสนอง เหตุการณ์ และการจัดการเซสชัน ปรับใช้ในเครื่องหรือบนคลาวด์แซนด์บ็อกซ์ รวมถึง E2B, Daytona, Docker, Vercel และ Cloudflare พร้อมการกำหนดค่าตามสภาพแวดล้อม สตรีมเหตุการณ์ของเอเจนต์ จัดการความคงอยู่ของเซสชันข้ามแบ็กเอนด์หลายตัว (ในหน่วยความจำ, SQLite, Postgres, IndexedDB) และจัดการการทำงานแบบมนุษย์ในวงจร...

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

Skills เพิ่มเติมจาก rivet-dev

rivetkit-actors
rivet-dev
สร้างแบ็กเอนด์ที่มีสถานะด้วย Rivet Actors: โปรเซสประสิทธิภาพสูง อายุยืนยาว ในหน่วยความจำ และคงอยู่ ใช้เมื่อคุณเติบโตเกินกว่า HTTP, ฐานข้อมูล หรือคิว…
official
agent-browser
rivet-dev
ทำให้การโต้ตอบกับเบราว์เซอร์เป็นอัตโนมัติสำหรับการทดสอบเว็บ การกรอกฟอร์ม การจับภาพหน้าจอ และการดึงข้อมูล ใช้เมื่อผู้ใช้ต้องการนำทางเว็บไซต์ โต้ตอบกับเว็บ…
official
multiplayer-game
rivet-dev
รูปแบบเชิงปฏิบัติสำหรับการสร้างเกมผู้เล่นหลายคน: การจับคู่ผู้เล่น, ลูปการทำงานแบบติ๊ก, สถานะแบบเรียลไทม์, การจัดการความสนใจ และการตรวจสอบความถูกต้อง รวมถึงโค้ดเริ่มต้นและรูปแบบสถาปัตยกรรมสำหรับเกม 10 ประเภท (แบทเทิลรอยัล, อารีน่า, สไตล์ IO, โลกเปิด, ปาร์ตี้, ฟิสิกส์ 2D/3D, แบบจัดอันดับ, ผลัดกันเล่น, แบบไม่ได้เล่น) พร้อมโทโพโลยีของตัวละคร, แผนภาพวงจรชีวิต และกลยุทธ์เน็ตโค้ด ครอบคลุมพื้นฐานการจำลองเซิร์ฟเวอร์: ลูปเรียลไทม์แบบคงที่เทียบกับการอัปเดตที่ขับเคลื่อนด้วยการกระทำ, การเลือกเอ็นจิ้นฟิสิกส์ (
official
rivetkit
rivet-dev
การคำนวณแบบมีสถานะและอายุยืนสำหรับเอเจนต์ AI แอปผู้เล่นหลายคน และระบบอัตโนมัติของเวิร์กโฟลว์ แอคเตอร์เป็นกระบวนการในหน่วยความจำที่คงอยู่ซึ่งรักษาสถานะข้ามคำขอโดยไม่ต้องไปกลับฐานข้อมูล พร้อมการปรับขนาดอัตโนมัติจากศูนย์ไปจนถึงหลายล้านอินสแตนซ์พร้อมกัน มีการสื่อสารแบบเรียลไทม์ในตัวผ่าน WebSockets และอีเวนต์ คิวที่ทนทานสำหรับการประมวลผลข้อความตามลำดับ และ SQLite สำหรับการค้นหาข้อมูลที่มีโครงสร้าง สถานะคงอยู่ข้ามการรีสตาร์ทและการขัดข้องผ่าน Rivet Cloud หรือโฮสต์เอง...
official
rivetkit-actors
rivet-dev
สร้างแบ็กเอนด์ที่มีสถานะด้วย Rivet Actors: โปรเซสประสิทธิภาพสูง อายุยืนยาว ในหน่วยความจำ และคงอยู่ ใช้เมื่อคุณเติบโตเกินกว่า HTTP, ฐานข้อมูล หรือคิว…
official
rivetkit-client-javascript
rivet-dev
ไคลเอนต์ JavaScript สำหรับเชื่อมต่อกับ Rivet Actors ด้วยการเชื่อมต่อแบบไร้สถานะหรือมีสถานะ รองรับสภาพแวดล้อมเบราว์เซอร์ Node.js และ Bun พร้อมการตรวจจับเอนด์พอยต์อัตโนมัติผ่านตัวแปรสภาพแวดล้อมหรือการกำหนดค่าแบบชัดเจน มีโหมดการโต้ตอบสองแบบ: การเรียกแอคชันแบบไร้สถานะสำหรับคำขออิสระ และการเชื่อมต่อแบบมีสถานะพร้อมการสมัครรับเหตุการณ์แบบเรียลไทม์ รวมถึงการเข้าถึง HTTP และ WebSocket ระดับต่ำสำหรับแอคเตอร์ที่ใช้ตัวจัดการ onRequest หรือ onWebSocket ให้การเข้าถึงแบบอาร์เรย์ผสม...
official
rivetkit-client-react
rivet-dev
React client สำหรับเชื่อมต่อกับ Rivet Actors โดยใช้ hooks และการจัดการสถานะแบบเรียลไทม์ สร้าง typed hooks ด้วย createRivetKit() และเชื่อมต่อกับอินสแตนซ์ของ actor โดยใช้ useActor() พร้อม keys และพารามิเตอร์เสริม สมัครรับอีเวนต์ของ actor ด้วย useEvent() และตรวจสอบวงจรการเชื่อมต่อผ่านสถานะ connStatus และ error states ใช้ createClient() สำหรับการเรียกแบบ stateless แบบครั้งเดียว, วิธีการค้นหา actor (get, getOrCreate, create, getForId), และการเข้าถึง HTTP/WebSocket ระดับต่ำ รองรับ compound array keys...
official
rivetkit-client-swift
rivet-dev
Swift client สำหรับเชื่อมต่อกับ Rivet Actors ที่มีโหมดการเชื่อมต่อแบบ stateless และ stateful รองรับทั้งการเรียก action แบบ stateless และการเชื่อมต่อ WebSocket แบบถาวรพร้อมการสตรีมเหตุการณ์แบบเรียลไทม์ผ่าน AsyncStream มีการเรียก action แบบระบุชนิดด้วยอาร์กิวเมนต์ตำแหน่ง 0–5 ตัว พร้อมทางเลือก JSON ดิบสำหรับจำนวนอาร์กิวเมนต์ที่มากขึ้น รวมถึงการตรวจสอบวงจรการเชื่อมต่อผ่านสตรีมสถานะ ข้อผิดพลาด การเปิด และการปิด รองรับการเข้าถึง HTTP และ WebSocket ระดับต่ำสำหรับ onRequest แบบกำหนดเองและ...
official