What happened
On a Linux server where T3 runs as root, every html_preview call fails right away with:
Headless Chrome could not render the page: the browser exited unexpectedly (exit code 1).
The input makes no difference. Even <p>hello</p> fails. The cause is that Chrome refuses to start as root with its sandbox on, and T3 launches the browser with the sandbox enabled. The error that reaches the agent doesn't include Chrome's own message, so the agent and the user can't tell why it failed.
Environment
- T3 Code 0.1.11,
t3 serve (started by t3 __service-launcher), both processes running as root
- Ubuntu 22.04.5 LTS, kernel 5.15, KVM VM (not a container)
- Browser that T3 downloaded on first use:
~/.t3/tools/chrome-headless-shell/linux64/157.0.8103.78/chrome-headless-shell
- Agent: Claude Code in a T3 thread
Diagnosis
Running the same binary that T3 downloaded:
$ chrome-headless-shell --dump-dom 'data:text/html,<p>hi</p>'
ERROR:content/browser/zygote_host/zygote_host_impl_linux.cc:117] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
$ chrome-headless-shell --no-sandbox --dump-dom 'data:text/html,<p>hi</p>'
<html><head></head><body><p>hi</p></body></html>
The same thing through T3's bundled playwright-core 1.64.1:
chromium.launch({ executablePath }) -> OK
chromium.launch({ executablePath, chromiumSandbox: true }) -> "Chromium sandboxing failed!"
So the binary, its libraries and its fonts are fine (ldd shows nothing missing). The only problem is the sandbox setting combined with uid 0. t3 browser setup doesn't help here, because no AppArmor or userns setting lets Chrome sandbox itself as root. That's a hard check in Chrome.
Running T3 as root is common on single-user VPSes and cloud dev boxes, which are exactly where t3 serve gets deployed.
Expected
Any one of these would fix it:
- When the server runs as uid 0, launch the preview browser with
--no-sandbox (chromiumSandbox: false), possibly with a one-time warning. This is what Puppeteer and Playwright users normally do for root.
- Or provide an explicit opt-in (env var or setting) to turn off the browser sandbox.
- Either way, put Chrome's stderr (or at least the "Running as root without --no-sandbox" line) into the
html_preview error. Then the failure explains itself instead of showing a bare exit code 1, and PreviewBrowserSandboxError / t3 browser setup could catch this case and say that setup can't fix it for root.
Related
#38222 is a different cause (AppArmor userns inside an LXC guest) with the same symptom: the sandbox blocks the preview browser and the message doesn't say why.