# Scale

Daytona sandboxes are designed to be created and operated at high volume. A single sandbox scales up by resizing its reserved resources, a fleet scales out by running many sandboxes at once, and each sandbox runs multiple processes concurrently.

Unlike request-based execution environments, a sandbox is a long-lived computer: processes are not terminated after a request completes, so running services, open connections, and background workers persist until the sandbox stops.

Scale operates along three dimensions:

| **Dimension** | **What scales** | **Mechanisms** |
| --- | --- | --- |
| Sandbox (vertical) | vCPU, RAM, and disk of a single sandbox | • [**Custom resources**](/content/docs/en/sandboxes#resources/index.html)<br> • [**Resize**](/content/docs/en/sandboxes#resize-sandboxes/index.html) |
| Fleet (horizontal) | Number of sandboxes running at the same time | • [**Snapshot fan-out**](/content/docs/en/snapshots/index.html)<br> • [**Fork**](/content/docs/en/sandboxes#fork-sandboxes/index.html)<br> • [**Linked sandboxes**](/content/docs/en/sandboxes#linked-sandboxes/index.html) |
| Workload (concurrency) | Concurrent processes inside a single sandbox | • [**Sessions**](/content/docs/en/process-code-execution#session-operations/index.html)<br> • [**Async commands**](/content/docs/en/process-code-execution#session-operations/index.html)<br> • [**PTY sessions**](/content/docs/en/pty/index.html) |

## Sandbox scaling

Sandbox scaling changes the resources of a single sandbox: **vCPU**, **memory**, and **disk**. Resources are reserved when the sandbox is created and can be changed later by resizing.

Resources are set differently depending on how the sandbox is created:

- **From an image**: set **`resources`** on the create parameters
- **From a snapshot**: the sandbox inherits the resources defined on the snapshot

Resizing changes the allocation of an existing sandbox. On a running sandbox, CPU and memory can be increased without interruption. Decreasing CPU or memory, or increasing disk, requires the sandbox to be stopped first. Disk can only grow, and GPU allocation cannot be resized. Every allocation must stay within your organization’s per-sandbox limits.

```python
from daytona import CreateSandboxFromImageParams, Daytona, Resources

daytona = Daytona()

# Reserve 2 vCPUs, 4GiB of RAM, and 8GiB of disk for the sandbox

sandbox = daytona.create(
    CreateSandboxFromImageParams(
        image="ubuntu:22.04",
        resources=Resources(cpu=2, memory=4, disk=8),
    )
)
```

```typescript
import { Daytona, Image } from '@daytona/sdk'

const daytona = new Daytona()

// Reserve 2 vCPUs, 4GiB of RAM, and 8GiB of disk for the sandbox

const sandbox = await daytona.create({
  image: Image.base('ubuntu:22.04'),
  resources: { cpu: 2, memory: 4, disk: 8 },
})
```

```ruby
require 'daytona'

daytona = Daytona::Daytona.new

# Reserve 2 vCPUs, 4GiB of RAM, and 8GiB of disk for the sandbox

sandbox = daytona.create(
  Daytona::CreateSandboxFromImageParams.new(
    image: Daytona::Image.base('ubuntu:22.04'),
    resources: Daytona::Resources.new(
      cpu: 2,
      memory: 4,
      disk: 8
    )
  )
)
```

```go
package main

import (
  "context"
  "github.com/daytona/clients/sdk-go/pkg/daytona"
  "github.com/daytona/clients/sdk-go/pkg/types"
)

func main() {
  client, _ := daytona.NewClient()
  ctx := context.Background()

// Reserve 2 vCPUs, 4GiB of RAM, and 8GiB of disk for the sandbox
  sandbox, err := client.Create(ctx, types.ImageParams{
    Image: "ubuntu:22.04",
    Resources: &types.Resources{
      CPU:    2,
      Memory: 4,
      Disk:   8,
    },
  })
}
```

## Fleet scaling

Fleet scaling raises the number of sandboxes running at the same time. The unit of scale is the sandbox itself: instead of packing unrelated workloads into one environment, create one sandbox per user, task, or agent.

Sandboxes are isolated from each other, so a fleet scales linearly: each new sandbox adds capacity without contention, and a failure in one sandbox does not affect the others.

The mechanisms differ in what state each new sandbox starts with:

| **Mechanism** | **Starting state** | **Use** |
| --- | --- | --- |
| [**Snapshot fan-out**](/content/docs/en/snapshots/index.html) | Filesystem from the snapshot; hot snapshots add memory state | Any number of identical environments from one prepared snapshot |
| [**Fork**](/content/docs/en/sandboxes#fork-sandboxes/index.html) | Filesystem and memory of a running VM sandbox | Branch a live environment into independent copies |
| [**Linked sandboxes**](/content/docs/en/sandboxes#linked-sandboxes/index.html) | Fresh environment, co-located with a parent on the same runner | Coordinated groups with a local network between parent and children |

**Snapshot fan-out** is the default pattern: prepare the environment once, capture it as a snapshot, and create any number of sandboxes from it. Each sandbox starts with the environment intact, with nothing to reinstall. Sandboxes created from a [hot snapshot](/content/docs/en/snapshots#create-snapshot-from-sandbox/index.html) start with processes already running.

## Workload concurrency

Workload concurrency runs multiple processes inside a single sandbox. A single sandbox can run an API server, a database, and background workers side by side: all processes share the sandbox’s filesystem and network, and exposed ports are reachable through [previews](/content/docs/en/preview/index.html).

A sandbox runs concurrent processes through [sessions](/content/docs/en/process-code-execution#session-operations/index.html). Each session is an independent shell with its own state: working directory, environment variables, and command history.

Commands within a session run sequentially, so parallelism comes from running multiple sessions. Commands started with `run_async` return immediately and run in the background, and [PTY sessions](/content/docs/en/pty/index.html) add interactive terminals.

## Capacity and throughput

Fleet size and creation rate operate within your organization’s limits. Both are [tier-based](/content/docs/en/limits#tiers/index.html) and raised by verification steps or by contacting support.

| **Control** | **What it limits** | **Scope** |
| --- | --- | --- |
| [**Compute pool**](/content/docs/en/limits#resources/index.html) | Total vCPU, RAM, and storage across all running sandboxes | Organization, per region and sandbox class |
| [**Per-sandbox limits**](/content/docs/en/limits/index.html) | Maximum vCPU, RAM, and storage of a single sandbox | Sandbox |
| [**Rate limits**](/content/docs/en/limits#rate-limits/index.html) | Sandbox creation, lifecycle operations, and API requests per minute | Organization |

To scale beyond the shared compute pool, [bring your own compute (BYOC)](/content/docs/en/bring-your-own-compute/index.html) attaches your own runner nodes in custom regions, which have no concurrent resource usage limits.

### Reclaiming capacity

The compute pool is shared by running sandboxes only: stopped, paused, and archived sandboxes free their reserved CPU and memory back to the pool. A fleet can therefore be much larger than the pool, as long as the concurrently running subset fits.

Reclamation runs automatically. [Ephemeral sandboxes](/content/docs/en/sandboxes#ephemeral-sandboxes/index.html) delete themselves on stop, and the [auto-stop, auto-pause, and auto-delete intervals](/content/docs/en/sandboxes#automated-lifecycle-management/index.html) reclaim capacity from idle sandboxes without manual intervention.
