Skip to main content
Claude Code is Anthropic’s coding agent. It can run without an interactive terminal, using claude -p, which means it can work inside a sandbox. There it gets a Linux machine of its own, with the repository, the tools and the shell it needs, and nothing it does can touch your computer. Between tasks, the sandbox sleeps with its memory and files. The next task then finds the agent, its session and its work exactly where they were. Before you start, set your Fibre API key in FIBRE_API_KEY and FIBRE_API_URL=https://api.fibre.dev. For the steps where Claude Code talks to Claude, you also need an Anthropic API key in ANTHROPIC_API_KEY.

Start a sandbox

Install Claude Code

Anthropic’s installer puts the claude program in ~/.local/bin. It takes about a minute, which is longer than an exec allows, so it runs as a background command.
output
To avoid installing it in every new sandbox, install it once and save that sandbox as a snapshot. New sandboxes created from the snapshot already have Claude Code.

Give it a repository

response
A private repository works the same way. Use a token in the URL, or write a deploy key into the sandbox.

Run a task

The task is passed in TASK, and the key in ANTHROPIC_API_KEY. Both are given to this one command only (there is more about the key below). --allowedTools lists what Claude Code may do without asking for permission. Since nobody is there to answer its questions, anything not on that list is simply refused.
With --output-format json, the last line of output is a single JSON object. It holds Claude Code’s answer in result, the session’s ID in session_id, and the cost in total_cost_usd. With curl, follow the command’s output in the same way as in the install step.

See what it changed

response
You can read any file it wrote with sbx.files.read, or let it commit its work and push a branch from the sandbox.

The next task, later

If you leave the sandbox alone, it goes to sleep after its idle timeout, with its memory and files saved. The next command wakes it, and the repository, the installed agent and Claude Code’s own session history are all still there. --continue picks up the conversation exactly where it stopped:
To continue a particular session rather than the most recent one, use --resume <session_id>. To keep the sandbox past the lifetime it was given, extend or remove it with sbx.update({ lifetime }). Read more in sleep, wake and lifetime.

The API key

Claude Code needs your Anthropic 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 Claude Code runs while it works can read it, including tests, install scripts and code in the repository. Treat the key as visible to that repository’s code. Use a key you can revoke, with a spending limit, and avoid giving a high-spending key to a sandbox that runs code you do not trust.
  • 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