OpenCode

Open-source multi-provider CLI coding agent with external launch verification and Keychain-backed secret injection.

Last updated

Cloud API TypeScript

1. Installation

Prerequisites

  • A platform supported by the current OpenCode release
  • API key for at least one provider (Anthropic, OpenAI, Google, xAI, Groq)

Install OpenCode

brew install opencode

Install the preferred stack

brew tap nvk/tap
brew install nvk/tap/agent-bondage
brew install nvk/tap/envchain-xtra
brew install nono

Observed on 2026-10-26: Homebrew OpenCode 2.1.4, agent-bondage 0.3.1, envchain-xtra 1.4.1, and upstream nono 0.80.0. OpenCode 2 is no longer the Go-era tool described by the older version of this page.

Verify

opencode --version
bondage --version
nono --version
envchain --help  # prints the version header

2. nono Profile

OpenCode's global config is ~/.config/opencode/opencode.json; provider credentials added through /connect live separately under ~/.local/share/opencode/auth.json. In the preferred API-key setup, bondage verifies the OpenCode target first, envchain-xtra injects only the chosen provider keys, and nono limits what the process can touch beyond the project directory.

What the sandbox allows

ResourceAccessWhy
Current working directoryRead + WriteProject files
~/.config/opencode/ReadGlobal config, skills, plugins, and commands
API endpointsNetworkProvider API calls
/dev/tty, /dev/nullRead + WriteTerminal I/O
/dev/urandomReadCrypto randomness
Current config behavior: OpenCode 2 supports {env:VARIABLE_NAME} substitution. Keep the real value in envchain or another secret manager; the config should contain only the variable reference. If the variable is missing, substitution produces an empty string.
Network caveat: Nono filesystem restrictions do not automatically filter outbound traffic. Select a network profile, allowed domains, credential routes, or full network blocking and verify the effective policy.

3. envchain-xtra

OpenCode supports many providers. Put only the provider credentials this profile actually needs in its envchain-xtra namespace; do not turn one convenience namespace into a bag of every model key you own.

Store your API keys

# Example: store only the providers used by this profile
envchain --set opencode ANTHROPIC_API_KEY
envchain --set opencode OPENAI_API_KEY

Provider-specific environment names and authentication methods change. Confirm the current OpenCode provider page for the exact integration, then use that name consistently in envchain and the {env:...} reference. For interactive credentials, use /connect and confirm configured accounts with opencode auth list.

Minimal config file (no secret values)

// ~/.config/opencode/opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "anthropic": {
      "settings": {
        "apiKey": "{env:ANTHROPIC_API_KEY}"
      }
    }
  }
}

4. bondage Wrapper

Add this thin wrapper to your shell config:

opencode() {
  bondage exec opencode ~/.config/bondage/bondage.conf -- "$@"
}

Sample stack snippets

Assuming your shared [global] block already exists in ~/.config/bondage/bondage.conf, this is a script-backed OpenCode shape to adapt:

# ~/.config/bondage/bondage.conf
[profile "opencode"]
namespace = opencode
use_envchain = true
use_nono = true
nono_profile = opencode
touch_policy = prompt
target_kind = script
target = /absolute/path/to/opencode/bin/opencode
target_fp = sha256:replace-me
interpreter = /absolute/path/to/node
interpreter_fp = sha256:replace-me
package_root = /absolute/path/to/opencode
package_tree_fp = sha256:replace-me
nono_allow_cwd = true
nono_allow_file = /dev/tty
nono_allow_file = /dev/null
nono_read_file = /dev/urandom
{
  "extends": "opencode",
  "meta": {
    "name": "opencode",
    "description": "OpenCode with project-only access and envchain-backed provider keys"
  },
  "policy": {
    "add_deny_access": ["/Volumes"]
  },
  "workdir": {
    "access": "readwrite"
  }
}

How it works

The sequence is:

  1. The shell wrapper passes only the profile name and your arguments
  2. bondage verifies the exact OpenCode target
  3. envchain-xtra resolves Keychain lookups before the sandbox applies
  4. nono applies Seatbelt/Landlock restrictions
  5. OpenCode reads provider keys from env vars — no plaintext file access needed

Reload your shell:

source ~/.zshrc

5. Verification

Test the full chain

bondage verify opencode ~/.config/bondage/bondage.conf
bondage chain opencode ~/.config/bondage/bondage.conf -- --help
opencode --help

Confirm the chosen credential path

# Lists configured provider accounts without printing secret values
opencode auth list

If this profile is envchain-only, do not duplicate the same key through /connect. Keep opencode.json limited to {env:...} references and other non-secret settings.

Troubleshooting

SymptomCauseFix
"Invalid authentication credentials" Environment variable missing, wrong provider name, or stale /connect account Check opencode auth list, verify the envchain namespace, and keep the supported {env:...} reference
Provider or model missing Account not connected or provider restricted by config policy Run /connect or inject the documented environment variable, then inspect enabled/disabled provider settings
"Operation not permitted" nono blocking a path Check nono why for denied access
Shell name → bondage → envchain-xtra → nono → OpenCode Convenience Launch policy Secret release Kernel sandbox Actual agent