Skip to content

Commit 32b18f5

Browse files
dcramercodex
andcommitted
Harden sandbox browser startup in containers
Co-Authored-By: GPT-5 Codex <codex@openai.com>
1 parent 66b4c4e commit 32b18f5

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/ash/browser/providers/sandbox.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,12 @@ async def _launch_runtime(self) -> _RemoteSandboxRuntime:
779779
)
780780
break
781781
port = self._pick_port()
782+
flags = " ".join(self._CHROMIUM_RUNTIME_FLAGS)
782783
launch_cmd = (
783784
f"mkdir -p {shlex.quote(base_dir)} && "
785+
f"(rm -rf {shlex.quote(base_dir)}/profile/WidevineCdm >/dev/null 2>&1 || true) && "
784786
"nohup chromium "
785-
"--headless=new "
786-
"--no-sandbox "
787-
"--disable-dev-shm-usage "
788-
"--disable-gpu "
787+
f"{flags} "
789788
"--remote-debugging-address=127.0.0.1 "
790789
f"--remote-debugging-port={port} "
791790
f"--user-data-dir={shlex.quote(base_dir)}/profile "
@@ -1040,3 +1039,22 @@ async def _execute_sandbox_command(
10401039
_MAX_LAUNCH_TOTAL_SECONDS = 45.0
10411040
_HTTP_READY_TIMEOUT_SECONDS = 12.0
10421041
_WS_READY_TIMEOUT_SECONDS = 8.0
1042+
_CHROMIUM_RUNTIME_FLAGS = (
1043+
"--headless=new",
1044+
"--no-sandbox",
1045+
"--disable-setuid-sandbox",
1046+
"--disable-dev-shm-usage",
1047+
"--disable-gpu",
1048+
"--no-first-run",
1049+
"--no-default-browser-check",
1050+
"--disable-sync",
1051+
"--disable-background-networking",
1052+
"--disable-component-update",
1053+
"--disable-features=Translate,MediaRouter",
1054+
"--disable-session-crashed-bubble",
1055+
"--hide-crash-restore-bubble",
1056+
"--password-store=basic",
1057+
"--disable-breakpad",
1058+
"--disable-crash-reporter",
1059+
"--metrics-recording-only",
1060+
)

tests/test_browser_sandbox_provider.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ async def test_sandbox_provider_uses_executor_for_full_flow() -> None:
117117

118118
await provider.close_session(provider_session_id="s1")
119119
assert any("nohup chromium" in cmd for cmd in executor.commands)
120+
launch_cmd = next(cmd for cmd in executor.commands if "nohup chromium" in cmd)
121+
assert "--disable-component-update" in launch_cmd
122+
assert "--disable-background-networking" in launch_cmd
123+
assert "--disable-features=Translate,MediaRouter" in launch_cmd
124+
assert "rm -rf " in launch_cmd and "/profile/WidevineCdm" in launch_cmd
120125
assert any("/json/version" in cmd for cmd in executor.commands)
121126
assert any("kill 12345" in cmd for cmd in executor.commands)
122127

0 commit comments

Comments
 (0)