Full TypeScript SDK for building on top of OpenCode
1import { getSandbox } from '@cloudflare/sandbox';2import { createOpencode } from '@cloudflare/sandbox/opencode';34// Get a sandbox container and start OpenCode server inside it5const sandbox = getSandbox(env.Sandbox, "opencode");6const { client } = await createOpencode(sandbox, {7 directory: '/home/user/project',8 config: { provider: { anthropic: { options: { apiKey: env.ANTHROPIC_API_KEY } } } },9});1011// Create a session and send a prompt12const session = await client.session.create({ body: { title: "My Session" } });13const result = await client.session.prompt({14 path: { id: session.data.id },15 body: {16 model: { providerID: "anthropic", modelID: "claude-sonnet-4" },17 parts: [{ type: "text", text: "Summarize the README." }],18 },19});2021console.log(result.data?.parts?.find((p) => p.type === "text")?.text);