From fb5f9e52ceab03847fba56e60a34bdbb70b43369 Mon Sep 17 00:00:00 2001 From: James Russo Date: Tue, 17 Nov 2026 04:12:56 +0000 Subject: [PATCH] fix(engine): GPU probe, HDR capture and host-ceiling probe keep a required sandbox (#8018) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(engine): GPU probe, HDR capture and host-ceiling probe keep a required sandbox These three launches always passed --no-sandbox, even where HYPERFRAMES_CHROME_SANDBOX=1 says Chrome must keep its sandbox. They now drop it in that case and behave as before otherwise. — Rames Co-Authored-By: Claude Opus 5.5 * fix(engine): HDR capture passes --no-zygote only alongside --no-sandbox Chrome exits at launch ("Zygote cannot be disabled if sandbox is enabled") when --no-zygote is passed with its sandbox on, so HDR capture under HYPERFRAMES_CHROME_SANDBOX=1 needs to drop it together with --no-sandbox. — Rames Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../engine/src/services/browserManager.ts | 9 ++++-- .../engine/src/services/chromeHostCeiling.ts | 3 +- .../engine/src/services/chromeSandbox.test.ts | 28 +++++++++++++++++++ packages/engine/src/services/chromeSandbox.ts | 4 +++ packages/engine/src/services/hdrCapture.ts | 8 ++++-- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/packages/engine/src/services/browserManager.ts b/packages/engine/src/services/browserManager.ts index a397ae030f..d66e67e873 100644 --- a/packages/engine/src/services/browserManager.ts +++ b/packages/engine/src/services/browserManager.ts @@ -41,7 +41,11 @@ import { } from "./publicNetwork/captureProxy.js"; import { removeTreeBestEffortAsync } from "@hyperframes/core/remove-tree"; import { getSystemTotalMb, LOW_MEMORY_TOTAL_MB_THRESHOLD } from "./systemMemory.js"; -import { chromeSandboxArgs, launchWithChromeSandboxFallback } from "./chromeSandbox.js"; +import { + chromeSandboxArgs, + launchWithChromeSandboxFallback, + noSandboxUnlessRequired, +} from "./chromeSandbox.js"; import { describeWslGpuAccess, detectWsl, type WslHostFacts } from "./wslHost.js"; import { BrowserLeasePool, @@ -572,8 +576,7 @@ async function getPuppeteerOrNull(): Promise { function getHardwareGpuProbeArgs(platform: NodeJS.Platform): string[] { return [ - "--no-sandbox", - "--disable-setuid-sandbox", + ...noSandboxUnlessRequired(), "--disable-dev-shm-usage", "--enable-webgl", "--ignore-gpu-blocklist", diff --git a/packages/engine/src/services/chromeHostCeiling.ts b/packages/engine/src/services/chromeHostCeiling.ts index eb0d939f92..2bf1c77806 100644 --- a/packages/engine/src/services/chromeHostCeiling.ts +++ b/packages/engine/src/services/chromeHostCeiling.ts @@ -5,6 +5,7 @@ import { debuglog } from "node:util"; import { release } from "node:os"; import { dirname, join } from "node:path"; import { buildChromeLaunchEnv } from "@hyperframes/core/chrome-env"; +import { noSandboxUnlessRequired } from "./chromeSandbox.js"; /** Chrome 151 dropped macOS 12 and older (Darwin < 22); 150 is the last major that launches there. */ const MACOS_12_LAST_CHROME_MAJOR = 150; @@ -159,7 +160,7 @@ const debug = debuglog("hyperframes:browser"); export function shellStarts(binary: string, timeoutMs = 10_000): boolean { let answer = starts.get(binary); if (answer === undefined) { - const probe = ["--no-sandbox", "--dump-dom", "about:blank"]; + const probe = [...noSandboxUnlessRequired(), "--dump-dom", "about:blank"]; answer = spawnSync(binary, probe, { env: buildChromeLaunchEnv(), diff --git a/packages/engine/src/services/chromeSandbox.test.ts b/packages/engine/src/services/chromeSandbox.test.ts index b67234a0ef..b2f1b9cd09 100644 --- a/packages/engine/src/services/chromeSandbox.test.ts +++ b/packages/engine/src/services/chromeSandbox.test.ts @@ -4,9 +4,11 @@ import { chromeSandboxEnabled, launchWithChromeSandboxFallback, NO_SANDBOX_ARGS, + noSandboxUnlessRequired, type ChromeSandboxHost, } from "./chromeSandbox.js"; import { buildChromeArgs } from "./browserManager.js"; +import { buildHdrChromeArgs } from "./hdrCapture.js"; function host(overrides: Partial = {}): ChromeSandboxHost { return { @@ -70,6 +72,32 @@ describe("chromeSandboxEnabled", () => { }); }); +describe("launches that always ran without the sandbox", () => { + it("keep it when HYPERFRAMES_CHROME_SANDBOX=1 requires it, and run as before otherwise", () => { + expect(noSandboxUnlessRequired({ HYPERFRAMES_CHROME_SANDBOX: "1" })).toEqual([]); + expect(noSandboxUnlessRequired({})).toEqual(["--no-sandbox", "--disable-setuid-sandbox"]); + }); + + it("HDR capture keeps the sandbox when it is required, and drops --no-zygote with it", () => { + vi.stubEnv("HYPERFRAMES_CHROME_SANDBOX", "1"); + try { + const args = buildHdrChromeArgs(640, 360); + expect(args).not.toContain("--no-sandbox"); + expect(args).not.toContain("--no-zygote"); + } finally { + vi.unstubAllEnvs(); + } + vi.stubEnv("HYPERFRAMES_CHROME_SANDBOX", ""); + try { + expect(buildHdrChromeArgs(640, 360)).toEqual( + expect.arrayContaining(["--no-sandbox", "--disable-setuid-sandbox", "--no-zygote"]), + ); + } finally { + vi.unstubAllEnvs(); + } + }); +}); + describe("buildChromeArgs sandbox flags", () => { const base = { width: 320, height: 240, platform: "linux" as const }; diff --git a/packages/engine/src/services/chromeSandbox.ts b/packages/engine/src/services/chromeSandbox.ts index 52868227ba..5056517bba 100644 --- a/packages/engine/src/services/chromeSandbox.ts +++ b/packages/engine/src/services/chromeSandbox.ts @@ -58,6 +58,10 @@ export function chromeSandboxEnabled(host: ChromeSandboxHost = currentHost()): b return host.platform !== "linux" || !linuxCannotSandbox(host); } +export function noSandboxUnlessRequired(env: NodeJS.ProcessEnv = process.env): string[] { + return env.HYPERFRAMES_CHROME_SANDBOX === "1" ? [] : ["--no-sandbox", "--disable-setuid-sandbox"]; +} + export function chromeSandboxArgs(sandbox = chromeSandboxEnabled()): string[] { return sandbox ? [] : NO_SANDBOX_ARGS; } diff --git a/packages/engine/src/services/hdrCapture.ts b/packages/engine/src/services/hdrCapture.ts index 9050026f95..39fd628f33 100644 --- a/packages/engine/src/services/hdrCapture.ts +++ b/packages/engine/src/services/hdrCapture.ts @@ -23,6 +23,7 @@ import { withHyperframesBrowserMarker } from "@hyperframes/core/browser-marker"; import { buildChromeLaunchEnv } from "@hyperframes/core/chrome-env"; import type { Page, Browser, PuppeteerNode } from "puppeteer-core"; import { resolveFullChromePath, ownedLaunchOptions } from "./browserManager.js"; +import { noSandboxUnlessRequired } from "./chromeSandbox.js"; // ── PQ (SMPTE 2084) OETF ───────────────────────────────────────────────────── @@ -262,10 +263,11 @@ export async function launchHdrBrowser( } export function buildHdrChromeArgs(width: number, height: number): string[] { + const noSandbox = noSandboxUnlessRequired(); + const noZygoteOnlyWithoutSandbox = noSandbox.length > 0 ? ["--no-zygote"] : []; return [ "--enable-unsafe-webgpu", - "--no-sandbox", - "--disable-setuid-sandbox", + ...noSandbox, "--window-position=-10000,-10000", `--window-size=${width},${height}`, "--disable-background-timer-throttling", @@ -276,7 +278,7 @@ export function buildHdrChromeArgs(width: number, height: number): string[] { "--disable-component-update", "--disable-default-apps", "--disable-sync", - "--no-zygote", + ...noZygoteOnlyWithoutSandbox, "--force-gpu-mem-available-mb=4096", "--autoplay-policy=no-user-gesture-required", ];