Baseten Sandboxes are now available and free to use until November 16. Each organization can run up to 10 sandboxes at once. To raise this limit, contact support.
- Port route: your own code calls the sandbox’s URL followed by
/port/<PORT>/, with a sandbox access token. See Call an HTTP service in a sandbox. - Preview: an HTTPS URL for browsers and sharing, such as an agent-generated website. This page covers previews.
Prepare your application
Bind your application to the sandbox’sHOST environment variable so the
preview can reach it. Port 80 is reserved and can’t serve a preview, and a
preview of port 443 must be private.
Set up your SDK or the CLI before running these
examples. They use an existing sandbox named hello-world with Python
installed, such as one created from Base Image. To create one, see
Create a sandbox.
Create a preview
Start a web server on port3000, wait for it to listen, then create a
private preview named web and a preview token that expires after 1 hour.
To open the application through a private preview:
- TypeScript
- Python
- Go
- CLI
Run the following code:
/tmp. For your own application, replace the server command and port. The
preview routes traffic to the running application; it doesn’t start it.
Retrieve or create the sandbox through the SDK before managing its previews.
Preview operations need the sandbox’s name and don’t work on a handle created
from its URL alone.
On later runs, reuse the running server and existing preview instead of
starting another process on the same port. To reuse a preview by name, pass
createIfNotExists: true in TypeScript, create_if_not_exists=True in Python,
CreateIfNotExists: true in Go, or --if-not-exists in the CLI. This returns
the existing preview unchanged, including its access settings.
Control preview access
A preview token grants access to one private preview until it expires. It’s separate from the sandbox access token that authenticates sandbox requests. Treat a URL containing a preview token as a credential and share it only with people who should have access. The first request sets a cookie so the browser can continue navigating without the query parameter. To let anyone with the URL open the application, make the preview public. To make a preview public:- TypeScript
- Python
- Go
- CLI
Run the following code:
public to false in TypeScript and Go
or False in Python, or pass --private in the CLI.
Set an expiration
When a preview expires, Baseten deletes it and its URL stops serving. A preview’s expiration is separate from its tokens’ expiration and the sandbox’s expiration. Set it as a duration from the request, or as a fixed time withexpiresAt in TypeScript,
expires_at in Python, ExpiresAt in Go, or --expires-at in the CLI. Use
one or the other in a request. Setting an expiration replaces any previous one.
To delete the preview after 1 hour:
- TypeScript
- Python
- Go
- CLI
Run the following code:
List and inspect previews
To list and inspect a sandbox’s previews:-
Run the following command to list the sandbox’s previews:
-
Run the following command to inspect one preview’s URL, port, and status:
502 error, check that your application is running
on the preview’s port and listening on HOST.
Remove a preview
Deleting a preview removes its tokens and stops access through its URL. It leaves the sandbox running. Deleting the sandbox also removes its previews. To remove the preview and stop the server:- TypeScript
- Python
- Go
- CLI
Run the following code:
baseten sandbox preview and
Create a sandbox preview.