Skip to content

Sandbox Management

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

Creating Sandboxes

Daytona SDK provides an option to create Sandboxes with default or custom configurations. You can specify the language, image, resources, environment variables, and volumes for the Sandbox. By default, the sandboxes auto-stop after 15 minutes of inactivity. To overwrite this behavior, you can increase the auto-stop interval or set it to 0 to completely disable it.

Basic Sandbox Creation

Daytona SDK provides methods to create Sandboxes with default configurations, specific languages, or custom IDs using Python and TypeScript.

from daytona_sdk import Daytona
daytona = Daytona()
# Create a basic Sandbox
sandbox = daytona.create()
# Create a Sandbox with specific language
params = CreateSandboxParams(language="python")
sandbox = daytona.create(params)
# Create a Sandbox with custom ID
params = CreateSandboxParams(id="my-sandbox")
sandbox = daytona.create(params)

Sandbox Information

Daytona SDK provides methods to get information about a Sandbox, such as ID, root directory, and status using Python and TypeScript.

# Get Sandbox ID
sandbox_id = sandbox.id
# Get the root directory of tha Sandbox user
root_dir = sandbox.get_user_root_dir()
# Get the Sandbox name, image and state
name = sandbox.instance.name
image = sandbox.instance.image
state = sandbox.instance.state
# Get the preview link for an app running on port 3000
preview_link = sandbox.get_preview_link(3000)

Remove Sandbox

Daytona SDK provides methods to perform operations on Sandboxes, such as removing Sandboxes using Python and TypeScript.

# Remove Sandbox
daytona.remove(sandbox)

Sandbox Persistence

Daytona keeps the filesystem in its entirety during the Sandbox lifecycle. The persistence functionality is built into the system, and nothing needs to be explicitly done from the user side.

It is important to understand the Sandbox states to maintain cost-effectiveness. A Sandbox can have three states during its lifecycle:

Running

Running Sandboxes utilize CPU, memory, and disk storage. Every resource is charged per second of usage. When Sandboxes are not actively used, it is recommended that they be stopped. This can be done:

  • Manually using the stop command
  • Automatically by setting the autoStop interval

Stopped

Stopped Sandboxes only utilize disk storage. They can be instantly started when needed. The stopped state should be used when the Sandbox is expected to be started again soon. Otherwise, it is recommended to archive the Sandbox to eliminate disk usage costs.

Archived

When Sandboxes are archived, the entire filesystem state is moved to very cost-effective object storage, making it possible to keep Sandboxes available for an extended period.

Performance Considerations

The tradeoff between archived and stopped states is that starting an archived Sandbox takes more time, depending on its size.