diff --git a/third_party/runtime/impl/daytona/daytona_runtime.py b/third_party/runtime/impl/daytona/daytona_runtime.py index 8ce67143f3..020b0458cc 100644 --- a/third_party/runtime/impl/daytona/daytona_runtime.py +++ b/third_party/runtime/impl/daytona/daytona_runtime.py @@ -117,12 +117,17 @@ class DaytonaRuntime(ActionExecutionClient): return env_vars def _create_sandbox(self) -> Sandbox: + # Check if auto-stop should be disabled - otherwise have it trigger after 60 minutes + disable_auto_stop = os.getenv('DAYTONA_DISABLE_AUTO_STOP', 'false').lower() == 'true' + auto_stop_interval = 0 if disable_auto_stop else 60 + sandbox_params = CreateSandboxFromSnapshotParams( language='python', snapshot=self.config.sandbox.runtime_container_image, public=True, env_vars=self._get_creation_env_vars(), labels={OPENHANDS_SID_LABEL: self.sid}, + auto_stop_interval=auto_stop_interval, ) return self.daytona.create(sandbox_params) @@ -245,7 +250,14 @@ class DaytonaRuntime(ActionExecutionClient): return if self.sandbox: - self.sandbox.delete() + delete_on_close = os.getenv('DAYTONA_DELETE_ON_CLOSE', 'false').lower() == 'true' + + if delete_on_close: + self.sandbox.delete() + else: + # Only stop if sandbox is currently started + if self._get_sandbox().state == 'started': + self.sandbox.stop() @property def vscode_url(self) -> str | None: