Class: Daytona::Sandbox
- Inherits:
-
Object
- Object
- Daytona::Sandbox
- Includes:
- Instrumentation
- Defined in:
- lib/daytona/sandbox.rb
Overview
rubocop:disable Metrics/ClassLength
Constant Summary collapse
- DEFAULT_TIMEOUT =
60
Instance Attribute Summary collapse
-
#auto_archive_interval ⇒ Float
Auto-archive interval in minutes.
-
#auto_delete_interval ⇒ Float
(negative value means disabled, 0 means delete immediately upon stopping).
-
#auto_stop_interval ⇒ Float
Auto-stop interval in minutes (0 means disabled).
-
#backup_created_at ⇒ String?
readonly
The creation timestamp of the last backup.
-
#backup_state ⇒ String
readonly
The state of the backup.
-
#build_info ⇒ DaytonaApiClient::BuildInfo?
readonly
Build information for the sandbox if it was created from a dynamic build.
- #code_interpreter ⇒ Daytona::CodeInterpreter readonly
- #computer_use ⇒ Daytona::ComputerUse readonly
- #config ⇒ Daytona::Config readonly
-
#cpu ⇒ Float
readonly
The CPU quota for the sandbox.
-
#created_at ⇒ String
readonly
The creation timestamp of the sandbox.
-
#daemon_version ⇒ String
readonly
The version of the daemon running in the sandbox.
-
#desired_state ⇒ DaytonaApiClient::SandboxDesiredState
readonly
The desired state of the sandbox.
-
#disk ⇒ Float
readonly
The disk quota for the sandbox.
-
#env ⇒ Hash<String, String>?
readonly
Environment variables for the sandbox.
-
#error_reason ⇒ String
readonly
The error reason of the sandbox.
- #fs ⇒ Daytona::FileSystem readonly
- #git ⇒ Daytona::Git readonly
-
#gpu ⇒ Float
readonly
The GPU quota for the sandbox.
-
#id ⇒ String
readonly
The ID of the sandbox.
-
#labels ⇒ Hash<String, String>
Labels for the sandbox.
-
#last_activity_at ⇒ String
readonly
The last activity timestamp of the sandbox.
-
#memory ⇒ Float
readonly
The memory quota for the sandbox.
-
#network_allow_list ⇒ String?
readonly
Comma-separated list of allowed CIDR network addresses for the sandbox.
-
#network_block_all ⇒ Boolean?
readonly
Whether to block all network access for the sandbox.
-
#organization_id ⇒ String
readonly
The organization ID of the sandbox.
- #process ⇒ Daytona::Process readonly
-
#public ⇒ Boolean
readonly
Whether the sandbox http preview is public.
- #sandbox_api ⇒ DaytonaApiClient::SandboxApi readonly
-
#snapshot ⇒ String
readonly
The snapshot used for the sandbox.
-
#state ⇒ DaytonaApiClient::SandboxState
readonly
The state of the sandbox.
-
#target ⇒ String
readonly
The target environment for the sandbox.
-
#updated_at ⇒ String
readonly
The last update timestamp of the sandbox.
-
#user ⇒ String
readonly
The user associated with the project.
-
#volumes ⇒ Array<DaytonaApiClient::SandboxVolume>?
readonly
Volumes attached to the sandbox.
Instance Method Summary collapse
-
#archive ⇒ void
Archives the sandbox, making it inactive and preserving its state.
-
#create_lsp_server(language_id:, path_to_project:) ⇒ Daytona::LspServer
Creates a new Language Server Protocol (LSP) server instance.
-
#create_signed_preview_url(port, expires_in_seconds = nil) ⇒ DaytonaApiClient::SignedPortPreviewUrl
Creates a signed preview URL for the sandbox at the specified port.
-
#create_ssh_access(expires_in_minutes) ⇒ DaytonaApiClient::SshAccessDto
Creates an SSH access token for the sandbox.
- #delete ⇒ void
-
#experimental_create_snapshot(name:, timeout: DEFAULT_TIMEOUT) ⇒ void
Creates a snapshot from the current state of the Sandbox.
-
#experimental_fork(name: nil, timeout: DEFAULT_TIMEOUT) ⇒ Daytona::Sandbox
Forks the Sandbox, creating a new Sandbox with an identical filesystem.
-
#expire_signed_preview_url(port, token) ⇒ void
Expires a signed preview URL for the sandbox at the specified port.
-
#get_user_home_dir ⇒ String
Gets the user’s home directory path for the logged in user inside the Sandbox.
-
#get_work_dir ⇒ String
Gets the working directory path inside the Sandbox.
-
#initialize(sandbox_dto:, config:, sandbox_api:, otel_state: nil) ⇒ Sandbox
constructor
A new instance of Sandbox.
-
#preview_url(port) ⇒ DaytonaApiClient::PortPreviewUrl
Retrieves the preview link for the sandbox at the specified port.
-
#recover(timeout = DEFAULT_TIMEOUT) ⇒ void
Recovers the Sandbox from a recoverable error and waits for it to be ready.
-
#refresh ⇒ void
Refresh the Sandbox data from the API.
-
#refresh_activity ⇒ void
Refreshes the sandbox activity to reset the timer for automated lifecycle management actions.
-
#resize(resources, timeout = DEFAULT_TIMEOUT) ⇒ void
Resizes the Sandbox resources.
-
#revoke_ssh_access(token) ⇒ void
Revokes an SSH access token for the sandbox.
-
#start(timeout = DEFAULT_TIMEOUT) ⇒ void
Starts the Sandbox and waits for it to be ready.
-
#stop(timeout = DEFAULT_TIMEOUT, force: false) ⇒ void
Stops the Sandbox and waits for it to be stopped.
-
#update_network_settings(network_block_all: nil, network_allow_list: nil) ⇒ void
Updates outbound network policy on the runner (block all, restore access, or CIDR allow list).
-
#validate_ssh_access(token) ⇒ DaytonaApiClient::SshAccessValidationDto
Validates an SSH access token for the sandbox.
-
#wait_for_resize_complete(_timeout = DEFAULT_TIMEOUT) ⇒ void
Waits for the Sandbox resize operation to complete.
-
#wait_for_sandbox_start(_timeout = DEFAULT_TIMEOUT) ⇒ void
Waits for the Sandbox to reach the ‘started’ state.
-
#wait_for_sandbox_stop(_timeout = DEFAULT_TIMEOUT) ⇒ void
Waits for the Sandbox to reach the ‘stopped’ state.
Methods included from Instrumentation
Constructor Details
#initialize(sandbox_dto:, config:, sandbox_api:, otel_state: nil) ⇒ Sandbox
Returns a new instance of Sandbox.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/daytona/sandbox.rb', line 131 def initialize(sandbox_dto:, config:, sandbox_api:, otel_state: nil) # rubocop:disable Metrics/MethodLength process_response(sandbox_dto) @config = config @sandbox_api = sandbox_api @otel_state = otel_state # Create toolbox API clients with dynamic configuration toolbox_api_config = build_toolbox_api_config # Helper to create API client with authentication header create_authenticated_client = lambda do client = DaytonaToolboxApiClient::ApiClient.new(toolbox_api_config) client.default_headers['Authorization'] = "Bearer #{config.api_key || config.jwt_token}" client.default_headers['X-Daytona-Source'] = 'sdk-ruby' client.default_headers['X-Daytona-SDK-Version'] = Sdk::VERSION client.default_headers['X-Daytona-Organization-ID'] = config.organization_id if config.jwt_token client.user_agent = "sdk-ruby/#{Sdk::VERSION}" client end process_api = DaytonaToolboxApiClient::ProcessApi.new(create_authenticated_client.call) fs_api = DaytonaToolboxApiClient::FileSystemApi.new(create_authenticated_client.call) git_api = DaytonaToolboxApiClient::GitApi.new(create_authenticated_client.call) lsp_api = DaytonaToolboxApiClient::LspApi.new(create_authenticated_client.call) computer_use_api = DaytonaToolboxApiClient::ComputerUseApi.new(create_authenticated_client.call) interpreter_api = DaytonaToolboxApiClient::InterpreterApi.new(create_authenticated_client.call) info_api = DaytonaToolboxApiClient::InfoApi.new(create_authenticated_client.call) @process = Process.new( sandbox_id: id, toolbox_api: process_api, get_preview_link: proc { |port| preview_url(port) }, language: (labels || {}).fetch(CODE_TOOLBOX_LANGUAGE_LABEL, 'python'), otel_state: ) @fs = FileSystem.new(sandbox_id: id, toolbox_api: fs_api, otel_state:) @git = Git.new(sandbox_id: id, toolbox_api: git_api, otel_state:) @computer_use = ComputerUse.new(sandbox_id: id, toolbox_api: computer_use_api, otel_state:) @code_interpreter = CodeInterpreter.new( sandbox_id: id, toolbox_api: interpreter_api, get_preview_link: proc { |port| preview_url(port) }, otel_state: ) @lsp_api = lsp_api @info_api = info_api end |
Instance Attribute Details
#auto_archive_interval ⇒ Float
Returns Auto-archive interval in minutes.
79 80 81 |
# File 'lib/daytona/sandbox.rb', line 79 def auto_archive_interval @auto_archive_interval end |
#auto_delete_interval ⇒ Float
(negative value means disabled, 0 means delete immediately upon stopping)
83 84 85 |
# File 'lib/daytona/sandbox.rb', line 83 def auto_delete_interval @auto_delete_interval end |
#auto_stop_interval ⇒ Float
Returns Auto-stop interval in minutes (0 means disabled).
76 77 78 |
# File 'lib/daytona/sandbox.rb', line 76 def auto_stop_interval @auto_stop_interval end |
#backup_created_at ⇒ String? (readonly)
Returns The creation timestamp of the last backup. Not returned by list results; call #refresh on each item to populate.
73 74 75 |
# File 'lib/daytona/sandbox.rb', line 73 def backup_created_at @backup_created_at end |
#backup_state ⇒ String (readonly)
Returns The state of the backup.
69 70 71 |
# File 'lib/daytona/sandbox.rb', line 69 def backup_state @backup_state end |
#build_info ⇒ DaytonaApiClient::BuildInfo? (readonly)
Returns 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.
92 93 94 |
# File 'lib/daytona/sandbox.rb', line 92 def build_info @build_info end |
#code_interpreter ⇒ Daytona::CodeInterpreter (readonly)
125 126 127 |
# File 'lib/daytona/sandbox.rb', line 125 def code_interpreter @code_interpreter end |
#computer_use ⇒ Daytona::ComputerUse (readonly)
122 123 124 |
# File 'lib/daytona/sandbox.rb', line 122 def computer_use @computer_use end |
#config ⇒ Daytona::Config (readonly)
107 108 109 |
# File 'lib/daytona/sandbox.rb', line 107 def config @config end |
#cpu ⇒ Float (readonly)
Returns The CPU quota for the sandbox.
48 49 50 |
# File 'lib/daytona/sandbox.rb', line 48 def cpu @cpu end |
#created_at ⇒ String (readonly)
Returns The creation timestamp of the sandbox.
95 96 97 |
# File 'lib/daytona/sandbox.rb', line 95 def created_at @created_at end |
#daemon_version ⇒ String (readonly)
Returns The version of the daemon running in the sandbox.
104 105 106 |
# File 'lib/daytona/sandbox.rb', line 104 def daemon_version @daemon_version end |
#desired_state ⇒ DaytonaApiClient::SandboxDesiredState (readonly)
Returns The desired state of the sandbox.
63 64 65 |
# File 'lib/daytona/sandbox.rb', line 63 def desired_state @desired_state end |
#disk ⇒ Float (readonly)
Returns The disk quota for the sandbox.
57 58 59 |
# File 'lib/daytona/sandbox.rb', line 57 def disk @disk end |
#env ⇒ Hash<String, String>? (readonly)
Returns Environment variables for the sandbox. Not returned by list results; call #refresh on each item to populate.
28 29 30 |
# File 'lib/daytona/sandbox.rb', line 28 def env @env end |
#error_reason ⇒ String (readonly)
Returns The error reason of the sandbox.
66 67 68 |
# File 'lib/daytona/sandbox.rb', line 66 def error_reason @error_reason end |
#fs ⇒ Daytona::FileSystem (readonly)
116 117 118 |
# File 'lib/daytona/sandbox.rb', line 116 def fs @fs end |
#git ⇒ Daytona::Git (readonly)
119 120 121 |
# File 'lib/daytona/sandbox.rb', line 119 def git @git end |
#gpu ⇒ Float (readonly)
Returns The GPU quota for the sandbox.
51 52 53 |
# File 'lib/daytona/sandbox.rb', line 51 def gpu @gpu end |
#id ⇒ String (readonly)
Returns The ID of the sandbox.
15 16 17 |
# File 'lib/daytona/sandbox.rb', line 15 def id @id end |
#labels ⇒ Hash<String, String>
Returns Labels for the sandbox.
31 32 33 |
# File 'lib/daytona/sandbox.rb', line 31 def labels @labels end |
#last_activity_at ⇒ String (readonly)
Returns The last activity timestamp of the sandbox.
101 102 103 |
# File 'lib/daytona/sandbox.rb', line 101 def last_activity_at @last_activity_at end |
#memory ⇒ Float (readonly)
Returns The memory quota for the sandbox.
54 55 56 |
# File 'lib/daytona/sandbox.rb', line 54 def memory @memory end |
#network_allow_list ⇒ String? (readonly)
Returns Comma-separated list of allowed CIDR network addresses for the sandbox. Not returned by list results; call #refresh on each item to populate.
42 43 44 |
# File 'lib/daytona/sandbox.rb', line 42 def network_allow_list @network_allow_list end |
#network_block_all ⇒ Boolean? (readonly)
Returns Whether to block all network access for the sandbox. Not returned by list results; call #refresh on each item to populate.
38 39 40 |
# File 'lib/daytona/sandbox.rb', line 38 def network_block_all @network_block_all end |
#organization_id ⇒ String (readonly)
Returns The organization ID of the sandbox.
18 19 20 |
# File 'lib/daytona/sandbox.rb', line 18 def organization_id @organization_id end |
#process ⇒ Daytona::Process (readonly)
113 114 115 |
# File 'lib/daytona/sandbox.rb', line 113 def process @process end |
#public ⇒ Boolean (readonly)
Returns Whether the sandbox http preview is public.
34 35 36 |
# File 'lib/daytona/sandbox.rb', line 34 def public @public end |
#sandbox_api ⇒ DaytonaApiClient::SandboxApi (readonly)
110 111 112 |
# File 'lib/daytona/sandbox.rb', line 110 def sandbox_api @sandbox_api end |
#snapshot ⇒ String (readonly)
Returns The snapshot used for the sandbox.
21 22 23 |
# File 'lib/daytona/sandbox.rb', line 21 def snapshot @snapshot end |
#state ⇒ DaytonaApiClient::SandboxState (readonly)
Returns The state of the sandbox.
60 61 62 |
# File 'lib/daytona/sandbox.rb', line 60 def state @state end |
#target ⇒ String (readonly)
Returns The target environment for the sandbox.
45 46 47 |
# File 'lib/daytona/sandbox.rb', line 45 def target @target end |
#updated_at ⇒ String (readonly)
Returns The last update timestamp of the sandbox.
98 99 100 |
# File 'lib/daytona/sandbox.rb', line 98 def updated_at @updated_at end |
#user ⇒ String (readonly)
Returns The user associated with the project.
24 25 26 |
# File 'lib/daytona/sandbox.rb', line 24 def user @user end |
#volumes ⇒ Array<DaytonaApiClient::SandboxVolume>? (readonly)
Returns Volumes attached to the sandbox. Not returned by list results; call #refresh on each item to populate.
87 88 89 |
# File 'lib/daytona/sandbox.rb', line 87 def volumes @volumes end |
Instance Method Details
#archive ⇒ void
This method returns an undefined value.
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.
186 187 188 189 |
# File 'lib/daytona/sandbox.rb', line 186 def archive sandbox_api.archive_sandbox(id) refresh end |
#create_lsp_server(language_id:, path_to_project:) ⇒ Daytona::LspServer
Creates a new Language Server Protocol (LSP) server instance. The LSP server provides language-specific features like code completion, diagnostics, and more.
467 468 469 |
# File 'lib/daytona/sandbox.rb', line 467 def create_lsp_server(language_id:, path_to_project:) LspServer.new(language_id:, path_to_project:, toolbox_api: @lsp_api, sandbox_id: id, otel_state:) end |
#create_signed_preview_url(port, expires_in_seconds = nil) ⇒ DaytonaApiClient::SignedPortPreviewUrl
Creates a signed preview URL for the sandbox at the specified port.
321 322 323 |
# File 'lib/daytona/sandbox.rb', line 321 def create_signed_preview_url(port, expires_in_seconds = nil) sandbox_api.get_signed_port_preview_url(id, port, { expires_in_seconds: }) end |
#create_ssh_access(expires_in_minutes) ⇒ DaytonaApiClient::SshAccessDto
Creates an SSH access token for the sandbox.
255 |
# File 'lib/daytona/sandbox.rb', line 255 def create_ssh_access(expires_in_minutes) = sandbox_api.create_ssh_access(id, { expires_in_minutes: }) |
#delete ⇒ void
This method returns an undefined value.
258 259 260 261 262 263 264 265 |
# File 'lib/daytona/sandbox.rb', line 258 def delete sandbox_api.delete_sandbox(id) refresh rescue DaytonaApiClient::ApiError => e raise unless e.code == 404 @state = 'destroyed' end |
#experimental_create_snapshot(name:, timeout: DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
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.
532 533 534 535 536 537 538 539 540 541 |
# File 'lib/daytona/sandbox.rb', line 532 def experimental_create_snapshot(name:, timeout: DEFAULT_TIMEOUT) with_timeout( timeout:, message: "Sandbox #{id} snapshot failed within the #{timeout} seconds timeout period", setup: proc { sandbox_api.create_sandbox_snapshot(id, DaytonaApiClient::CreateSandboxSnapshot.new(name:)) refresh } ) { wait_for_snapshot_complete } end |
#experimental_fork(name: nil, timeout: DEFAULT_TIMEOUT) ⇒ Daytona::Sandbox
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.
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/daytona/sandbox.rb', line 504 def experimental_fork(name: nil, timeout: DEFAULT_TIMEOUT) # rubocop:disable Metrics/MethodLength forked_dto = nil with_timeout( timeout:, message: "Sandbox #{id} fork failed to become ready within the #{timeout} seconds timeout period", setup: proc { forked_dto = sandbox_api.fork_sandbox(id, DaytonaApiClient::ForkSandbox.new(name:)) } ) do forked = Sandbox.new( sandbox_dto: forked_dto, config:, sandbox_api:, code_toolbox:, otel_state: ) forked.send(:wait_for_states, operation: OPERATION_START, target_states: [DaytonaApiClient::SandboxState::STARTED]) return forked end end |
#expire_signed_preview_url(port, token) ⇒ void
This method returns an undefined value.
Expires a signed preview URL for the sandbox at the specified port.
333 334 335 |
# File 'lib/daytona/sandbox.rb', line 333 def expire_signed_preview_url(port, token) sandbox_api.expire_signed_port_preview_url(id, port, token) end |
#get_user_home_dir ⇒ String
Gets the user’s home directory path for the logged in user inside the Sandbox.
274 275 276 277 278 |
# File 'lib/daytona/sandbox.rb', line 274 def get_user_home_dir @info_api.get_user_home_dir.dir rescue StandardError => e raise Sdk::Error, "Failed to get user home directory: #{e.}" end |
#get_work_dir ⇒ String
Gets the working directory path inside the Sandbox.
288 289 290 291 292 |
# File 'lib/daytona/sandbox.rb', line 288 def get_work_dir @info_api.get_work_dir.dir rescue StandardError => e raise Sdk::Error, "Failed to get working directory path: #{e.}" end |
#preview_url(port) ⇒ DaytonaApiClient::PortPreviewUrl
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.
308 |
# File 'lib/daytona/sandbox.rb', line 308 def preview_url(port) = sandbox_api.get_port_preview_url(id, port) |
#recover(timeout = DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Recovers the Sandbox from a recoverable error and waits for it to be ready.
385 386 387 388 389 390 391 392 393 |
# File 'lib/daytona/sandbox.rb', line 385 def recover(timeout = DEFAULT_TIMEOUT) with_timeout( timeout:, message: "Sandbox #{id} failed to recover within the #{timeout} seconds timeout period", setup: proc { process_response(sandbox_api.recover_sandbox(id)) } ) { wait_for_states(operation: OPERATION_START, target_states: [DaytonaApiClient::SandboxState::STARTED]) } rescue StandardError => e raise Sdk::Error, "Failed to recover sandbox: #{e.}" end |
#refresh ⇒ void
This method returns an undefined value.
Refresh the Sandbox data from the API.
340 |
# File 'lib/daytona/sandbox.rb', line 340 def refresh = process_response(sandbox_api.get_sandbox(id)) |
#refresh_activity ⇒ void
This method returns an undefined value.
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.
351 352 353 354 355 356 |
# File 'lib/daytona/sandbox.rb', line 351 def refresh_activity sandbox_api.update_last_activity(id) nil rescue StandardError => e raise Sdk::Error, "Failed to refresh sandbox activity: #{e.}" end |
#resize(resources, timeout = DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
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.
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/daytona/sandbox.rb', line 432 def resize(resources, timeout = DEFAULT_TIMEOUT) raise Sdk::Error, 'Resources must not be nil' if resources.nil? with_timeout( timeout:, message: "Sandbox #{id} failed to resize within the #{timeout} seconds timeout period", setup: proc { resize_attrs = {} resize_attrs[:cpu] = resources.cpu if resources.cpu resize_attrs[:memory] = resources.memory if resources.memory resize_attrs[:disk] = resources.disk if resources.disk resize_request = DaytonaApiClient::ResizeSandbox.new(resize_attrs) process_response(sandbox_api.resize_sandbox(id, resize_request)) } ) { wait_for_resize_complete } end |
#revoke_ssh_access(token) ⇒ void
This method returns an undefined value.
Revokes an SSH access token for the sandbox.
362 |
# File 'lib/daytona/sandbox.rb', line 362 def revoke_ssh_access(token) = sandbox_api.revoke_ssh_access(id, token:) |
#start(timeout = DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Starts the Sandbox and waits for it to be ready.
368 369 370 371 372 373 374 |
# File 'lib/daytona/sandbox.rb', line 368 def start(timeout = DEFAULT_TIMEOUT) with_timeout( timeout:, message: "Sandbox #{id} failed to become ready within the #{timeout} seconds timeout period", setup: proc { process_response(sandbox_api.start_sandbox(id)) } ) { wait_for_states(operation: OPERATION_START, target_states: [DaytonaApiClient::SandboxState::STARTED]) } end |
#stop(timeout = DEFAULT_TIMEOUT, force: false) ⇒ void
This method returns an undefined value.
Stops the Sandbox and waits for it to be stopped.
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/daytona/sandbox.rb', line 400 def stop(timeout = DEFAULT_TIMEOUT, force: false) # rubocop:disable Metrics/MethodLength with_timeout( timeout:, message: "Sandbox #{id} failed to become stopped within the #{timeout} seconds timeout period", setup: proc { sandbox_api.stop_sandbox(id, { force: force }) refresh } ) do wait_for_states( operation: OPERATION_STOP, target_states: [DaytonaApiClient::SandboxState::STOPPED, DaytonaApiClient::SandboxState::DESTROYED] ) end end |
#update_network_settings(network_block_all: nil, network_allow_list: nil) ⇒ void
This method returns an undefined value.
Updates outbound network policy on the runner (block all, restore access, or CIDR allow list).
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/daytona/sandbox.rb', line 221 def update_network_settings(network_block_all: nil, network_allow_list: nil) if network_block_all.nil? && network_allow_list.nil? raise Sdk::Error, 'At least one of network_block_all or network_allow_list must be provided' end body = DaytonaApiClient::UpdateSandboxNetworkSettings.new( network_block_all:, network_allow_list: ) data = sandbox_api.update_network_settings(id, body) @network_block_all = data.network_block_all @network_allow_list = data.network_allow_list end |
#validate_ssh_access(token) ⇒ DaytonaApiClient::SshAccessValidationDto
Validates an SSH access token for the sandbox.
475 |
# File 'lib/daytona/sandbox.rb', line 475 def validate_ssh_access(token) = sandbox_api.validate_ssh_access(token) |
#wait_for_resize_complete(_timeout = DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Waits for the Sandbox resize operation to complete. Polls the Sandbox status until the state is no longer ‘resizing’.
454 455 456 457 |
# File 'lib/daytona/sandbox.rb', line 454 def wait_for_resize_complete(_timeout = DEFAULT_TIMEOUT) wait_for_states(operation: OPERATION_RESIZE, target_states: [DaytonaApiClient::SandboxState::STARTED, DaytonaApiClient::SandboxState::STOPPED]) end |
#wait_for_sandbox_start(_timeout = DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
Waits for the Sandbox to reach the ‘started’ state. Polls the Sandbox status until it reaches the ‘started’ state or encounters an error.
482 483 484 |
# File 'lib/daytona/sandbox.rb', line 482 def wait_for_sandbox_start(_timeout = DEFAULT_TIMEOUT) wait_for_states(operation: OPERATION_START, target_states: [DaytonaApiClient::SandboxState::STARTED]) end |
#wait_for_sandbox_stop(_timeout = DEFAULT_TIMEOUT) ⇒ void
This method returns an undefined value.
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.
492 493 494 495 |
# File 'lib/daytona/sandbox.rb', line 492 def wait_for_sandbox_stop(_timeout = DEFAULT_TIMEOUT) wait_for_states(operation: OPERATION_STOP, target_states: [DaytonaApiClient::SandboxState::STOPPED, DaytonaApiClient::SandboxState::DESTROYED]) end |