url field. If a program inside the sandbox
listens on the sandbox’s exposed port, anyone can reach that program at the address, from anywhere, over a
secure connection with a valid certificate. You do not need to set up a server, a domain or a certificate yourself.
This is useful in many situations:
- Show a user the app their agent just built, live, while the agent keeps working on it.
- Share a preview of a branch with a teammate or a reviewer.
- Receive webhooks from services such as GitHub, Stripe or Slack in a sandbox you are testing.
- Run a small API or bot without deploying it anywhere.
Serve an app
This example serves a small web app with one page and one JSON endpoint. It only uses Node, which is already installed, and listens on port 3000. Follow the steps to get it running at a public address.1
Start a sandbox that serves port 3000
Response
Response
response
2
Put the app in
3
Start the server so it keeps running
keep: true makes the server a program that keeps running on its own, even across sleep and wake. The second
line waits until the server answers before moving on.4
Open it from anywhere
Output
Output
output
url into your browser, or send it to someone. They see the app, over HTTPS, without setting
anything up.A visitor wakes it
This sandbox was created to sleep after one quiet minute. Wait for it to fall asleep, then simply visit the URL again. You do not need to call the API or wake the sandbox first. The first request waits a moment while the sandbox wakes up, then gets its answer from the same server, which still remembers its earlier visits.Output
Output
output
started time is the same as before the sleep. That shows the server was resumed, not restarted. Anything
it held in memory, such as user sessions, caches or a loaded model, is still there.
Live connections
The address carries more than ordinary page loads:- WebSockets work, so features such as live reload, chat and terminals in the browser all work.
- Streaming responses, such as server-sent events, reach the visitor as your app writes them.
- An open connection keeps the sandbox awake. A user watching a live page is never cut off because the sandbox went to sleep.
Who can open it
If you do not want a sandbox reachable from the internet, simply do not run anything on its exposed port. When nothing is listening there, the address answers with an error and reaches nothing inside the sandbox.Good to know
These details answer the questions that usually come up:Clean up
Related
Preview environments
A preview per pull request, from a repo.
Sleep and wake
What a sleeping app keeps, and what wakes it.
Run commands
Keep servers running with
keep.Browser
Test the app with a real browser in the same sandbox.