apps/docs/src/content/docs/en/ruby-sdk/sandbox.mdx
Sandbox class for Daytona SDK.
def initialize(sandbox_dto:, config:, sandbox_api:, otel_state:)
Returns:
Sandbox - a new instance of Sandboxdef id()
Returns:
String - The ID of the sandboxdef organization_id()
Returns:
String - The organization ID of the sandboxdef snapshot()
Returns:
String - The snapshot used for the sandboxdef user()
Returns:
String - The user associated with the projectdef env()
Returns:
Hash\<String, String\>, nil - Environment variables for the sandbox.
Not returned by list results; call #refresh on each item to populate.def labels()
Returns:
Hash\<String, String\> - Labels for the sandboxdef public()
Returns:
Boolean - Whether the sandbox http preview is publicdef network_block_all()
Returns:
Boolean, nil - Whether to block all network access for the sandbox.
Not returned by list results; call #refresh on each item to populate.def network_allow_list()
Returns:
String, nil - Comma-separated list of allowed CIDR network addresses for the sandbox.
Not returned by list results; call #refresh on each item to populate.def target()
Returns:
String - The target environment for the sandboxdef cpu()
Returns:
Float - The CPU quota for the sandboxdef gpu()
Returns:
Float - The GPU quota for the sandboxdef memory()
Returns:
Float - The memory quota for the sandboxdef disk()
Returns:
Float - The disk quota for the sandboxdef state()
Returns:
DaytonaApiClient:SandboxState - The state of the sandboxdef desired_state()
Returns:
DaytonaApiClient:SandboxDesiredState - The desired state of the sandboxdef error_reason()
Returns:
String - The error reason of the sandboxdef backup_state()
Returns:
String - The state of the backupdef backup_created_at()
Returns:
String, nil - The creation timestamp of the last backup.
Not returned by list results; call #refresh on each item to populate.def auto_stop_interval()
Returns:
Float - Auto-stop interval in minutes (0 means disabled)def auto_archive_interval()
Returns:
Float - Auto-archive interval in minutesdef auto_delete_interval()
(negative value means disabled, 0 means delete immediately upon stopping)
Returns:
Float - Auto-delete interval in minutesdef volumes()
Returns:
Array\<DaytonaApiClient:SandboxVolume\>, nil - Volumes attached to the sandbox.
Not returned by list results; call #refresh on each item to populate.def build_info()
Returns:
DaytonaApiClient:BuildInfo, nil - Build information for the sandbox if it was
created from a dynamic build.
Not returned by list results; call #refresh on each item to populate.def created_at()
Returns:
String - The creation timestamp of the sandboxdef updated_at()
Returns:
String - The last update timestamp of the sandboxdef last_activity_at()
Returns:
String - The last activity timestamp of the sandboxdef daemon_version()
Returns:
String - The version of the daemon running in the sandboxdef config()
Returns:
Daytona:Configdef sandbox_api()
Returns:
DaytonaApiClient:SandboxApidef process()
Returns:
Daytona:Processdef fs()
Returns:
Daytona:FileSystemdef git()
Returns:
Daytona:Gitdef computer_use()
Returns:
Daytona:ComputerUsedef code_interpreter()
Returns:
Daytona:CodeInterpreterdef 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:
voiddef 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:
interval Integer -Returns:
IntegerRaises:
Daytona:Sdk:Error -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:
interval Integer -Returns:
IntegerRaises:
Daytona:Sdk:Error -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_all Boolean, nil -network_allow_list String, nil -Returns:
voidRaises:
Daytona:Sdk:Error -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:
interval Integer -Returns:
IntegerRaises:
Daytona:Sdk:Error -def create_ssh_access(expires_in_minutes)
Creates an SSH access token for the sandbox.
Parameters:
expires_in_minutes Integer - TThe number of minutes the SSH access token will be valid forReturns:
DaytonaApiClient:SshAccessDtodef delete()
Returns:
voiddef 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 userExamples:
user_home_dir = sandbox.get_user_home_dir
puts "Sandbox user home: #{user_home_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_dir
puts "Sandbox working directory: #{work_dir}"
def labels=(labels)
Sets labels for the Sandbox.
Parameters:
labels Hash<String, String> -Returns:
Hash\<String, String\>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:
port Integer -Returns:
DaytonaApiClient:PortPreviewUrldef create_signed_preview_url(port, expires_in_seconds)
Creates a signed preview URL for the sandbox at the specified port.
Parameters:
port Integer - The port to open the preview link onexpires_in_seconds Integer, 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 objectExamples:
signed_url = sandbox.create_signed_preview_url(3000, 120)
puts "Signed URL: #{signed_url.url}"
puts "Token: #{signed_url.token}"
def expire_signed_preview_url(port, token)
Expires a signed preview URL for the sandbox at the specified port.
Parameters:
port Integer - The port to expire the signed preview URL ontoken String - The token to expireReturns:
voidExamples:
sandbox.expire_signed_preview_url(3000, "token-value")
def refresh()
Refresh the Sandbox data from the API.
Returns:
voiddef 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:
voidExamples:
sandbox.refresh_activity
def revoke_ssh_access(token)
Revokes an SSH access token for the sandbox.
Parameters:
token String -Returns:
voiddef start(timeout)
Starts the Sandbox and waits for it to be ready.
Parameters:
timeout Numeric - Maximum wait time in seconds (defaults to 60 s).Returns:
voiddef recover(timeout)
Recovers the Sandbox from a recoverable error and waits for it to be ready.
Parameters:
timeout Numeric - Maximum wait time in seconds (defaults to 60 s).Returns:
voidExamples:
sandbox = daytona.get('my-sandbox-id')
sandbox.recover(timeout: 40) # Wait up to 40 seconds
puts 'Sandbox recovered successfully'
def stop(timeout, force:)
Stops the Sandbox and waits for it to be stopped.
Parameters:
timeout Numeric - Maximum wait time in seconds (defaults to 60 s).force Boolean - If true, uses SIGKILL instead of SIGTERM (defaults to false).Returns:
voiddef 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:
resources Daytona:Resources - New resource configurationtimeout Numeric - Maximum wait time in seconds (defaults to 60 s)Returns:
voidRaises:
Sdk:Error -Examples:
sandbox.resize(Daytona::Resources.new(cpu: 4, memory: 8))
sandbox.stop
sandbox.resize(Daytona::Resources.new(cpu: 2, memory: 4, disk: 30))
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:
timeout Numeric - Maximum wait time in seconds (defaults to 60 s)Returns:
voiddef 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_id Symbol - The language server type (e.g., Daytona::LspServer::Language::PYTHON)path_to_project String - Path to the project root directory. Relative paths are resolved
based on the sandbox working directory.Returns:
Daytona:LspServerdef validate_ssh_access(token)
Validates an SSH access token for the sandbox.
Parameters:
token String -Returns:
DaytonaApiClient:SshAccessValidationDtodef 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:
timeout Numeric - Maximum wait time in seconds (defaults to 60 s).Returns:
voiddef 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:
timeout Numeric - Maximum wait time in seconds (defaults to 60 s).Returns:
voiddef 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:
name String, nil - Optional name for the forked Sandboxtimeout Numeric - Maximum wait time in seconds (defaults to 60 s)Returns:
Daytona:Sandbox - The forked Sandboxdef 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:
name String - Name for the new snapshottimeout Numeric - Maximum wait time in seconds (defaults to 60 s)Returns:
void