> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sazabi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCode sandbox CLI

> Give the Sazabi agent the OpenCode CLI (opencode) in its sandbox to run the OpenCode AI coding agent.

[All OpenCode integration capabilities](https://docs.sazabi.com/catalogs/integrations/opencode)

## About

This CLI connection makes the OpenCode CLI (`opencode`) available in the Sazabi agent's sandbox. The CLI is already installed in the sandbox; connecting it configures the CLI with your OpenCode config and, optionally, your provider credentials.

OpenCode supports many model providers. Your config chooses the default provider and model, and the credentials you add let the agent call it.

## Prerequisites

* A Sazabi project.

* An OpenCode config (`OPENCODE_CONFIG_CONTENT`, required): a JSON object that sets the default `model` and any provider config. Use the [OpenCode provider docs](https://opencode.ai/docs/providers/) to choose a provider and model. For example:

  ```json theme={"system"}
  {
    "$schema": "https://opencode.ai/config.json",
    "model": "anthropic/claude-sonnet-4-5"
  }
  ```

* Credentials for the provider your config uses. These fields are optional when you connect, but `opencode run` fails without them:
  * `OPENCODE_AUTH_JSON`: the contents of `~/.local/share/opencode/auth.json` from a machine where you already ran `/connect` in OpenCode.
  * Or an API key: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY` (Gemini), or `OPENROUTER_API_KEY`.

## Set up in the dashboard

Configure the sandbox in the dashboard under [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis).

**Step 1**

### Find OpenCode in the catalog

In [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis), find OpenCode under **Browse sandbox CLIs** and choose to connect it.

**Step 2**

### Choose provider and model

Paste your config JSON into **OpenCode config JSON**. You can include advanced provider options directly in this config if OpenCode requires them.

**Step 3**

### Add provider keys

Paste your OpenCode `auth.json` into **OpenCode auth JSON**, or fill in the API key fields for the providers your config references. Add only the credentials you want available in the sandbox, then save.

Before saving, Sazabi checks only that the config (and the auth JSON, if you provided it) is valid JSON. Provider credentials are first used when the agent runs `opencode`.

## Set up with the CLI

You can also configure the OpenCode CLI connection with the [Sazabi CLI](https://docs.sazabi.com/reference/cli.md) (installed and authenticated; see [CLI reference](https://docs.sazabi.com/reference/cli/sandbox-clis.md)).

```bash theme={"system"}
sazabi sandbox-clis connect opencode \
  --env OPENCODE_CONFIG_CONTENT="$(cat opencode.json)" \
  --env ANTHROPIC_API_KEY=<your-anthropic-key>
```

To reuse a local OpenCode sign-in instead of an API key, pass your `auth.json`:

```bash theme={"system"}
sazabi sandbox-clis connect opencode \
  --env OPENCODE_CONFIG_CONTENT="$(cat opencode.json)" \
  --env OPENCODE_AUTH_JSON="$(cat ~/.local/share/opencode/auth.json)"
```

`connect` runs the same JSON check first, and a failed check saves nothing. To check values without saving, run the same command with `test` in place of `connect` (the test command also requires the `--env` flags). You can also load values from a file with `--env-file <path>`.

## Verify

In a thread, ask the agent to run `opencode run "Reply with exactly: opencode-ok"` and show the output. The check passes when the thread shows a reply from your configured model. Because provider credentials aren't checked at save time, this run is also what confirms them.

## Troubleshooting

**Command not found**: Confirm the OpenCode CLI connection is enabled for the project under [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis).

**Connect fails with a JSON error**: The config or auth JSON isn't valid JSON. Validate it locally, for example with `jq . opencode.json`, then paste the full object.

**Connect succeeds but `opencode run` fails**: Sazabi doesn't validate provider credentials when it saves. Check that the `model` in your config uses the `provider/model` format, that you added credentials for that provider, and that the key has access to the model. Fix the values under [**Settings > Sandbox CLIs**](https://app.sazabi.com/settings/sandbox-clis), then repeat Verify.

## Further reading

> [card] [Working with the agent](https://docs.sazabi.com/ask/better-answers.md)
>
> Put the connected CLI to work in an investigation thread.

> [card] [Set up the sandbox](https://docs.sazabi.com/ask/sandbox.md)
>
> How the sandbox works and its security model.

> [card] [Sandbox CLIs](https://docs.sazabi.com/catalogs/integrations.md#sandbox-clis)
>
> Browse the catalog and connect more tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.