Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Add pause_closed_runtimes config to pause instead of stop runtimes (#6885)

Robert Brennanef62ccde3680
diff --git a/openhands/core/config/sandbox_config.py b/openhands/core/config/sandbox_config.py
index 820c33c70a..87ad874117 100644
--- a/openhands/core/config/sandbox_config.py
+++ b/openhands/core/config/sandbox_config.py
@@ -41,6 +41,7 @@ class SandboxConfig(BaseModel):
remote_runtime_api_url: str | None = Field(default='http://localhost:8000')
local_runtime_url: str = Field(default='http://localhost')
keep_runtime_alive: bool = Field(default=False)
+ pause_closed_runtimes: bool = Field(default=True)
rm_all_containers: bool = Field(default=False)
api_key: str | None = Field(default=None)
base_container_image: str = Field(
diff --git a/openhands/runtime/impl/remote/remote_runtime.py b/openhands/runtime/impl/remote/remote_runtime.py
index 7e1256d283..03882a06bf 100644
--- a/openhands/runtime/impl/remote/remote_runtime.py
+++ b/openhands/runtime/impl/remote/remote_runtime.py
@@ -377,7 +377,22 @@ class RemoteRuntime(ActionExecutionClient):
raise AgentRuntimeNotReadyError()
def close(self):
- if self.config.sandbox.keep_runtime_alive or self.attach_to_existing:
+ if self.attach_to_existing:
+ super().close()
+ return
+ if self.config.sandbox.keep_runtime_alive:
+ if self.config.sandbox.pause_closed_runtimes:
+ try:
+ if not self._runtime_closed:
+ with self._send_runtime_api_request(
+ 'POST',
+ f'{self.config.sandbox.remote_runtime_api_url}/pause',
+ json={'runtime_id': self.runtime_id},
+ ):
+ self.log('debug', 'Runtime paused.')
+ except Exception as e:
+ self.log('error', f'Unable to pause runtime: {str(e)}')
+ raise e
super().close()
return
try: