OpenCode
Run OpenCode in a sandbox from the prebuilt opencode template, with the LLM provider of your choice. Use it headless, or serve it over HTTP and drive it from the OpenCode SDK.
- E2B
- Prebuilt opencode sandbox template
- e2b
- TypeScript, Python
Get started
Paste the prompt into your coding agent, or follow the steps yourself.
Paste this into your coding agent
Run OpenCode in an E2B sandbox from this project.
- 1.Install the e2b SDK using the project's package manager.
- 2.The SDK needs the E2B_API_KEY environment variable, and OpenCode needs an LLM provider key such as ANTHROPIC_API_KEY. If E2B_API_KEY isn't set, ask me for my API key from https://console.e2b.dev/?tab=keys. Never hardcode either key.
- 3.Follow the OpenCode guide at https://docs.e2b.dev/agents/opencode: create a sandbox from the opencode template, pass the provider key in envs, and run opencode run "<task>" headless. Kill the sandbox when it's done.
- 4.Run one task and show me the output that came from the sandbox.
Or set it up yourself
1. Install the E2B SDK
2. Set your API keys
3. Run OpenCode headless
4. Or serve it over HTTP
What runs in the sandbox
OpenCode and the commands it runs live in the sandbox, away from your machine.
- OpenCode with any provider it supports. Pass ANTHROPIC_API_KEY, OPENAI_API_KEY or GEMINI_API_KEY in envs.
- The repo you clone and every change OpenCode makes. Read the result back with git diff.
- opencode serve exposes its HTTP API on a sandbox port you reach through getHost().
- Set onTimeout to pause and the sandbox pauses at its timeout instead of being killed, so you can resume it.
More coding agents
Other coding agents that run in E2B sandboxes.
- Claude CodeRun Claude Code in its own sandbox with a real filesystem, terminal, and git, so it can work unattended.
- OpenAI CodexRun OpenAI's Codex CLI headless in a sandbox and collect the diff when it's done.
- PiRun the Pi coding agent in a sandbox, or keep Pi local and send its tool calls to E2B with @e2b/pi.
