背景
如果是root用户安装后默认使用会提示
Chromium sandboxing failed!
================================
To avoid the sandboxing issue, do either of the following:
- (preferred): Configure your environment to support sandboxing
- (alternative): Launch Chromium without sandbox using 'chromiumSandbox: false' option解决方法:
来自grok heavy搜索得到()
在 root 下运行 playwright-cli 的正确方法(解决 Chromium sandbox 问题)
你遇到的核心问题是:Chromium 不允许以 root 用户身份运行,除非显式禁用 sandbox(错误来源:Running as root without --no-sandbox is not supported)。
你之前用的 PLAYWRIGHT_CHROMIUM_SANDBOX=false 是错误的变量名,这个 CLI 不认它。
@playwright/cli(微软官方为 AI Agent 设计的 CLI)提供了专用的环境变量来控制 sandbox。
方法1(全局)
把下面这行加到 ~/.bashrc 或 ~/.zshrc 里,以后就不用每次都敲了:
export PLAYWRIGHT_MCP_NO_SANDBOX=true然后 source ~/.bashrc 生效。
方法2(项目级别)
playwright-cli 支持配置文件,可以直接设置 chromiumSandbox: false(官方推荐写法):
- 在当前目录(或项目根目录)创建配置文件:
mkdir -p .playwright
cat > .playwright/cli.config.json << EOF
{
"browser": {
"launchOptions": {
"chromiumSandbox": false
}
}
}
EOF- 之后直接运行(不需要环境变量):
playwright-cli open https://demo.playwright.dev/todomvc/ --headed配置文件路径也可以自定义:PLAYWRIGHT_MCP_CONFIG=/path/to/config.json