- 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.
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:Start every user ready
A new user should not have to wait fornpm 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 withexposedPort, 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:Clean up
What it costs, worked through
Here is an example with real numbers: 1,000 users on themedium 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.
Related
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.