Skip to main content
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. A sandbox’s memory and vCPUs set its price. See sandbox prices for the rates. 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 command:
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.

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 credentials, API keys, or tokens in a sandbox’s environment. Code running inside the sandbox can read every environment variable, including values the Management API masks.
To create a sandbox with environment variables:Run the following code:
Set secret: false for a value you want to read back later.
Configuration responses show **** for values marked as secret. Masking is on by default. Turn it off when you set a value you want to read back. Run the following command to read the sandbox’s environment variables back:

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 with its actual value. Don’t copy masked **** values from a configuration response. An update without environment variables leaves the existing set unchanged. 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.