コンテンツにスキップ

Sandboxes

View as Markdown

このコンテンツはまだ日本語訳がありません。

Sandboxes are isolated runtime environments managed by Daytona. This guide covers the lifecycle of Sandboxes and how to create, manage, and remove them using the Daytona SDK.

Daytona Sandboxes use 1 vCPU, 1GB RAM, and 3GiB disk by default. Organizations get a maximum sandbox resource limit of 4 vCPUs, 8GB RAM, and 10GB disk. For more power, contact support@daytona.io.

Sandbox lifecycle

Throughout its lifecycle, a Daytona Sandbox can have several different states. The diagram below shows the states and possible transitions between them.

Sandbox lifecycle diagram

Multiple runtime support

Daytona Sandboxes support Python, TypeScript, and JavaScript programming language runtimes for direct code execution inside the sandbox.

The language parameter controls which programming language runtime is used for the sandbox:

  • python
  • typescript
  • javascript

If omitted, the Daytona SDK will default to python. To override this, explicitly set the language value when creating the sandbox.

Create Sandboxes

Daytona provides options to programmatically create sandboxes with default or custom configurations. You can specify programming language runtime, snapshots, resources, environment variables, and volumes for each sandbox. Running sandboxes utilize CPU, memory, and disk storage. Every resource is charged per second of usage.

from daytona import Daytona, CreateSandboxFromSnapshotParams
daytona = Daytona()
# Create a sandbox
sandbox = daytona.create()
# Create a sandbox with python
params = CreateSandboxFromSnapshotParams(language="python")
sandbox = daytona.create(params)
# Create a sandbox with a custom name
params = CreateSandboxFromSnapshotParams(name="my_awesome_sandbox")
sandbox = daytona.create(params)
# Create a sandbox with custom labels
params = CreateSandboxFromSnapshotParams(labels={"LABEL": "label"})
sandbox = daytona.create(params)

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, API, and CLI references:

create (Python SDK)

create (TypeScript SDK)

create (Ruby SDK)

Create (Go SDK)

create (CLI)

create (API)

Resources

Daytona Sandbox uses 1 vCPU, 1GB RAM, and 3GiB disk by default.

Daytona keeps a pool of warm sandboxes using default snapshots. When available, sandboxes launch within milliseconds instead of cold-booting.

To set custom sandbox resources (CPU, memory, and disk space), use the Resources class:

from daytona import Daytona, Resources, CreateSandboxFromImageParams, Image
daytona = Daytona()
# Create a sandbox with custom resources
resources = Resources(
cpu=2, # 2 CPU cores
memory=4, # 4GB RAM
disk=8, # 8GB disk space
)
params = CreateSandboxFromImageParams(
image=Image.debian_slim("3.12"),
resources=resources
)
sandbox = daytona.create(params)

All resource parameters are optional. If not specified, Daytona will use default values appropriate for the selected language and use case.

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, CLI, and API references:

Resources (Python SDK)

Resources (TypeScript SDK)

Resources (Ruby SDK)

Resources (API)

Resources (CLI)

Ephemeral Sandboxes

Ephemeral Sandboxes are automatically deleted once they are stopped. They are useful for short-lived tasks or for testing purposes.

To create an ephemeral Sandbox, set the ephemeral parameter to True when creating a sandbox:

from daytona import Daytona, CreateSandboxFromSnapshotParams
daytona = Daytona()
# Create an ephemeral sandbox
params = CreateSandboxFromSnapshotParams(
ephemeral=True,
auto_stop_interval=5 # The ephemeral sandbox will be deleted after 5 minutes of inactivity
)
sandbox = daytona.create(params)

Network settings (Firewall)

Daytona Sandboxes provide configurable network firewall controls to enhance security and manage connectivity. By default, network access follows standard security policies, but you can customize network settings when creating a sandbox.

Start Sandboxes

Daytona provides options to start sandboxes in Daytona Dashboard ↗ or programmatically using the Python SDK, TypeScript SDK, Ruby SDK, CLI, and API references.

  1. Navigate to Daytona Sandboxes ↗
  2. Click the start icon () next to the sandbox you want to start.
Starting sandbox with ID: <sandbox-id>
sandbox = daytona.create(CreateSandboxFromSnapshotParams(language="python"))
# Start Sandbox
sandbox.start()

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, CLI, and API references:

start (Python SDK)

start (TypeScript SDK)

start (Ruby SDK)

Start (Go SDK)

start (CLI)

start (API)

