Skip to main content
Many apps built on Fibre have a web page in front: a coding playground, an app builder that shows a live preview, a data tool that runs Python for its users, or a dashboard that watches agents at work. The people using the page never talk to Fibre directly. Your server does, and the page talks to your server.
Never put your Fibre API key in code that runs in a browser. Anyone who opens the page can read it, and with it they could create sandboxes on your account. Keep the key on your server, and give the browser only what it needs.

The pattern

  1. The browser asks your server to do something for the signed-in user: run this code, start my preview.
  2. Your server finds that user’s sandbox, or creates one, using labels such as {"user": "42"} (see a sandbox per user), and makes the Fibre calls with your key.
  3. Your server answers the browser with the result: the command’s output, or the address of a preview.
This keeps every decision on your side: who may run what, how much, and for how long.

A small server

Here is a server with one route, POST /api/run, that runs a user’s Python in their own sandbox and returns the output. It finds the sandbox by the user’s ID and creates it on first use. Add your own sign-in check where the comment says so:
The page then calls your route like any other:
In the page
Because each user has their own sandbox, which sleeps between requests, a user who runs code again finds the variables, files and packages of their last run still there.

Show an app running in a sandbox

When the sandbox serves an app, such as a preview of what the user is building, create it with exposed_port and start the app in the background. Its public url can go straight into the page, for example in an iframe:
In the page
Your server returns the URL to the page. Keep in mind that anyone who has the URL can open the app, as with any public address, and a visit wakes a sleeping sandbox. See public URLs.

Show output as it happens

For long commands, such as an install, a build or an agent at work, the page should show output while it is being written. Your server starts the command in the background, follows its output, and passes each piece on to the browser, for example as server-sent events or over a WebSocket:
TypeScript (Node)
See run commands for following, reattaching and stopping commands.

Calls from the page to the sandbox’s app (CORS)

If code in your page calls the app inside a sandbox directly, at its url, the browser treats that as a request to another site and asks the app whether it allows it. That is the app’s decision: set CORS headers in the app that runs in the sandbox, as you would for any API on another domain. For example, a Node app can answer with Access-Control-Allow-Origin: https://your-app.example and the methods and headers it accepts, and answer OPTIONS requests itself.

Watching an agent’s browser or desktop

If an agent works in a sandbox’s browser, its live view link shows the browser and passes on clicks and keys, and nothing else, so it is safe to show to a person in your page. Keep the browser’s DevTools address (cdp_url) on your server: it gives full control of the browser. A desktop link works once, for the first person who opens it.