opencode template with OpenCode already installed.
CLI
Create a sandbox with the E2B CLI.Run headless
Useopencode run for non-interactive mode. Pass your LLM provider’s API key as an environment variable — OpenCode supports ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY, and others.
Example: work on a cloned repository
Connect with the OpenCode SDK
OpenCode includes a headless HTTP server that you can control programmatically using the@opencode-ai/sdk client. Start the server inside a sandbox, get the public URL with sandbox.getHost(), and connect from your application.
Build a custom template
If you need to customize the environment (e.g. pre-install dependencies, add config files), build your own template on top of the pre-builtopencode template.
Related guides
Sandbox persistence
Auto-pause, resume, and manage sandbox lifecycle
Git integration
Clone repos, manage branches, and push changes
SSH access
Connect to the sandbox via SSH for interactive sessions