-
Notifications
You must be signed in to change notification settings - Fork 46
Add OpenCode integration for Sandbox SDK #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Adds support for running OpenCode (AI coding agent) inside Sandbox containers with two usage patterns: 1. Programmatic SDK access via createOpencode(): - Returns typed client from @opencode-ai/sdk - Custom fetch adapter routes requests through container - Automatic server lifecycle management 2. Web UI proxy via proxyToOpencode(): - Exposes OpenCode's web interface through Workers - Handles localhost redirect for proper API routing Features: - Process reuse: detects existing OpenCode server on port - Provider auth: extracts API keys from config to env vars - Peer dependency on @opencode-ai/sdk (optional install) Includes example worker demonstrating both patterns.
🦋 Changeset detectedLatest commit: 1a9d1fe The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
🐳 Docker Images PublishedDefault (no Python): FROM cloudflare/sandbox:0.0.0-pr-282-9de5893With Python: FROM cloudflare/sandbox:0.0.0-pr-282-9de5893-pythonWith OpenCode: FROM cloudflare/sandbox:0.0.0-pr-282-9de5893-opencodeVersion: Use the |
Adds comprehensive documentation for the new OpenCode integration: - How-to guide covering both web UI and programmatic SDK usage - Complete API reference for createOpencode() and proxyToOpencode() - Configuration examples and error handling patterns - Production deployment considerations Related to cloudflare/sandbox-sdk#282 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Use `unknown` instead of `any` for dynamic SDK import - Add typed mock interfaces for Process and Sandbox in tests - Add tests for process reuse logic and API key extraction
Documents two usage patterns for running OpenCode AI coding agent inside Sandbox containers: - Web UI proxy with proxyToOpencode() for browser-based experience - Programmatic SDK access with createOpencode() for automation Includes configuration, error handling, and combined usage examples. Relates to cloudflare/sandbox-sdk#282
- Add -opencode Docker image variant with OpenCode CLI pre-installed - Handle concurrent startup attempts gracefully with retry logic - Add error handling in proxyToOpencode with proper error responses - Add OPENCODE_STARTUP_FAILED error code to shared error codes - Add logging throughout OpenCode server lifecycle - Use exact command matching for process detection - Add E2E tests for OpenCode CLI availability and server lifecycle - Update CI workflows to build -opencode image variant
c79d553 to
3c8d0e2
Compare
- Use @opencode-ai/sdk Config type instead of Record<string, unknown> - Fix API key extraction path (options.apiKey) - Add OpencodeStartupContext for structured error context - Remove Logger from public options (internal concern) - Add internal logging for debugging without exposing in API - Fix Sandbox<any> to Sandbox<unknown>
1b3340f to
b4eee16
Compare
b4eee16 to
3b748af
Compare
704dc49 to
dac1cc1
Compare
Refactors the integration to match OpenCode's own SDK structure with createOpencodeServer for server lifecycle and proxyToOpencode for web UI requests. Adds directory option and pre-clones sample project.
dac1cc1 to
c42a9e7
Compare
Adds comprehensive documentation for the new OpenCode integration feature: - API reference for createOpencodeServer(), createOpencode(), and proxyToOpencode() - How-to guide for both web UI and programmatic SDK access - Updated Dockerfile reference to document image variants (-opencode, -python) 🤖 Generated with Claude Code Synced from: cloudflare/sandbox-sdk#282 Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Validate that config.provider is an object before iterating, preventing crashes when users pass malformed config like strings or arrays. Add tests for proxyToOpencode redirect logic and malformed config handling.
Summary
Adds support for running OpenCode (AI coding agent) inside Sandbox containers with three functions:
createOpencodeServer()for server lifecycle managementcreateOpencode()for programmatic SDK access (server + typed client)proxyToOpencode()for web UI request proxyingUsage
Web UI proxy:
Programmatic SDK access:
Implementation details
sandbox.containerFetch()ANTHROPIC_API_KEYetc.)@opencode-ai/sdk(optional install)