> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superserve.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Choose a custom size

> Fix a sandbox's vCPU and memory at create, within its template's range.

A sandbox gets its size in one of two ways:

* **Auto** (the default): the sandbox uses its template's size. If the template has a range, the sandbox starts at the minimum and grows with load, up to the maximum. See [Memory resizing](https://docs.superserve.ai/sandbox/live-memory-resizing.md) and [CPU resizing](https://docs.superserve.ai/sandbox/live-cpu-resizing.md).
* **Fixed**: you choose `vcpu` and/or `memoryMib` within the template's range when you create the sandbox. It stays at that size.

One template with a range can serve a small sandbox for a quick script and a large one for a build.

## Build a template with a range

The template sets the range. Set `vcpuMax` above `vcpu` for a CPU range, and `memoryMaxMib` above `memoryMib` for a memory range. In the console, pick **Range** for vCPU or Memory. See [Growing CPU](https://docs.superserve.ai/templates/build-spec.md#growing-cpu) and [Growing memory](https://docs.superserve.ai/templates/build-spec.md#growing-memory) for the rules.

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
import { Template } from "@superserve/sdk"

const template = await Template.create({
  name: "my-env",
  from: "python:3.11",
  vcpu: 1,
  vcpuMax: 4,
  memoryMib: 2048,
  memoryMaxMib: 8192,
})
await template.waitUntilReady()
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
from superserve import Template

template = Template.create(
    name="my-env",
    from_="python:3.11",
    vcpu=1,
    vcpu_max=4,
    memory_mib=2048,
    memory_max_mib=8192,
)
template.wait_until_ready()
```

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
superserve template create my-env --from python:3.11 \
  --vcpu 1 --vcpu-max 4 --memory 2G --memory-max 8G
```

## Choose a size

Pass `vcpu`, `memoryMib` / `memory_mib`, or both. In the console, set vCPU or Memory to **Fixed** under **Size**.

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
import { Sandbox } from "@superserve/sdk"

const sandbox = await Sandbox.create({
  name: "build",
  fromTemplate: "my-env",
  vcpu: 3,
  memoryMib: 6144,
})
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
from superserve import Sandbox

sandbox = Sandbox.create(
    name="build",
    from_template="my-env",
    vcpu=3,
    memory_mib=6144,
)
```

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
superserve sandbox create --name build --template my-env --vcpu 3 --memory 6G
```

With the [MCP server](https://docs.superserve.ai/integrations/mcp.md), pass `vcpu` and `memory_mib` to `sandbox_create`.

* **`vcpu`**: whole vCPUs from the template's `vcpu` to its `vcpuMax`.
* **`memoryMib`**: MiB from the template's `memoryMib` to its `memoryMaxMib`, in 2 MiB steps from the minimum. For a 2048–8192 MiB template, 6144 works and 6145 doesn't.
* Both ends of the range are included. Values must also be within your plan's limits. See [Resource limits](https://docs.superserve.ai/templates/build-spec.md#resource-limits).

A fixed size holds through pause and resume. A dimension you leave out stays Auto. In the example above, passing only `vcpu: 3` would give a fixed 3 vCPU with memory still growing from 2048 to 8192 MiB.

The sandbox's info shows no maximum for a fixed dimension:

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
const info = await sandbox.getInfo()
console.log(info.vcpuCount, info.vcpuMax) // 3 undefined
console.log(info.memoryMib, info.memoryMaxMib) // 6144 undefined
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
info = sandbox.get_info()
print(info.vcpu_count, info.vcpu_max)  # 3 None
print(info.memory_mib, info.memory_max_mib)  # 6144 None
```

## Snapshot copies

A sandbox created from a [snapshot](https://docs.superserve.ai/sandbox/snapshots.md) keeps the original sandbox's size, Auto or Fixed. You can also choose a size with `fromSnapshot` / `from_snapshot`:

* **`vcpu`** works when the original sandbox came from a template with a CPU range. The snapshot records that range, and the copy can take any count in it. For a snapshot of a 2 vCPU sandbox from a 1–4 vCPU template, 1, 3 and 4 all work.
* **`memoryMib`** works when the original sandbox had a fixed memory size. The copy can take any size in the snapshot's memory range, in 2 MiB steps from the minimum.

```typescript TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
const copy = await Sandbox.create({
  name: "bigger-copy",
  fromSnapshot: snapshot,
  vcpu: 4,
})
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
copy = Sandbox.create(
    name="bigger-copy",
    from_snapshot=snapshot,
    vcpu=4,
)
```

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
superserve sandbox create --name bigger-copy --snapshot <snapshot-id> --vcpu 4
```

A snapshot of a copy records the same range, so a copy of a copy can choose again.

## Errors

| Status | Error | When |
| - | - | - |
| `400` | `ValidationError` | The value is outside the template's or snapshot's range, or the template has no range for that dimension. System templates such as `superserve/base` have none. |
| `400` | `ValidationError` | `vcpu` with a snapshot that has no recorded CPU range, for example one from a system template. |
| `400` | `ValidationError` | `memoryMib` with a snapshot of a sandbox that didn't have a fixed memory size. |
| `402` | `BillingError` with code `sandbox_exceeds_plan_limits` | The value is within range but above your plan's limits. See [Billing errors](https://docs.superserve.ai/errors.md#billing-errors-402). |
| `409` | `ConflictError` | The template was built before custom sizes were available. [Rebuild it](https://docs.superserve.ai/templates/lifecycle.md), or leave out `vcpu` and `memoryMib`. |
| `429` | `RateLimitError` with code `host_capacity` | The host has no room for that size right now. Retry after a short wait. |

Custom sizes apply to sandboxes placed on GCP. For an AWS placement (`placement.cloud` set to `aws` in [`POST /sandboxes`](https://docs.superserve.ai/api-reference/sandboxes/create-a-new-sandbox)), leave out `vcpu` and `memoryMib`.

## Billing

A fixed size is billed at that size while the sandbox is active. An Auto dimension is billed as described in [CPU resizing](https://docs.superserve.ai/sandbox/live-cpu-resizing.md#billing) and [Memory resizing](https://docs.superserve.ai/sandbox/live-memory-resizing.md#billing).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.