fix(stagehand): Inject --no-sandbox into Stagehand's Chromium launch when sandbox is disabled#1906
Open
vdusek wants to merge 1 commit into
Open
fix(stagehand): Inject --no-sandbox into Stagehand's Chromium launch when sandbox is disabled#1906vdusek wants to merge 1 commit into
--no-sandbox into Stagehand's Chromium launch when sandbox is disabled#1906vdusek wants to merge 1 commit into
Conversation
…box is disabled Stagehand's `BrowserLaunchOptions` accepts `chromium_sandbox` but does not propagate it to the underlying Chromium launch, so containers running as root (e.g. Apify actors with `disable_browser_sandbox=True`) hit `ECONNREFUSED` on the CDP port. Inject `--no-sandbox` explicitly in `StagehandBrowserPlugin` so the `StagehandCrawler` actually starts a session on the Apify platform.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1906 +/- ##
==========================================
- Coverage 92.95% 92.88% -0.07%
==========================================
Files 167 167
Lines 11709 11714 +5
==========================================
- Hits 10884 10881 -3
- Misses 825 833 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
vdusek
added a commit
that referenced
this pull request
May 20, 2026
…1905) ## Summary Today's [scheduled run](https://github.com/apify/crawlee-python/actions/runs/26136278735) had the `playwright_chrome+impit+pip` variant of `test_static_crawler_actor_at_apify` hang on `apify push` for the full 30-minute `pytest-timeout` window ([job log](https://github.com/apify/crawlee-python/actions/runs/26136278735/job/76872087287)). Yesterday it was a different combination — these are transient `apify-cli` / network flakes, not a code bug. Two test-infrastructure fixes: - **`@pytest.mark.flaky(reruns=3)`** on `test_static_crawler_actor_at_apify`, plus **`timeout=120`** on every `apify-cli` `subprocess.run` (`login`, `init`, `push`). A hung CLI now fails fast instead of burning the whole pytest-timeout window; the reruns absorb the transient. - **Fix `rerun=` → `reruns=` kwarg typo** in five existing `@pytest.mark.flaky` decorators. `pytest-rerunfailures` reads `reruns` (plural) — the typo silently meant 1 retry instead of 3 for the affected unit tests. The Stagehand `ECONNREFUSED` failures from the same scheduled run are a separate bug, fixed in #1906.
--no-sandbox into Stagehand's Chromium launch when sandbox is disabled--no-sandbox into Stagehand's Chromium launch when sandbox is disabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The scheduled e2e tests for the Stagehand template have failed for several days. After PR #1900 fixed the
OPENAI_API_KEYpropagation, the next layer of failure surfaced — every Stagehand variant in today's run failed identically on the Apify platform with:Root cause
Reproduced locally inside the
apify/actor-python-playwright:3.13image: Stagehand'sBrowserLaunchOptionsaccepts achromium_sandboxfield, but the field is not propagated to the underlying Chromium launch. When the actor runs as root (which it does on Apify), Chromium silently refuses to start because the setuid sandbox can't initialise — and Stagehand's local SEA server then hitsECONNREFUSEDwhen it tries to connect to the missing Chromium CDP port. The regularPlaywrightCrawleris unaffected because Playwright's Python binding does translatechromium_sandbox=Falseinto--no-sandbox.Fix
In
StagehandBrowserPlugin, when the sandbox is disabled (config.disable_browser_sandbox=True, which Apify auto-sets), append'--no-sandbox'tobrowser_launch_options['args']as an explicit workaround. Verified end-to-end in the same actor base image — the crawler now completes requests successfully.The
apify pushhang from the same scheduled run is a separate flake and is addressed in #1905.