Skip to content
GitHub Get Started
Reference

OpenCode Compatibility

Sandbox Agent exposes an OpenCode-compatible API at /opencode.

Why use OpenCode clients with Sandbox Agent?

Section titled “Why use OpenCode clients with Sandbox Agent?”
  • OpenCode CLI (opencode attach)
  • OpenCode web UI
  • OpenCode TypeScript SDK (@opencode-ai/sdk)
Terminal window
sandbox-agent opencode --port 2468 --no-token

Or start server + attach manually:

Terminal window
sandbox-agent server --no-token --host 127.0.0.1 --port 2468
opencode attach http://localhost:2468/opencode

With authentication enabled:

Terminal window
sandbox-agent server --token "$SANDBOX_TOKEN" --host 127.0.0.1 --port 2468
opencode attach http://localhost:2468/opencode --password "$SANDBOX_TOKEN"
  1. Start Sandbox Agent with CORS

    Terminal window
    sandbox-agent server --no-token --host 127.0.0.1 --port 2468 --cors-allow-origin http://127.0.0.1:5173
  2. Run OpenCode web app

    Terminal window
    git clone https://github.com/anomalyco/opencode
    cd opencode/packages/app
    export VITE_OPENCODE_SERVER_HOST=127.0.0.1
    export VITE_OPENCODE_SERVER_PORT=2468
    bun install
    bun run dev -- --host 127.0.0.1 --port 5173
  3. Open UI

    Visit http://127.0.0.1:5173/.

import { createOpencodeClient } from "@opencode-ai/sdk";
const client = createOpencodeClient({
baseUrl: "http://localhost:2468/opencode",
});
const session = await client.session.create();
await client.session.promptAsync({
path: { id: session.data.id },
body: {
parts: [{ type: "text", text: "Hello, write a hello world script" }],
},
});
const events = await client.event.subscribe({});
for await (const event of events.stream) {
console.log(event);
}
  • API base path: /opencode
  • If server auth is enabled, pass bearer auth (or --password in OpenCode CLI)
  • For browser UIs, configure CORS with --cors-allow-origin
  • Provider selector currently exposes compatible providers (mock, amp, claude, codex)
  • Provider/model metadata for compatibility endpoints is normalized and may differ from native OpenCode grouping
  • Optional proxy: set OPENCODE_COMPAT_PROXY_URL to forward selected endpoints to native OpenCode
Endpoint Status Table
EndpointStatusNotes
GET /eventSession/message updates (SSE)
GET /global/eventGlobalEvent-wrapped stream
GET /sessionSession list
POST /sessionCreate session
GET /session/{id}Session details
POST /session/{id}/messageSend message
GET /session/{id}/messageSession messages
GET /permissionPending permissions
POST /permission/{id}/replyPermission reply
GET /questionPending questions
POST /question/{id}/replyQuestion reply
GET /providerProvider metadata
GET /commandProxied when OPENCODE_COMPAT_PROXY_URL is set; otherwise stub
GET /configProxied when set; otherwise stub
PATCH /configProxied when set; otherwise local compatibility behavior
GET /global/configProxied when set; otherwise stub
PATCH /global/configProxied when set; otherwise local compatibility behavior
/tui/*Proxied when set; otherwise local compatibility behavior
GET /agentAgent list
other endpointsEmpty/stub responses

✓ Functional ↔ Proxied optional − Stubbed