@fibre-dev/sdk, lets you work with sandboxes as objects in your code. It reads your API key
from the environment, gives you command output as it is written, retries temporary failures safely, and turns
errors into typed exceptions. It runs on Node 20 or later, Bun and Deno, and has no dependencies.
This page is organised by task. Each section shows a short example and links to the guide that explains the
feature in depth. At the end you will find a table of every method.
Install and configure
Add the SDK to your project and make your API key available:Terminal
Sandbox.create() automatically use a client built
from FIBRE_API_KEY (and from FIBRE_API_URL, which defaults to https://api.fibre.dev).
If you need different settings, for example a different key, create a Fibre client yourself and pass it as the
last argument:
TypeScript
Create, run, delete
The basic flow is to create a sandbox, run something in it and read the result:TypeScript
- A command can be a string or an array. A string runs through the shell (
sh -c), so pipes and&&work. An array is the program followed by its arguments. run()waits for the command to finish, with no time limit unless you pass{ timeout }. A non-zero exit code is returned as a result, not thrown as an error.cwdandenvset the directory and the environment variables for that one command.
Stream output as it happens
For longer commands,spawn() starts the command in the background and returns straight away. You can then read
its output with output(), piece by piece, as the command writes it:
TypeScript
chunk.stream tells you whether a piece came from stdout or stderr. If the connection drops, output()
reconnects and continues from where it left off.
Run a server in the background
A server should keep running after the call that started it, and through sleep and wake. Start it withkeep: true:
TypeScript
Write to a program’s input
Start a command withstdin: true to send it input while it runs:
TypeScript
Files
Every sandbox has afiles property for reading and writing its files directly:
TypeScript
Find sandboxes again
List sandboxes by their labels, get one by its ID, and change what can change:TypeScript
Serve an app
Create the sandbox withexposedPort, start a server on that port, and it is available at the sandbox’s url:
TypeScript
Snapshots
Take a snapshot of a prepared sandbox, its whole state with memory, so new ones start ready:TypeScript
Browser and desktop
Get links to a sandbox’s browser, or to its desktop:TypeScript
Secrets
Store a secret once, then give it to the one command that needs it, by name. Inside the sandbox it is an environment variable; its value is never returned by the API:TypeScript
Errors
When a call fails, the SDK throws aFibreError with status, code, requestId and docsUrl. Each kind of
error has its own class, so you can catch exactly the ones you expect:
TypeScript
Read more in errors, retries and limits.
Any API call
If the SDK does not have a method for a call yet, use the client’sjson() method. It still sends your key,
retries temporary failures and throws typed errors:
TypeScript
fibre.fetch() gives you the raw Response, for streams and binary bodies.