Set up
Install the CLI or an SDK:- TypeScript
- Python
- Go
- CLI
$SANDBOX_NAME for the sandbox name:
Sandbox commands are in pre-release. Arguments, flags, and output may change.
Create a sandbox
Creating a sandbox starts an isolated environment from an image. The new sandbox gets a name, an image, memory (which also sets its CPU allocation), and a region. Name, image, memory, and region can’t change after creation.An organization can run up to 10 sandboxes at once. To raise this quota,
contact Baseten support with your organization
ID.
- TypeScript
- Python
- Go
- CLI
- UI
createIfNotExists: true.Get a sandbox
A sandbox’s record shows its configuration, URL, and current status.- TypeScript
- Python
- Go
- CLI
- UI
client.get({ name: "hello-world" }).FAILED, inspect the sandbox’s logs
before retrying. For the deployment and deletion statuses, see
Lifecycle and expiration.
Interact with a running sandbox
You can interact with a sandbox in two ways:- Use the Management API,
through the CLI or an SDK, to:
- Create sandboxes.
- List sandboxes.
- Update sandboxes.
- Delete sandboxes.
- Use the sandbox’s own API, served by a server inside each sandbox at the
sandbox’s
urlfield, to:- Run commands.
- Read, write, and edit files.
url field the create or get call returns.
Get the URL before connecting:
- Python
- CLI
- Dashboard
- Python
- HTTP
- CLI
- MCP server
The SDK wraps the sandbox’s API with file and process methods:For operations the SDK doesn’t wrap,
sandbox.raw_api is the generated client,
and client.sandbox_from_url(url=...) builds a sandbox from a URL you
already have.Run commands in a sandbox
Run a single command in a deployed sandbox. Its output streams to your terminal, and its exit code becomes the command’s exit code.- TypeScript
- Python
- Go
- CLI
env:Set environment variables
Environment variables pass configuration, such as an output format or log level, to the processes in a sandbox, so one image can serve different tasks. Set them at creation. Names begin with a letter or underscore and contain only letters, digits, and underscores. Don’t put your Baseten API key in a sandbox’s environment.- TypeScript
- Python
- Go
- CLI
- UI
secret: false for a value you want to read back later.**** when you read
them back, so use them for credentials and tokens. For configuration you’ll
want to see later, such as LOG_LEVEL or OUTPUT_FORMAT, mark the value as
not secret so it stays readable. A describe shows the difference:
--show-secrets to describe, or read the
variable inside the sandbox. Don’t pass --plain-env or secret: false for
credentials; those values are stored and returned in plain text.
List sandboxes
- TypeScript
- Python
- Go
- CLI
statuses, such as statuses: ["DEPLOYED"].Manage a sandbox’s labels
Labels help you find and group sandboxes, such as marking every sandbox an agent creates withpurpose=agent. This example changes the purpose label
from hello-world to hello-universe:
- TypeScript
- Python
- Go
- CLI
- UI
envs.
The name, image, memory, and region can’t change after creation. To use a
different image, create a new sandbox.
Delete a sandbox
Deletion stops the sandbox’s processes and permanently removes its files, so save the files you need first.- TypeScript
- Python
- Go
- CLI
- UI
TERMINATED.
The sandbox reports TERMINATED for a few minutes, and then it’s no longer
found. Don’t reuse the name until deletion completes.
Work in a team
If you belong to multiple teams, specify a team ID when you create an SDK client:- TypeScript
- Python
- Go
- CLI
Handle a failed command
Use the error message to choose the next action:Next steps
Sandbox lifecycle and expiration
Track deployment status and set an expiration policy.
Manage sandbox images
Choose a built-in image, or create and version your own.