Skip to main content
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.
Set a sandbox’s memory, vCPUs, environment variables, and labels when you create it. You can change labels and environment variables later; memory and vCPUs are fixed at creation. Set up your SDK and API key before running the code.

Choose memory and vCPUs

Set a sandbox’s memory, and Baseten gives it the matching number of vCPUs. Without a memory value, a sandbox gets 4,096 MiB and 2 vCPUs. Each account has a maximum memory and vCPU count per sandbox. A request above either returns HTTP 429 with the limit, such as You have reached the maximum memory (4096) for your account. To raise your limits, Contact us. To create a sandbox with 2 GiB of memory:
Run the following code. The sandbox gets 1 vCPU:
In the dashboard, the CPU field fills in the matching count when you enter Memory (MiB).

Set a custom CPU count

Most workloads should keep the vCPU count that matches their memory. Set a CPU count when a workload needs a different balance, such as a compile-heavy task that needs more vCPUs than its memory provides. The CPU count is a whole number from 1 to 32, and memory must be 1,024 to 8,192 MiB per vCPU. For example, 4 vCPUs allow 4,096 to 32,768 MiB. Set memory along with the CPU count: with only a CPU count, memory defaults to 8,192 MiB per vCPU, capped at your account’s memory limit. To create a sandbox with 2 vCPUs and 2 GiB of memory:
Run the following code:
A CPU count with memory outside its range returns HTTP 400 with the allowed range, such as for 8 vCPU, memory must be between 8192 and 65536 MB. The sandbox’s record shows its vCPU count as cpu. To delete the sandbox automatically, set an

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 when you create a sandbox, or replace them later. 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.
To create a sandbox with environment variables:Run the following code:
Set secret: false for a value you want to read back later.
Values are secret by default. Use secret values for credentials and tokens. Baseten masks secret values as **** when you read them back. 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. Run the following command to read the sandbox’s environment variables back:
Secret masking protects values in ordinary configuration responses. Code running inside the sandbox can read the actual values, including an agent that can run commands. Only provide credentials that you’re willing to make available to that code. To reveal secret values in the configuration, run the following command:
Don’t include this output in logs or agent prompts. Don’t pass --plain-env or secret: false for credentials; those values remain readable in ordinary configuration responses.

Replace environment variables

An update that includes environment variables replaces the sandbox’s entire set, and removes any variable you omit. Include every variable you want to keep, including existing secrets with their actual values. Don’t copy masked **** values from a configuration response. An update without environment variables leaves the existing set unchanged. Set DB_PASSWORD in your local shell before running these examples. To replace a sandbox’s environment variables:
Run the following code:
For more information, see Update a sandbox.

Change sandbox labels

Labels help you find and group sandboxes, such as marking every sandbox an agent creates with purpose=agent. A new set of labels replaces all previous labels, so include every one you want to keep. This example changes the purpose label from hello-world to hello-universe.
To change sandbox labels:Run the following code:

Select a team

If you belong to one team, sandbox requests use it. If you belong to more than one, select the team that owns the sandbox in every request that manages it. To select a team:
Replace <TEAM_ID> with your team’s ID, then configure the client as follows:
For more information, see Create a sandbox and Update a sandbox.