Skip to main content
The TypeScript SDK, @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
For most programs, that is all the setup needed. Calls such as 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.
  • cwd and env set the directory and the environment variables for that one command.
Read more in create and configure.

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 with keep: true:
TypeScript

Write to a program’s input

Start a command with stdin: true to send it input while it runs:
TypeScript
Read more in run commands.

Files

Every sandbox has a files property for reading and writing its files directly:
TypeScript
Read more in files.

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 with exposedPort, start a server on that port, and it is available at the sandbox’s url:
TypeScript
Read more in public URLs.

Snapshots

Take a snapshot of a prepared sandbox, its whole state with memory, so new ones start ready:
TypeScript
Read more in snapshots, including what they cost.

Browser and desktop

Get links to a sandbox’s browser, or to its desktop:
TypeScript
Read more in browser and desktop.

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
Read more in secrets.

Errors

When a call fails, the SDK throws a FibreError 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’s json() 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.

Methods

For reference, here is every class and method in the SDK: