Skip to main content
OpenCode is an open-source coding agent that works with many different models. Its opencode run command gives OpenCode a single task without opening its interface. If you run it in a Fibre sandbox, OpenCode gets a Linux machine of its own for the repository, well away from your computer. Between tasks the sandbox sleeps with its memory and files, so the next task can continue the same session. Before you start, set your Fibre API key in FIBRE_API_KEY and FIBRE_API_URL=https://api.fibre.dev. For the steps where OpenCode talks to a model, you also need that model provider’s API key. The example uses Anthropic (ANTHROPIC_API_KEY). For OpenAI it would be OPENAI_API_KEY: each provider reads its own variable.

Start a sandbox

Install OpenCode

OpenCode is installed from npm, and the sandbox’s default image already has Node. The install takes under a minute, which is longer than an exec allows, so it runs as a background command.
output

Give it a repository

response

Run a task

-m chooses the model, written as provider/model. Once a provider’s key is set, opencode models anthropic lists the models that provider offers. --auto approves the actions OpenCode would otherwise stop and ask about, since nobody is there to answer. That is safe here, because the Fibre sandbox keeps whatever OpenCode does inside it. The key is given to this one command only; there is more about it below.
Add --format json to get one JSON event per line instead of plain text. With curl, follow the command’s output in the same way as in the install step.

See what it changed

response

The next task, later

When OpenCode has finished, the sandbox goes to sleep after its idle timeout, with its memory and files saved, and the next command wakes it. OpenCode keeps its sessions on the sandbox’s disk, so --continue carries on the last one.
To continue a particular session instead, use --session <id>.

The API key

The agent needs your model provider’s API key, so it is worth understanding exactly where that key goes:
  • Only the command you give it to can see it, along with the programs that command starts. Other commands in the sandbox do not get it, Fibre does not write it into the sandbox’s files, and Fibre’s API never returns it.
  • Everything OpenCode runs while it works can read it, including tests, install scripts and code in the repository. Treat it as visible to that repository’s code. Use a key you can revoke, with a spending limit.
  • Do not put the key in the sandbox’s own environment (env in the SDK, or env_vars in the API, when you create the sandbox). Every command in the sandbox would then get it.

Delete it

response