From fec1a3f59b0cbb8d9c9a6eaa9cc5b43aa2048c7c Mon Sep 17 00:00:00 2001 From: Vandit Date: Wed, 6 May 2026 04:43:11 +0530 Subject: [PATCH] fix: bind serve port to localhost (#706) --- openhands_cli/gui_launcher.py | 2 +- tests/test_gui_launcher.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/openhands_cli/gui_launcher.py b/openhands_cli/gui_launcher.py index b2b61e8ff..b8f072d95 100644 --- a/openhands_cli/gui_launcher.py +++ b/openhands_cli/gui_launcher.py @@ -187,7 +187,7 @@ def launch_gui_server(mount_cwd: bool = False, gpu: bool = False) -> None: docker_cmd.extend( [ "-p", - "3000:3000", + "127.0.0.1:3000:3000", "--add-host", "host.docker.internal:host-gateway", "--name", diff --git a/tests/test_gui_launcher.py b/tests/test_gui_launcher.py index 2b312ec6f..116cbf955 100644 --- a/tests/test_gui_launcher.py +++ b/tests/test_gui_launcher.py @@ -26,10 +26,18 @@ class TestFormatDockerCommand: "Running Docker command: docker run hello-world", ), ( - ["docker", "run", "-it", "--rm", "-p", "3000:3000", "openhands:latest"], + [ + "docker", + "run", + "-it", + "--rm", + "-p", + "127.0.0.1:3000:3000", + "openhands:latest", + ], ( - "Running Docker command: docker run -it --rm -p 3000:3000 " - "openhands:latest" + "Running Docker command: docker run -it --rm -p " + "127.0.0.1:3000:3000 openhands:latest" ), ), ([], "Running Docker command: "), @@ -183,6 +191,7 @@ def test_launch_gui_server_scenarios( assert run_cmd[0:2] == ["docker", "run"] # Verify --pull=always is in the command assert "--pull=always" in run_cmd + assert run_cmd[run_cmd.index("-p") + 1] == "127.0.0.1:3000:3000" if mount_cwd: assert "SANDBOX_VOLUMES=/current/dir:/workspace:rw" in " ".join(run_cmd)