Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Allowing local runtimes to have domains (#8798)

tofarrde196d6da135
diff --git a/openhands/runtime/impl/local/local_runtime.py b/openhands/runtime/impl/local/local_runtime.py
index a03ef6da07..0d50270bae 100644
--- a/openhands/runtime/impl/local/local_runtime.py
+++ b/openhands/runtime/impl/local/local_runtime.py
@@ -388,17 +388,37 @@ class LocalRuntime(ActionExecutionClient):
super().close()
+ @property
+ def runtime_url(self) -> str:
+
+ runtime_url = os.getenv('RUNTIME_URL')
+ if runtime_url:
+ return runtime_url
+
+
+
+ #TODO: This could be removed if we had a straightforward variable containing the RUNTIME_URL in the K8 env.
+ runtime_url_pattern = os.getenv('RUNTIME_URL_PATTERN')
+ hostname = os.getenv('HOSTNAME')
+ if runtime_url_pattern and hostname:
+ runtime_id = hostname.split('-')[1]
+ runtime_url = runtime_url_pattern.format(runtime_id=runtime_id)
+ return runtime_url
+
+ # Fallback to localhost
+ return self.config.sandbox.local_runtime_url
+
@property
def vscode_url(self) -> str | None:
token = super().get_vscode_token()
if not token:
return None
- vscode_url = f'http://localhost:{self._vscode_port}/?tkn={token}&folder={self.config.workspace_mount_path_in_sandbox}'
+ vscode_url = f'{self.runtime_url}:{self._vscode_port}/?tkn={token}&folder={self.config.workspace_mount_path_in_sandbox}'
return vscode_url
@property
def web_hosts(self) -> dict[str, int]:
hosts: dict[str, int] = {}
for port in self._app_ports:
- hosts[f'http://localhost:{port}'] = port
+ hosts[f'{self.runtime_url}:{port}'] = port
return hosts