List Sandboxes

Daytona provides options to view information about sandboxes (ID, root directory, and status) and manage their lifecycle.

# List all sandboxes
result = daytona.list()
# Iterate through results
for sandbox in result.items:
print(f"Sandbox: {sandbox.id} (state: {sandbox.state})")
# List sandboxes with labels filter
result = daytona.list(labels={"env": "dev"})

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, CLI, and API references:

list (Python SDK)

list (TypeScript SDK)

list (Ruby SDK)

List (Go SDK)

list (CLI)

list (API)

Stop Sandboxes

Daytona provides methods to stop sandboxes in Daytona Dashboard ↗ or programmatically using the Python SDK, TypeScript SDK, and Ruby SDK.

  1. Navigate to Daytona Sandboxes ↗
  2. Click the stop icon () next to the sandbox you want to stop.
Stopping sandbox with ID: <sandbox-id>

Stopped sandboxes maintain filesystem persistence while their memory state is cleared. They incur only disk usage costs and can be started again when needed.

The stopped state should be used when a sandbox is expected to be started again soon. Otherwise, it is recommended to stop and then archive the sandbox to eliminate disk usage costs.

sandbox = daytona.create(CreateSandboxFromSnapshotParams(language="python"))
# Stop sandbox
sandbox.stop()
print(sandbox.id) # 7cd11133-96c1-4cc8-9baa-c757b8f8c916
# The sandbox ID can later be used to find the sandbox and start it
sandbox = daytona.find_one("7cd11133-96c1-4cc8-9baa-c757b8f8c916")
# Start sandbox
sandbox.start()

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, CLI, and API references:

stop (Python SDK)

stop (TypeScript SDK)

stop (Ruby SDK)

Stop (Go SDK)

find_one (Python SDK)

findOne (TypeScript SDK)

find_one (Ruby SDK)

FindOne (Go SDK)

stop (CLI)

stop (API)

Archive Sandboxes

Daytona provides methods to archive sandboxes in Daytona Dashboard ↗ or programmatically using the Python SDK, TypeScript SDK, and Ruby SDK.

When sandboxes are archived, the entire filesystem state is moved to a cost-effective object storage, making it possible to keep sandboxes available for an extended period. Starting an archived sandbox takes more time than starting a stopped sandbox, depending on its size.

A sandbox must be stopped before it can be archived and can be started again in the same way as a stopped sandbox.

# Archive Sandbox
sandbox.archive()

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, CLI, and API references:

archive (Python SDK)

archive (TypeScript SDK)

archive (Ruby SDK)

Archive (Go SDK)

archive (CLI)

archive (API)

Recover Sandboxes

Daytona provides methods to recover sandboxes in Daytona Dashboard ↗ or programmatically using the Python SDK, TypeScript SDK, and Ruby SDK.

# Recover sandbox
sandbox.recover()

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, and API references:

recover (Python SDK)

recover (TypeScript SDK)

recover (Ruby SDK)

recover (API)

Recover from error state

When a sandbox enters an error state, it can sometimes be recovered using the recover method, depending on the underlying error reason. The recoverable flag indicates whether the error state can be resolved through an automated recovery procedure.

# Check if the Sandbox is recoverable
if sandbox.recoverable:
sandbox.recover()
print("Sandbox recovered successfully")

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, and API references:

recover (Python SDK)

recover (TypeScript SDK)

recover (Ruby SDK)

recover (API)

Resize Sandboxes

Daytona provides methods to resize sandbox resources (CPU, memory, and disk) after creation.

Resizing a started sandbox allows you to increase CPU and memory without interruption. To increase disk capacity or decrease CPU and memory, the sandbox must be stopped first.

from daytona import Daytona, Resources
daytona = Daytona()
sandbox = daytona.create()
# Resize a started sandbox (CPU and memory can be increased)
sandbox.resize(Resources(cpu=2, memory=4))
# Resize a stopped sandbox (CPU, memory, and disk can be changed)
sandbox.stop()
sandbox.resize(Resources(cpu=4, memory=8, disk=20))
sandbox.start()

For more information, see the Python SDK, TypeScript SDK, Go SDK, and Ruby SDK references:

resize (Python SDK)

resize (TypeScript SDK)

Resize (Go SDK)

resize (Ruby SDK)

Delete Sandboxes

Daytona provides methods to delete sandboxes in Daytona Dashboard ↗ or programmatically using the Python SDK, TypeScript SDK, and Ruby SDK.

  1. Navigate to Daytona Sandboxes ↗
  2. Click the Delete button next to the sandbox you want to delete.
