Skip to main content
The Claude Agent SDK lets you build your own agent on the same foundation as Claude Code. Your agent can read files, edit them and run commands, on whatever machine it runs on. That is exactly why that machine should be a sandbox, not your own server. Anthropic’s hosting guide suggests a separate container for each session, and recommends shutting idle containers down and rebuilding them from saved sessions to save money. A Fibre sandbox does that part for you: when the agent is idle, the sandbox sleeps with its memory and files, and the next task wakes it exactly where it was. Before you start, set your Fibre API key in FIBRE_API_KEY and FIBRE_API_URL=https://api.fibre.dev. For the steps where the agent talks to Claude, you also need an Anthropic API key in ANTHROPIC_API_KEY.

Start a sandbox

Install the SDK

Create a small Node project in the sandbox and install the SDK from npm. This takes about a minute, which is longer than an exec allows, so it runs as a background command.
output

Write the agent

The agent itself is a short program. It reads its task from the TASK environment variable and works in the directory it is started in. When you start it with --continue, it resumes the most recent session in that directory instead of starting a new one.

Give it a repository

response

Run a task

Now run the agent in the repository. The API key and the task are given to this one command only. There is more about the key below.

The next task, later

When the agent has finished, the sandbox goes to sleep after its idle timeout, with its memory and files saved, and the next command wakes it. The SDK keeps its sessions on the sandbox’s disk, so --continue picks up the whole conversation. You do not need a session store of your own, and nothing has to be rebuilt.
An agent that keeps running between tasks, such as a small server that your app sends tasks to, can sleep too. Start it with keep: true, and the process itself is kept across sleep, even in the middle of a conversation. See sleep, wake and lifetime.

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 the agent 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