Skip to content

Commit 7551887

Browse files
Merge branch 'main' into openhands/add-gpt-5-3-codex-v2
2 parents 6ffabfb + 2e8a2bd commit 7551887

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

openhands-tools/openhands/tools/browser_use/impl.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,24 @@ def init_logic():
247247
if inject_scripts:
248248
self._server.set_inject_scripts(inject_scripts)
249249

250+
# Chromium refuses to run as root with sandboxing enabled.
251+
# Disable the sandbox when running as root so CHROME_DOCKER_ARGS
252+
# (--no-sandbox, --disable-setuid-sandbox, etc.) are applied.
253+
# SECURITY: Running Chrome as root without a sandbox is risky
254+
# - a compromised browser has full root access. Use only in
255+
# controlled environments.
256+
running_as_root = os.getuid() == 0
257+
if running_as_root:
258+
logger.warning(
259+
"Running as root - disabling Chromium sandbox "
260+
"(required for root). This reduces security isolation."
261+
)
262+
250263
self._config = {
251264
"headless": headless,
252265
"allowed_domains": allowed_domains or [],
253266
"executable_path": executable_path,
267+
"chromium_sandbox": not running_as_root,
254268
**config,
255269
}
256270

tests/tools/browser_use/test_browser_initialization.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_initialization_config_passed_to_server(self):
8989
"openhands.tools.browser_use.impl.CustomBrowserUseServer",
9090
return_value=mock_server,
9191
),
92+
patch("os.getuid", return_value=1000), # Non-root user
9293
):
9394
executor = BrowserToolExecutor(
9495
headless=False,
@@ -101,6 +102,7 @@ def test_initialization_config_passed_to_server(self):
101102
"headless": False,
102103
"allowed_domains": ["example.com"],
103104
"executable_path": "/usr/bin/chromium",
105+
"chromium_sandbox": True, # Enabled for non-root
104106
"custom_param": "test",
105107
}
106108

0 commit comments

Comments
 (0)