Modal logo

Sandbox resources and pricing

This page covers resource configuration and pricing for Modal Sandboxes.

Modal Sandboxes differ from many other sandbox providers on two dimensions:

  • Modal Sandboxes have elastic resourcing. They automatically “burst” beyond their CPU and memory requests.
  • You’re charged max(request, actual) for both CPU and memory. When bursting, charging max(request, actual) means you only pay for active-resources.

Sandbox workloads tend to have highly variable resource usage, so this burst model tends to result in prices far lower than most sandbox providers.

See Billing in the resource guide for more details.

Pay for what you use 

By default, each Sandbox requests 0.125 CPU cores and 128 MiB of memory and bursts beyond that as needed.

Modal schedules and packs Sandboxes onto hosts so that additional CPU and memory is available the vast majority of the time. The worst case is an out-of-memory eviction, and Modal backs its burst model with an eviction probability SLO of less than 0.0001% per minute for Sandboxes above their request but under 8 GiB (about 1 eviction per 694 Sandbox-days). Because Sandboxes can reliably burst to use additional resources, most workloads don’t need to set a resource request for their Sandboxes.

Not setting a resource request means you only pay for the resources your Sandbox is actively using each second, with the small default request as the minimum.

Setting resource requests 

Requesting resources guarantees your Sandbox a minimum amount of CPU and memory. You are charged for requested resources for the lifetime of your Sandbox, regardless of whether the resources are being used.

Set CPU and memory requests using the cpu and memory parameters when creating your Sandbox. The cpu parameter specifies physical CPU cores (1 core = 2 vCPUs), and memory specifies MiB:

import modal

app = modal.App.lookup("my-app", create_if_missing=True)

sb = modal.Sandbox.create(
    cpu=0.5,
    memory=512,
    app=app,
)

For details on default values and maximum limits, see Reserving CPU and memory.

Setting resource limits 

You can set upper limits to cap how much a Sandbox can burst. Limits are particularly useful when an AI agent controls what runs inside the Sandbox, as they prevent misbehaving or adversarial workloads from consuming unbounded resources. They also let you evaluate agents on bounded resources, like when running evals.

sb = modal.Sandbox.create(
    cpu=(0.5, 4.0),       # Request 0.5 cores, limit to 4 cores
    memory=(512, 2048),   # Request 512 MiB, limit to 2048 MiB
    app=app,
)

See Resource limits for details on how CPU and memory limits behave.

Tuning your requests 

The Sandboxes tab on an App page has metrics to help you monitor your bursting and, if needed, find the right request size: CPU Per Sandbox, Memory Per Sandbox, CPU Pressure Per Sandbox, and Exit Reasons.

Resource-sizing charts on the Sandboxes metrics tab

CPU Per Sandbox and Memory Per Sandbox show percentiles of how much CPU and memory your Sandboxes actually use. And CPU Pressure Per Sandbox and Exit Reasons tell you if a request is too low. CPU Pressure Per Sandbox tracks time Sandboxes spent stalled waiting for CPU; Exit Reasons tracks Sandboxes evicted while exceeding their memory request.

  1. Start with the default request values for CPU and memory, which are used when you omit the cpu and memory parameters.

  2. Run your typical workload and check CPU Per Sandbox and Memory Per Sandbox to see your actual usage.

  3. Check CPU Pressure Per Sandbox and Exit Reasons to confirm that throttling and evictions are at acceptable levels.

  4. If evictions are higher than needed, raise the resource request based on your observed usage.

Disk 

Sandboxes have the same disk limits as other Modal containers, and their disk size cannot be increased. On the VM runtime, the root filesystem is a fixed 512 GiB.

GPU Sandboxes 

You can also run Sandboxes with GPUs. See GPU acceleration for available GPU types and configuration. GPU Sandboxes are only supported with runtime="gvisor".

Unlike CPU Sandboxes, GPU Sandboxes are subject to preemption. Design your GPU workloads to handle interruptions gracefully.

Cost attribution 

The cost attribution tools in the billing guide let you attribute spend by App, including costs aggregated over all of an App’s Sandboxes.

For a more granular breakdown of Sandbox cost, use App.sandboxes.stats() to query costs over a time range, grouped by the values of Sandbox tags. This example prints the last 24 hours of cost for each value of the major_version tag:

from datetime import datetime, timedelta, timezone

app = modal.App.lookup("my-app")

this_hour = datetime.now(timezone.utc).replace(minute=0, second=0, microsecond=0)
since = this_hour - timedelta(days=1)

for group in app.sandboxes.stats(since=since, group_by_tags=["major_version"]):
    print(group.tags["major_version"], group.cost, group.cost_by_resource)

Each group has a total cost in USD and a breakdown by billed resource, such as CPU, Memory, and GPU type.

  • since, and until if you pass it, must be on a UTC hour boundary, and a query can span at most 7 days.
  • Sandboxes that don’t have a tag you group by are still counted, with a null value for that tag.
  • To filter by tag, pass tags. Only Sandboxes that have all of those tags and values are included.
  • Costs don’t account for credits or reservations, so your invoice may be lower.

For all parameters and return types, see the SDK reference (Python, JavaScript, Go).

Additional resources