Skip to main content
Most of a sandbox’s life is spent waiting: for the user’s next message, the next pull request, the next test run. Fibre does not charge you for that waiting. When nothing has happened in a sandbox for a while, it goes to sleep. When the next call comes, it wakes up exactly where it was, with the same running programs, the same data in memory and the same open files. This is different from most machines you may have used. Stopping a server normally throws away everything in memory, and starting it again means booting from scratch. A Fibre sandbox keeps its memory while it sleeps, so waking it is more like opening a laptop lid than switching on a computer. Keeping memory across a sleep changes how you can build:
  • There is no slow start to design around. A dev server that took a long time to start is already running after a wake. An agent’s process still holds its conversation. A dataset loaded into memory is still loaded.
  • You do not write code to save and restore state. Nothing needs to be written to disk before a sleep, and nothing needs to be rebuilt after a wake.
  • One sandbox per user becomes affordable. If a thousand users each work ten minutes an hour, you pay for ten minutes an hour each, not for a thousand machines running all the time.

See it: memory survives a sleep

The best way to understand this is to see it. In this example, a small server loads two million rows into memory and counts the requests it receives. We call it, let the sandbox fall asleep, and then call it again. If memory really survives the sleep, the count carries on from where it was, and the data is not loaded a second time.
1

Start a sandbox that sleeps after one quiet minute

2

Run a server that holds data in memory

response
keep: true starts the server as a program that keeps running on its own, independently of the call that started it. See keep a program running.
3

Leave it alone until it sleeps

There is nothing to call here. Because this sandbox was created with a one-minute idle timeout, it goes to sleep on its own after a quiet minute, and its status changes from running to standby. The code below simply watches for that:
output
From this moment on, you are not paying for compute.
4

Call it again

There is no separate “wake” call. You simply use the sandbox again, and Fibre wakes it before answering:
response
Look at hits: it is 3, not 1. The answer came from the same process (the same pid) that loaded its data at the same time (the same loaded_at). The server was not restarted: it was resumed, and the two million rows were never loaded again.

What is kept

Here is what a sandbox keeps while it sleeps:
There is one difference between the two runtimes. On standard, a program you started with a plain exec or command, and which is still running when the sandbox goes to sleep, is not there after the wake. So start anything that should keep running with keep: true. On vm, every process is kept, and you do not need to think about it.

Connections to other services

Programs inside the sandbox keep their state across a sleep, but the services they were talking to do not wait for them. A database connection, a message queue, or a pool of HTTP connections that was open when the sandbox fell asleep may have been closed by the other side by the time it wakes. The first query on such a connection then fails with an error such as “connection reset” or “server closed the connection”. Most client libraries can handle this for you. Turn on the option that checks or retries a connection before using it, for example pool_pre_ping=True in SQLAlchemy, a keep-alive or retry option in your HTTP client, or simply reconnect when a call fails with a connection error. Connections that arrive at the sandbox, such as visitors to its url, are not affected: each new visitor wakes it and is served.

When it sleeps

A sandbox goes to sleep when nothing has happened in it for its idle timeout, which is 300 seconds (5 minutes) unless you choose another value. Fibre counts any of these as “something happening”:
  • A command or exec is running, or a shell or terminal is open.
  • Its programs are using the CPU.
  • Network traffic is flowing, in either direction. This matters for agents: an agent waiting for a model’s answer has a connection open, so it is never put to sleep in the middle of a thought.
Only when all of these have been quiet for the whole idle timeout does the sandbox go to sleep.

What wakes it

Any call that needs the sandbox wakes it, with no extra step on your side: The call that wakes a sandbox simply takes a moment longer than usual. If several calls arrive while it is waking, they all wait for that same wake, and nothing is started twice.

Tune it

You decide how quickly a sandbox goes to sleep. Set the idle timeout when you create the sandbox, or change it at any time. Here, setting it to 0 means the sandbox never sleeps:
response
Which value to choose depends on how the sandbox is used:

Lifetime

Sleeping is not the same as being deleted, and neither is time passing: a sandbox is kept until you delete it, asleep or awake. Fibre never deletes one on its own. While it exists, its saved state counts towards your storage. If you want a sandbox to delete itself, give it a lifetime: from 60 seconds up to 10 years, when you create it or later. It is deleted when the lifetime ends, whether it is asleep or awake at that moment. Each new lifetime counts from the moment you set it:
response
To remove the lifetime, so the sandbox is kept until you delete it, send null:
response
A workspace per user needs no lifetime: it sleeps while they are away and is there when they come back. If you would rather have Fibre delete the workspaces of users who never return, give each one a lifetime and extend it each time the user shows up.

When it is deleted

When you delete it, or when a lifetime you set ends, a sandbox is gone for good: its running programs are stopped, and its files, its memory and its address are deleted. This cannot be undone, and nothing is kept for you to restore.

Keep work after deleting it

A sandbox keeps its work for as long as you keep the sandbox. To keep what it produced after you delete it:
  • Copy the results out before it ends: read the files you need, or pack a folder and download it (see files), or push code to its repository from inside the sandbox.
  • Save it as a snapshot to start new sandboxes exactly as it is now, memory included. A snapshot outlives the sandbox it came from.

What it costs

Here is an example. A support agent’s sandbox on the medium size works for 4 minutes in each hour of an 8-hour day. It is awake for 32 minutes in total, which costs **about $0.016 a day**. If the same sandbox were left awake all day, it would cost $0.72 a day. See pricing.

Clean up

Run commands

Start programs that carry on across sleep with keep.

Runtimes

On vm, every process survives a sleep, not only the kept ones.

Serve an app

A site that sleeps when nobody visits and wakes on the next request.

Pricing and limits

What awake time costs at each size.