Skip to main content
Many agents run inside your own app, built with a framework such as the AI SDK or OpenAI Agents. Those agents often need to run code, and your app is the wrong place to run code a model wrote. The solution is to give the agent a tool (a function the model can ask your app to call) that runs commands in a Fibre sandbox. The model writes the commands, the sandbox runs them, and your app never runs model-written code itself. Each conversation gets its own sandbox, which sleeps between turns while keeping everything the agent installed and wrote. Before you start, set your Fibre API key in FIBRE_API_KEY and FIBRE_API_URL=https://api.fibre.dev. For the steps that call a model, you also need your model provider’s API key.

One sandbox per conversation

Create a sandbox when a conversation starts, and label it with the conversation’s ID so that the next turn can find it again:
On every later turn, look the sandbox up by its label instead of creating a new one:
response

The tool’s function

The tool itself is a single function. It runs a shell command in the sandbox and returns the exit code and the end of the output. Returning only the end matters: a command that prints a lot of text would otherwise fill up the model’s context. A command that runs for more than two minutes is stopped, and the model is told why.
response
This is the function your app calls each time the model uses the tool.

Hand it to the framework

Every framework describes a tool in the same way: a name, a description that the model reads to decide when to use it, the shape of its input, and the function to call. Here is the same tool for the AI SDK and for OpenAI Agents:
Other frameworks, such as Mastra, LangGraph or a loop you wrote yourself, can use the same function. If your agent edits many files, add tools for files (sbx.files.read, sbx.files.write). If it needs the web, add a tool for the sandbox’s browser.

What the model can reach

It is worth being clear about what the model can and cannot reach through this tool:
  • It can only reach the sandbox. Your Fibre API key stays in your app, inside runCommand. The model sends a command and gets its output back, but never sees the key.
  • The sandbox has none of your app’s secrets or files, unless you put them there. Anything you do put there, the model can read with its next command.
  • The sandbox can reach the internet, so the agent can install packages and fetch pages. To limit that, see network access.

Between turns

Between turns, the sandbox goes to sleep after its idle timeout, with its memory and files saved, and the next tool call wakes it. A conversation can therefore pause for minutes or hours and pick up again with everything in place. Read more in sleep, wake and lifetime.

When the conversation ends

response
If you do not delete it, it is deleted automatically when the lifetime it was given ends.