Run OpenCode in a sandbox

Preview

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 models lists the models that your keys can use.
  • -m provider/model selects the model for one run.

With a subscription

GitHub Copilot (Pro, Pro+, Business or Enterprise):

  1. Connect to the sandbox over SSH.
  2. Run opencode auth login, and select GitHub Copilot.
  3. Open github.com/login/device, and type the code that OpenCode shows.

OpenCode Zen or OpenCode Go:

  1. Create a key at opencode.ai/auth.
  2. Put the key in the env of the sandbox as OPENCODE_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

  1. Put your Munito AI key in the env of the sandbox as MUNITO_API_KEY.
  2. 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 run runs one task with the build agent, and then it stops. It writes the answer to standard output.
  • --auto approves each permission that no rule denies. Then OpenCode runs commands and changes files with no question.
  • Without --auto, opencode run rejects each permission that asks.
  • -m provider/model selects the model for one run. Without it, OpenCode uses model from its configuration.
  • For a task of more than 30 minutes, start opencode run in the background with nohup, and read its log with later commands.

Use the terminal UI

  1. Add your public key with SSH.
  2. Connect with the command that GET /sandboxes/{sandbox_id}/ssh gives.
  3. Run opencode in /workspace.

To keep the session after you disconnect, install tmux (apt-get install -y tmux), and start OpenCode in it.