Deleting sandbox with ID: <sandbox-id>
# Delete sandbox
sandbox.delete()

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, CLI, and API references:

delete (Python SDK)

delete (TypeScript SDK)

delete (Ruby SDK)

Delete (Go SDK)

delete (CLI)

delete (API)

Automated lifecycle management

Daytona Sandboxes can be automatically stopped, archived, and deleted based on user-defined intervals.

Auto-stop interval

The auto-stop interval parameter sets the amount of time after which a running sandbox will be automatically stopped.

The auto-stop interval will trigger even if there are internal processes running in the sandbox. The system differentiates between “internal processes” and “active user interaction”. Merely having a script or background task running is not sufficient to keep the sandbox alive.

The parameter can either be set to:

  • a time interval in minutes
  • 0: disables the auto-stop functionality, allowing the sandbox to run indefinitely

If the parameter is not set, the default interval of 15 minutes will be used.

sandbox = daytona.create(CreateSandboxFromSnapshotParams(
snapshot="my-snapshot-name",
# Disables the auto-stop feature - default is 15 minutes
auto_stop_interval=0,
))

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

set_autostop_interval (Python SDK)

setAutostopInterval (TypeScript SDK)

auto_stop_interval (Ruby SDK)

set_auto_stop_interval (API)

What resets the timer

The inactivity timer resets only for specific external interactions:

What does not reset the timer

The following do not reset the timer:

  • SDK calls that are not toolbox actions
  • Background scripts (e.g., npm run dev run as a fire-and-forget command)
  • Long-running tasks without external interaction
  • Processes that don’t involve active monitoring

If you run a long-running task like LLM inference that takes more than 15 minutes without any external interaction, the sandbox may auto-stop mid-process because the process itself doesn’t count as “activity”.

Auto-archive interval

Daytona provides methods to set the auto-archive interval using the Python SDK, TypeScript SDK, and Ruby SDK.

The auto-archive interval parameter sets the amount of time after which a continuously stopped sandbox will be automatically archived.

The parameter can either be set to:

  • a time interval in minutes
  • 0: the maximum interval of 30 days will be used

If the parameter is not set, the default interval of 7 days will be used.

sandbox = daytona.create(CreateSandboxFromSnapshotParams(
snapshot="my-snapshot-name",
# Auto-archive after a sandbox has been stopped for 1 hour
auto_archive_interval=60,
))

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

set_auto_archive_interval (Python SDK)

setAutoArchiveInterval (TypeScript SDK)

auto_archive_interval (Ruby SDK)

SetAutoArchiveInterval (Go SDK)

set_auto_archive_interval (API)

Auto-delete interval

Daytona provides methods to set the auto-delete interval using the Python SDK, TypeScript SDK, and Ruby SDK.

The auto-delete interval parameter sets the amount of time after which a continuously stopped sandbox will be automatically deleted. By default, sandboxes will never be automatically deleted.

The parameter can either be set to:

  • a time interval in minutes
  • -1: disables the auto-delete functionality
  • 0: the sandbox will be deleted immediately after stopping

If the parameter is not set, the sandbox will not be deleted automatically.

sandbox = daytona.create(CreateSandboxFromSnapshotParams(
snapshot="my-snapshot-name",
# Auto-delete after a sandbox has been stopped for 1 hour
auto_delete_interval=60,
))
# Delete the sandbox immediately after it has been stopped
sandbox.set_auto_delete_interval(0)
# Disable auto-deletion
sandbox.set_auto_delete_interval(-1)

For more information, see the Python SDK, TypeScript SDK, Ruby SDK, Go SDK, and API references:

set_auto_delete_interval (Python SDK)

setAutoDeleteInterval (TypeScript SDK)

auto_delete_interval (Ruby SDK)

SetAutoDeleteInterval (Go SDK)

set_auto_delete_interval (API)

Running indefinitely

Daytona provides methods to run sandboxes indefinitely using the Python SDK, TypeScript SDK, and Ruby SDK.

By default, Daytona Sandboxes auto-stop after 15 minutes of inactivity. To keep a sandbox running without interruption, set the auto-stop interval to 0 when creating a new sandbox:

sandbox = daytona.create(CreateSandboxFromSnapshotParams(
snapshot="my_awesome_snapshot",
# Disables the auto-stop feature - default is 15 minutes
auto_stop_interval=0,
))