Skip to content

fix(sandbox): preserve NEKO_* env across sudo re-exec in start-browser.sh - #507

Merged
xfgong merged 4 commits into
mainfrom
fix/2026-08-19-preserve-neko-env-across-sudo
Aug 20, 2026
Merged

fix(sandbox): preserve NEKO_* env across sudo re-exec in start-browser.sh#507
xfgong merged 4 commits into
mainfrom
fix/2026-08-19-preserve-neko-env-across-sudo

Conversation

@xfgong

@xfgong xfgong commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

What

When start-browser.sh runs as the agent (uid 1000), it re-execs through
sudo so the chown/lock/pidfile steps can touch /var/run. The sandbox
image bakes NEKO_WEBRTC_ICESERVERS_* (TURN at turn:192.168.1.208:3478)
into Config.Env so Neko can relay WebRTC media, but /etc/sudoers sets
Defaults env_reset and does not include NEKO_* in env_keep, so sudo
strips the ICE config. Neko falls back to Google STUN only, the WebRTC
media path has no relay, and the live view white-screens.

Why

The agent path (browser skill telling the agent to run
/usr/local/bin/start-browser.sh as the sandbox user) loses the TURN
server baked into the image. The backend's start_browser flow uses
as_root=True and was never affected; the bug only shows up when the
agent starts the browser itself. Surfaced once PR #506
(feat/2026-08-19-auto-open-browser-preview) started opening the Browser
panel automatically and the agent-driven path became user-visible.

How

Preserve the NEKO_* vars across the exec sudo boundary via a temp file
the root branch sources back. NEKO_ENV_FILE is set on the sudo command
line (not the inherited env) so it survives env_reset and points the
re-exec'd root shell at the file.

start_browser (backend, as_root=True) takes the existing fast path and
never hits the preservation code, so behaviour for the live-view flow is
unchanged.

Test plan

After rebuilding the cubeplex-sandbox image with a new tag and rolling
it onto a node:

  1. Restart a sandbox; verify docker inspect on the new tag still bakes
    NEKO_WEBRTC_ICESERVERS_BACKEND/FRONTEND with turn:192.168.1.208:3478.
  2. As the agent (sudo -u cubeplex), run /usr/local/bin/start-browser.sh;
    confirm /var/log/neko/neko.log shows
    iceservers-backend=[{"urls":["turn:192.168.1.208:3478"],...}] (not
    the Google STUN default).
  3. Open the Browser panel; confirm the Neko stream renders non-white.
  4. Repeat with a sandbox on the other TURN-less node (217) to confirm the
    ICE relay still works through coturn on 208.

Requires rebuilding cubeplex-sandbox (new tag) and deploying it for the
fix to take effect; sh -n and a code review suffice at the repo level.

…r.sh

The sandbox image bakes NEKO_WEBRTC_ICESERVERS_* (TURN at
192.168.1.208:3478) into Config.Env so Neko can relay WebRTC media.
When start-browser.sh runs as the agent (uid 1000), it re-execs
through sudo; /etc/sudoers sets Defaults env_reset and does not
include NEKO_* in env_keep, so sudo strips the TURN config. Neko
falls back to Google STUN only, ICE has no relay, and the live view
white-screens.

Preserve the NEKO_* vars across the re-exec via a temp file the
root branch sources back. NEKO_ENV_FILE is set on the sudo command
line (not the inherited env), so it survives env_reset.

Surfaced by PR #506 (auto-open browser preview) once the Browser
panel started opening on its own and the agent-started browser
path became user-visible. The backend's as_root=True path is
unaffected.

Requires rebuilding the cubeplex-sandbox image with a new tag and
deploying it for the fix to land in running sandboxes.
@github-actions github-actions Bot added bug Something isn't working deploy Deployment / infra labels Aug 20, 2026
@github-actions github-actions Bot added the backend Backend code label Aug 20, 2026
@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot added the ci CI and tooling label Aug 20, 2026
@xfgong
xfgong merged commit 3230c7c into main Aug 20, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend code bug Something isn't working ci CI and tooling deploy Deployment / infra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant