Skip to main content
Flue is a TypeScript framework for building agents. Its built-in tools (bash, read, write, edit, grep, and glob) run against the sandbox you pass to useSandbox. Back that sandbox with a Superserve sandbox, and every command the model runs, and every file it writes, stays in an isolated VM instead of on your machine. The model API key stays in your app; the sandbox never sees it.

Setup

Flue needs Node.js 22.19 or later. Create a project with this package.json:
package.json
@flue/runtime 2.3.0 does not load with version 1.5.0 of its @earendil-works/pi-ai dependency (does not provide an export named 'Type'). The overrides block pins the 1.4.0 release until a fixed Flue release ships. See flue#912.
Install the packages and put your keys in .env. flue run loads .env from the project directory.
.env
See API keys to create a Superserve API key.

Add the sandbox adapter

Flue’s sandboxFromDriver turns a small driver object into the sandbox that Flue’s tools use. This driver sends commands to sandbox.commands.run and file reads and writes to sandbox.files. Save it as src/sandboxes/superserve.ts.
src/sandboxes/superserve.ts
Every command gets a timeout. Without one, the SDK request ends after 30 seconds, so long installs and builds would fail.

Write the agent

Flue calls createSandbox with the agent instance id. The agent below tags its sandbox with the agent name and that id, so later turns for the same agent and id find and reuse the same sandbox. Save it as src/agents/coder.ts.
src/agents/coder.ts
Flue does not tell the adapter when an agent instance is finished, so the sandbox cleans up after itself. idleTimeoutSeconds pauses the sandbox after 15 minutes with no activity, and autoDeleteSeconds deletes it after one day paused. A paused sandbox keeps its files, and Sandbox.connect() resumes it on the next turn. See Idle timeout and Auto-delete.

Run the agent

Pass an --id so later turns continue the same agent instance:
Output from a run with claude-sonnet-5-5 (trimmed):
Run a second turn with the same id. Flue keeps the conversation, and createSandbox finds the sandbox from the first turn, so the file is still there:

Use a template

The default sandbox has python3, git, curl, and Node.js. To give the agent other tools, build a template once and create the agent’s sandboxes from it. This template adds ripgrep, which Flue’s grep tool uses when it is installed.
scripts/build-template.ts
Then pass the template name to Sandbox.create in src/agents/coder.ts:

Delete a sandbox

To delete an agent’s sandbox before auto-delete does, find it by its metadata tag:
scripts/delete-sandbox.ts
See Metadata tags for more about filters.

Good to know

  • The lookup in createSandbox is not atomic. If two processes can start the same agent instance at the same time, store the sandbox id with the conversation in your database, and connect to that id instead.
  • The model can call only Flue’s tools. Keep kill(), pause(), and update() in your application code, not in a tool.
  • Cancelling a Flue call does not stop a command that is already running in the sandbox. The command stops when its timeout expires.
  • The default sandbox has python3 but no python. Tell the model in the system prompt, or use a template with the tools you need.
  • To limit what model-written code can reach, create the sandbox with network rules.

Resources

Flue docs

Sandboxes, tools, and durable agents in Flue.

Run commands

Options for commands.run, including environment variables and working directory.