Skip to main content
Many products give each user a machine of their own: an AI app builder, a coding assistant, a notebook, or an agent that works on the user’s files. Products like these have three needs in common:
  • Each user’s code must be kept apart from everyone else’s.
  • A user’s work must still be there when they come back tomorrow.
  • The bill must not grow because of users who are not active right now.
This page shows how to meet all three with Fibre, and what it costs.

Three patterns

There are three common ways to give users sandboxes. The first one suits almost every product: With sleep, inactive users cost nothing for compute. You do not need to write any code to stop and start sandboxes: a request to a sleeping sandbox wakes it, with the user’s programs and memory exactly as they left them.

Find or create a user’s sandbox

Each time a user does something, your app needs their sandbox. You do not need to store sandbox IDs in your own database for this: label each sandbox with the user’s ID, and look it up by that label. If the user does not have a sandbox yet, create one. It is kept until you delete it, so it is there whenever the user comes back:
There is one subtle case. If two requests for a brand-new user arrive at the same moment, both might find no sandbox and both might create one. To prevent that, send an idempotency key based on the user’s ID. Both requests then get the same sandbox:

Start every user ready

A new user should not have to wait for npm install to finish before they can start. Prepare one sandbox with your stack, save it as a snapshot, and create every user’s sandbox from it. Each one then starts with the dependencies installed and your development server already running:

Show the user their app

If you create the sandbox with exposedPort, whatever the user’s app serves on that port is available at the sandbox’s url. You can show it in a frame next to your chat, or simply give the user the link. A visit wakes a sleeping sandbox, so the preview still works after the user has been away. See public URLs.

When users come and go

Here is what to do, or not do, as users come and go:
Keep a copy of the user’s important work outside the sandbox as well. Push their code to a repository, or copy important files out with the files API when a session ends. A sandbox is a workspace, not a backup.

Clean up

What it costs, worked through

Here is an example with real numbers: 1,000 users on the medium size, each active for 30 minutes a day, on 20 days a month. The only difference between those two lines is sleep. See pricing for all the prices.

Sleep and wake

What a sleeping sandbox keeps, and what wakes it.

A key for one sandbox

Let the user’s agent manage its own sandbox, and nothing else.