Skip to main content
OpenCode is an open-source coding agent that supports multiple LLM providers. E2B provides a pre-built opencode template with OpenCode already installed.

CLI

Create a sandbox with the E2B CLI.
Once inside the sandbox, start OpenCode.

Run headless

Use opencode 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-built opencode template.
Run the build script to create the template.

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