Run OpenCode in a sandbox with the API key of a model provider, a subscription that OpenCode supports, or the open models of Munito AI.
Sign in
Use one of these three methods.
With the API key of a provider
Put the key in the env of the sandbox, in the usual variable of the provider:
{
"ANTHROPIC_API_KEY": "sk-ant-..."
}opencode modelslists the models that your keys can use.-m provider/modelselects the model for one run.
With a subscription
GitHub Copilot (Pro, Pro+, Business or Enterprise):
- Connect to the sandbox over SSH.
- Run
opencode auth login, and select GitHub Copilot. - Open github.com/login/device, and type the code that OpenCode shows.
OpenCode Zen or OpenCode Go:
- Create a key at opencode.ai/auth.
- Put the key in the
envof the sandbox asOPENCODE_API_KEY.
- OpenCode keeps a sign-in in
~/.local/share/opencode/auth.json. - Anthropic does not allow a Claude subscription in OpenCode. For Claude, use Claude Code.
- For a ChatGPT plan, use Codex.
- See providers in the OpenCode docs.
With the open models of Munito AI
- Put your Munito AI key in the
envof the sandbox asMUNITO_API_KEY. - Write this configuration to
~/.config/opencode/opencode.json, with the files API or a command:
{
"$schema": "https://opencode.ai/config.json",
"model": "munito/zai-org/glm-5.3-flash",
"provider": {
"munito": {
"npm": "@ai-sdk/openai-compatible",
"name": "Munito",
"options": {
"baseURL": "https://api.munito.ai/inference/v1",
"apiKey": "{env:MUNITO_API_KEY}"
},
"models": {
"zai-org/glm-5.3-flash": {
"name": "GLM-5.3-Flash",
"limit": {
"context": 1048576,
"output": 943718
}
}
}
}
}
}{env:MUNITO_API_KEY}reads the key from the environment, so the file holds no key.- OpenCode with open models explains the provider, the reasoning effort and the regional hosts.
Run a task
curl -sS --fail-with-body "https://api.munito.ai/sandboxes/v1/sandboxes/$SANDBOX/exec" \
-H "Authorization: Bearer $MUNITO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"command": "cd /workspace && opencode run --auto \"Write a Python script that prints the first 10 primes, and run it\"", "timeout": 1800}'opencode runruns one task with thebuildagent, and then it stops. It writes the answer to standard output.--autoapproves each permission that no rule denies. Then OpenCode runs commands and changes files with no question.- Without
--auto,opencode runrejects each permission that asks. -m provider/modelselects the model for one run. Without it, OpenCode usesmodelfrom its configuration.- For a task of more than 30 minutes, start
opencode runin the background withnohup, and read its log with later commands.
Use the terminal UI
- Add your public key with SSH.
- Connect with the command that
GET /sandboxes/{sandbox_id}/sshgives. - Run
opencodein/workspace.
To keep the session after you disconnect, install tmux (apt-get install -y tmux), and start OpenCode in it.