Sandbox
Section titled “Sandbox”Sandbox class for Daytona SDK.
Constructors
Section titled “Constructors”new Sandbox()
Section titled “new Sandbox()”def initialize(sandbox_dto:, config:, sandbox_api:, otel_state:)Returns:
Sandbox- a new instance of Sandbox
Methods
Section titled “Methods”def id()Returns:
String- The ID of the sandbox
organization_id()
Section titled “organization_id()”def organization_id()Returns:
String- The organization ID of the sandbox
snapshot()
Section titled “snapshot()”def snapshot()Returns:
String- The snapshot used for the sandbox
user()
Section titled “user()”def user()Returns:
String- The user associated with the project
def env()Returns:
Hash\<String, String\>- Environment variables for the sandbox
labels()
Section titled “labels()”def labels()Returns:
Hash\<String, String\>- Labels for the sandbox
public()
Section titled “public()”def public()Returns:
Boolean- Whether the sandbox http preview is public
network_block_all()
Section titled “network_block_all()”def network_block_all()Returns:
Boolean- Whether to block all network access for the sandbox
network_allow_list()
Section titled “network_allow_list()”def network_allow_list()Returns:
String- Comma-separated list of allowed CIDR network addresses for the sandbox
target()
Section titled “target()”def target()Returns:
String- The target environment for the sandbox
def cpu()Returns:
Float- The CPU quota for the sandbox
def gpu()Returns:
Float- The GPU quota for the sandbox
memory()
Section titled “memory()”def memory()Returns:
Float- The memory quota for the sandbox
disk()
Section titled “disk()”def disk()Returns:
Float- The disk quota for the sandbox
state()
Section titled “state()”def state()Returns:
DaytonaApiClient:SandboxState- The state of the sandbox
desired_state()
Section titled “desired_state()”def desired_state()Returns:
DaytonaApiClient:SandboxDesiredState- The desired state of the sandbox
error_reason()
Section titled “error_reason()”def error_reason()Returns:
String- The error reason of the sandbox
backup_state()
Section titled “backup_state()”def backup_state()Returns:
String- The state of the backup
backup_created_at()
Section titled “backup_created_at()”def backup_created_at()Returns:
String- The creation timestamp of the last backup
auto_stop_interval()
Section titled “auto_stop_interval()”def auto_stop_interval()Returns:
Float- Auto-stop interval in minutes (0 means disabled)
auto_archive_interval()
Section titled “auto_archive_interval()”def auto_archive_interval()Returns:
Float- Auto-archive interval in minutes
auto_delete_interval()
Section titled “auto_delete_interval()”def auto_delete_interval()(negative value means disabled, 0 means delete immediately upon stopping)
Returns:
Float- Auto-delete interval in minutes
volumes()
Section titled “volumes()”def volumes()Returns:
Array\<DaytonaApiClient:SandboxVolume\>- Array of volumes attached to the sandbox
build_info()
Section titled “build_info()”def build_info()Returns:
DaytonaApiClient:BuildInfo- Build information for the sandbox
created_at()
Section titled “created_at()”def created_at()Returns:
String- The creation timestamp of the sandbox
updated_at()
Section titled “updated_at()”def updated_at()Returns:
String- The last update timestamp of the sandbox
last_activity_at()
Section titled “last_activity_at()”def last_activity_at()Returns:
String- The last activity timestamp of the sandbox
daemon_version()
Section titled “daemon_version()”def daemon_version()Returns:
String- The version of the daemon running in the sandbox
config()
Section titled “config()”def config()Returns:
Daytona:Config
sandbox_api()
Section titled “sandbox_api()”def sandbox_api()Returns:
DaytonaApiClient:SandboxApi
process()
Section titled “process()”def process()Returns:
Daytona:Process
def fs()Returns:
Daytona:FileSystem
def git()Returns:
Daytona:Git
computer_use()
Section titled “computer_use()”def computer_use()Returns:
Daytona:ComputerUse
code_interpreter()
Section titled “code_interpreter()”def code_interpreter()Returns:
Daytona:CodeInterpreter
archive()
Section titled “archive()”def archive()Archives the sandbox, making it inactive and preserving its state. When sandboxes are archived, the entire filesystem state is moved to cost-effective object storage, making it possible to keep sandboxes available for an extended period. The tradeoff between archived and stopped states is that starting an archived sandbox takes more time, depending on its size. Sandbox must be stopped before archiving.
Returns:
void
auto_archive_interval=()
Section titled “auto_archive_interval=()”def auto_archive_interval=(interval)Sets the auto-archive interval for the Sandbox. The Sandbox will automatically archive after being continuously stopped for the specified interval.
Parameters:
intervalInteger -
Returns:
Integer
Raises:
Daytona:Sdk:Error-
auto_delete_interval=()
Section titled “auto_delete_interval=()”def auto_delete_interval=(interval)Sets the auto-delete interval for the Sandbox. The Sandbox will automatically delete after being continuously stopped for the specified interval.
Parameters:
intervalInteger -
Returns:
Integer
Raises:
Daytona:Sdk:Error-
update_network_settings()
Section titled “update_network_settings()”def update_network_settings(network_block_all:, network_allow_list:)Updates outbound network policy on the runner (block all, restore access, or CIDR allow list).
Parameters:
network_block_allBoolean, nil -network_allow_listString, nil -
Returns:
void
Raises:
Daytona:Sdk:Error-
auto_stop_interval=()
Section titled “auto_stop_interval=()”def auto_stop_interval=(interval)Sets the auto-stop interval for the Sandbox. The Sandbox will automatically stop after being idle (no new events) for the specified interval. Events include any state changes or interactions with the Sandbox through the SDK. Interactions using Sandbox Previews are not included.
Parameters:
intervalInteger -
Returns:
Integer
Raises:
Daytona:Sdk:Error-
create_ssh_access()
Section titled “create_ssh_access()”def create_ssh_access(expires_in_minutes)Creates an SSH access token for the sandbox.
Parameters:
expires_in_minutesInteger - TThe number of minutes the SSH access token will be valid for
Returns:
DaytonaApiClient:SshAccessDto
delete()
Section titled “delete()”def delete()Returns:
void
get_user_home_dir()
Section titled “get_user_home_dir()”def get_user_home_dir()Gets the user’s home directory path for the logged in user inside the Sandbox.
Returns:
String- The absolute path to the Sandbox user’s home directory for the logged in user
Examples:
user_home_dir = sandbox.get_user_home_dirputs "Sandbox user home: #{user_home_dir}"get_work_dir()
Section titled “get_work_dir()”def get_work_dir()Gets the working directory path inside the Sandbox.
Returns:
String- The absolute path to the Sandbox working directory. Uses the WORKDIR specified in the Dockerfile if present, or falling back to the user’s home directory if not.
Examples:
work_dir = sandbox.get_work_dirputs "Sandbox working directory: #{work_dir}"labels=()
Section titled “labels=()”def labels=(labels)Sets labels for the Sandbox.
Parameters:
labelsHash<String, String> -
Returns:
Hash\<String, String\>
preview_url()
Section titled “preview_url()”def preview_url(port)Retrieves the preview link for the sandbox at the specified port. If the port is closed, it will be opened automatically. For private sandboxes, a token is included to grant access to the URL.
Parameters:
portInteger -
Returns:
DaytonaApiClient:PortPreviewUrl
create_signed_preview_url()
Section titled “create_signed_preview_url()”def create_signed_preview_url(port, expires_in_seconds)Creates a signed preview URL for the sandbox at the specified port.
Parameters:
portInteger - The port to open the preview link onexpires_in_secondsInteger, nil - The number of seconds the signed preview URL will be valid for. Defaults to 60 seconds.
Returns:
DaytonaApiClient:SignedPortPreviewUrl- The signed preview URL response object
Examples:
signed_url = sandbox.create_signed_preview_url(3000, 120)puts "Signed URL: #{signed_url.url}"puts "Token: #{signed_url.token}"expire_signed_preview_url()
Section titled “expire_signed_preview_url()”def expire_signed_preview_url(port, token)Expires a signed preview URL for the sandbox at the specified port.
Parameters:
portInteger - The port to expire the signed preview URL ontokenString - The token to expire
Returns:
void
Examples:
sandbox.expire_signed_preview_url(3000, "token-value")refresh()
Section titled “refresh()”def refresh()Refresh the Sandbox data from the API.
Returns:
void
refresh_activity()
Section titled “refresh_activity()”def refresh_activity()Refreshes the sandbox activity to reset the timer for automated lifecycle management actions.
This method updates the sandbox’s last activity timestamp without changing its state. It is useful for keeping long-running sessions alive while there is still user activity.
Returns:
void
Examples:
sandbox.refresh_activityrevoke_ssh_access()
Section titled “revoke_ssh_access()”def revoke_ssh_access(token)Revokes an SSH access token for the sandbox.
Parameters:
tokenString -
Returns:
void
start()
Section titled “start()”def start(timeout)Starts the Sandbox and waits for it to be ready.
Parameters:
timeoutNumeric - Maximum wait time in seconds (defaults to 60 s).
Returns:
void
recover()
Section titled “recover()”def recover(timeout)Recovers the Sandbox from a recoverable error and waits for it to be ready.
Parameters:
timeoutNumeric - Maximum wait time in seconds (defaults to 60 s).
Returns:
void
Examples:
sandbox = daytona.get('my-sandbox-id')sandbox.recover(timeout: 40) # Wait up to 40 secondsputs 'Sandbox recovered successfully'stop()
Section titled “stop()”def stop(timeout, force:)Stops the Sandbox and waits for it to be stopped.
Parameters:
timeoutNumeric - Maximum wait time in seconds (defaults to 60 s).forceBoolean - If true, uses SIGKILL instead of SIGTERM (defaults to false).
Returns:
void
resize()
Section titled “resize()”def resize(resources, timeout)Resizes the Sandbox resources.
Changes the CPU, memory, or disk allocation for the Sandbox. Resizing a started sandbox allows increasing CPU and memory. To resize disk or decrease resources, the sandbox must be stopped first.
Parameters:
resourcesDaytona:Resources - New resource configurationtimeoutNumeric - Maximum wait time in seconds (defaults to 60 s)
Returns:
void
Raises:
Sdk:Error-
Examples:
sandbox.resize(Daytona::Resources.new(cpu: 4, memory: 8))sandbox.stopsandbox.resize(Daytona::Resources.new(cpu: 2, memory: 4, disk: 30))wait_for_resize_complete()
Section titled “wait_for_resize_complete()”def wait_for_resize_complete(_timeout)Waits for the Sandbox resize operation to complete. Polls the Sandbox status until the state is no longer ‘resizing’.
Parameters:
timeoutNumeric - Maximum wait time in seconds (defaults to 60 s)
Returns:
void
create_lsp_server()
Section titled “create_lsp_server()”def create_lsp_server(language_id:, path_to_project:)Creates a new Language Server Protocol (LSP) server instance. The LSP server provides language-specific features like code completion, diagnostics, and more.
Parameters:
language_idSymbol - The language server type (e.g., Daytona::LspServer::Language::PYTHON)path_to_projectString - Path to the project root directory. Relative paths are resolved based on the sandbox working directory.
Returns:
Daytona:LspServer
validate_ssh_access()
Section titled “validate_ssh_access()”def validate_ssh_access(token)Validates an SSH access token for the sandbox.
Parameters:
tokenString -
Returns:
DaytonaApiClient:SshAccessValidationDto
wait_for_sandbox_start()
Section titled “wait_for_sandbox_start()”def wait_for_sandbox_start(_timeout)Waits for the Sandbox to reach the ‘started’ state. Polls the Sandbox status until it reaches the ‘started’ state or encounters an error.
Parameters:
timeoutNumeric - Maximum wait time in seconds (defaults to 60 s).
Returns:
void
wait_for_sandbox_stop()
Section titled “wait_for_sandbox_stop()”def wait_for_sandbox_stop(_timeout)Waits for the Sandbox to reach the ‘stopped’ state. Polls the Sandbox status until it reaches the ‘stopped’ state or encounters an error. Treats destroyed as stopped to cover ephemeral sandboxes that are automatically deleted after stopping.
Parameters:
timeoutNumeric - Maximum wait time in seconds (defaults to 60 s).
Returns:
void
experimental_fork()
Section titled “experimental_fork()”def experimental_fork(name:, timeout:)Forks the Sandbox, creating a new Sandbox with an identical filesystem. The forked Sandbox is a copy-on-write clone of the original. It starts with the same disk contents but operates independently from that point on.
Parameters:
nameString, nil - Optional name for the forked SandboxtimeoutNumeric - Maximum wait time in seconds (defaults to 60 s)
Returns:
Daytona:Sandbox- The forked Sandbox
experimental_create_snapshot()
Section titled “experimental_create_snapshot()”def experimental_create_snapshot(name:, timeout:)Creates a snapshot from the current state of the Sandbox. The Sandbox will temporarily enter a ‘snapshotting’ state and return to its previous state when complete.
Parameters:
nameString - Name for the new snapshottimeoutNumeric - Maximum wait time in seconds (defaults to 60 s)
Returns:
void