Skip to content

feat(bwopenchamber): add bwopenchamber and bwopencode2 --serve-open - #43

Merged
Matt Snyder (maatthias) merged 26 commits into
NSLS2:mainfrom
stuwilkins:add_bwopenchamber
Nov 19, 2026
Merged

Matt Snyder (maatthias) merged 26 commits into
NSLS2:mainfrom
stuwilkins:add_bwopenchamber

Conversation

@stuwilkins

@stuwilkins Stuart B. Wilkins (stuwilkins) commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds bwopenchamber, which runs OpenChamber (a web UI for OpenCode) in the same bubblewrap sandbox as its OpenCode, so the terminal, git, worktrees and every tool call stay sandboxed and only the browser is outside, behind an ssh tunnel.

Also changes bwopencode2 --serve (from #37) so it is easier to sign in to: one block with the ssh -L command, a one-time sign-in link and a google-chrome --app=... command, a new link on Enter, and --serve-open, which opens the signed-in web UI in a browser on the same host. These are six commits at the end of the branch and are independent of bwopenchamber.

This depends on #37 and should not merge before it. It uses that PR's private network namespace and publish address, so until #37 merges this PR also shows #37's commits. Review only the 17 commits after #37's tip e8738f0 (git log e8738f0.. lists them): eleven for bwopenchamber and its sign-in, database-lock and data-directory fixes, and six for bwopencode2 --serve-open and the sign-in block (feat(bwopencode2): add --serve-open and a sign-in block for --serve, fix(bwopencode2): do not hand the --serve-open link to xdg-open without a browser, docs(bwopencode2): record that only a browser signs in with the --serve link, fix(bwopencode2): keep the launcher's descriptors from the --serve-open browser, feat(bwopencode2): make --serve-open work without --serve, and the cleaned-up --serve-open terminal output). Once #37 merges, the diff here shrinks to those.

Description

Why a launcher of its own, and not bwopencode2 --serve behind an OpenChamber on another machine. OpenChamber is not only a screen. Its server runs the browser terminal, git and worktree commands, project start commands and scheduled tasks, and it gives the agent tools that call back into it. Run outside the sandbox in front of a sandboxed OpenCode, all of that would run unsandboxed. So the whole server runs inside one sandbox.

What it does

  • Sources bin/bwopencode2 (it now runs main only when executed, and finds its library from its own file) for the OpenCode 2 mounts, environment, database guard and the --serve port pool, so a fix made there applies to both. Moving that shared code into lib/ is deliberately left for after Feat/bwrap private netns #37 lands, because bwopencode2 is being rewritten there.
  • Takes its port from the same pool and claim directory as --serve (24700-24709), published on the user's 127.H1.H2.1; one ssh_config block (--ssh-config) covers both. The server listens on 0.0.0.0 inside the private network, as --serve does.
  • Random UI password for each session (or BWOPENCODE2_SERVE_PASSWORD), passed only in the sandbox environment.
  • A random sign-in signing key for each session (OPENCODE_JWT_SECRET). Without it OpenChamber 2.7.0 writes a key to its data directory and reuses it, so a browser stayed signed in across restarts and password changes, and the agent could read the file.
  • The policy is a read-only /etc/openchamber/policy.json that the launcher generates and mounts from a descriptor inside the sandbox (the host's file is not visible there): enterprise mode (no tunnels, public relay, classification service, adding providers in the app), the installed OpenCode 2 pinned, allowNetworkAccess: true for the private network, no extensions. It is a file, not environment variables, because without one a saved opencodeBinary in OpenChamber's settings.json (which the agent can write) overrides OPENCODE_BINARY; only a policy file outranks it. Copilot's review found this: a fake OpenCode named in settings.json ran with the environment alone, and did not run with the file.
  • No host OPENCODE_* or OPENCHAMBER_* variable reaches the server, and no OpenChamber argument is passed through.
  • Finds a Node.js that is new enough, not just the first on PATH: BWOPENCHAMBER_NODE if set, else the node on PATH if it is 24.14 or newer, else the newest node-24 / nodejs24 in /usr/bin and /usr/local/bin that is (RHEL 10 keeps nodejs 22 as the default and nodejs24 installs node-24 beside it). With no node on PATH it takes the newest versioned one (a bug found in Copilot's review: it first took the first one found). When none qualifies the error lists what it found with versions and what to do. Checked on the real host with no stubs: it lists /usr/bin/node and /usr/bin/node-22 (both 22.23.2), and BWOPENCHAMBER_NODE set to a pixi Node 24.22.1 launches. On babelfish (RHEL 10.2) the dry run, with no override, uses /usr/bin/node-24 (24.21.0, from nodejs24, installed next to the default 22.23.2), and a real launch started the server, the pinned OpenCode and the browser terminal's node-pty. The matching install is NSLS2/ansible#5064.
  • The data directory is bound whole and read-write, so it is checked in bind mode: a symlink to a directory that contains a blocked path (~/.config/gh) is refused, and the resolved path is what is mounted (found in Copilot's review; _check_dir_safe had accepted it).
  • OpenChamber's data directory is ~/.local/share/bwopenchamber, apart from any OpenChamber run outside a sandbox. Its run/ directory is an empty tmpfs, because OpenChamber writes the UI password there in plain text (checked with 2.7.0).

bwopencode2 --serve: sign-in block and --serve-open

  • When the server answers, the wrapper inside the sandbox prints one block: the ssh -L command and the ssh_config alias, the one-time sign-in link for http://127.0.0.1:PORT, the same link as a google-chrome --app=... command (an app window without tabs), the link for this host and the password. A link works once and expires after 5 minutes and an ssh tunnel can take longer to set up, so Enter in the terminal asks the server for a new one. The wrapper only reads Enter when it has a terminal and stops at end of input. A backslash or double quote in a fixed password is now escaped for curl's config file.
  • --serve-open is --serve plus a browser on the same host, so it works by itself (--serve --serve-open means the same) and --serve alone opens nothing. It starts a helper on the host, outside the sandbox, just before the sandbox replaces the launcher. The helper waits for the server, asks it for a one-time link of its own and starts the browser detached: google-chrome --app=LINK (or google-chrome-stable, chromium, chromium-browser), else firefox, else xdg-open but only when xdg-mime names a default web browser for http (the scheme of the link). BWOPENCODE2_SERVE_BROWSER names another one. With no desktop session (DISPLAY and WAYLAND_DISPLAY unset) or no browser it opens nothing and says so; --dry-run opens nothing.
  • The --serve-open terminal output is short, since it is for the host you are on: one line, OpenCode web UI on ADDR:PORT, opened in google-chrome., or, if no browser opened (none found, no desktop session, the browser exited with an error within 8 seconds, the server never answered), a fresh one-time link to open by hand, how to get another (Enter), and the password for "Use password" (only there). --serve output is unchanged.
  • The helper closes the launcher's descriptors before starting the browser. Found in Copilot's review of this PR and reproduced: the browser inherited the database session lock and held it as long as its window was open, so the next launch on the same data directory would have been refused. A test fails without the fix.
  • Why xdg-open is guarded: on a workstation with no browser, xdg-open handed the link to the GNOME text editor, which showed "Could Not Open File, HTTP Client Error: Unauthorized".
  • Only a browser signs in. The server redirects to / and sets the cookie only for Accept: text/html; curl or the text editor get a JSON token and use up the code (checked with OpenCode 2.2.7).

Known limit (documented in docs/bw-wrappers.md). OpenChamber puts its credentials into the environment of the OpenCode it starts, so the agent's shell has OPENCHAMBER_UI_PASSWORD, OPENCODE_SERVER_PASSWORD, OPENCODE_PASSWORD and the new OPENCODE_JWT_SECRET (checked in a running session). With them an agent could sign in to the UI (or sign a cookie itself) or call its own OpenCode server and so change settings or answer its own permission prompts. Nothing leaves the sandbox. The launcher cannot remove them, and hiding them only from the agent's shell would not help, because a process of the same user can read the server's environment from /proc. The agent is told not to use them; that is an instruction, not a control.

Open questions for reviewers (1, 3 and 6 especially for Thomas A Caswell (@tacaswell), as the author of #37)

  1. Sourcing bwopencode2 is the smallest change but couples the two launchers. Is a follow-up PR that moves the shared code into lib/ after Feat/bwrap private netns #37 the right way to untangle it?

  2. Sharing the --serve port pool and claim directory means one alias covers both. Any objection to the two sharing it?

  3. --share-net is still accepted. The server then binds the user's publish address on the host network, and OpenCode's own port is on the host's loopback behind its own random password. Keep it as the escape hatch for hosts without pasta or slirp4netns, or refuse it for OpenChamber?

  4. The published 127.H1.H2.1 address is not access control (the Feat/bwrap private netns #37 docs say so); another local user can connect, and the UI password keeps them out. Is that acceptable for a UI that gives a terminal, or should this wait for per-user access control on published ports?

  5. OpenChamber's own outbound traffic (update checks, GitHub) goes through the private network and is logged, but nothing filters it.

  6. On a real launch ss -ltnp shows the published socket owned by platform-python (the network log's helper) and not by pasta. Is that expected?

  7. Copilot's review summary of the second push says pasta startup "releases the database session lock", with no detail. Checked on a real launch (fuser on the lock file while a bwopencode2 session ran on pasta): the lock is held for the whole session and released after it ends, but only by the network log's helper processes (a forked copy of the launcher shell and its condenser), which inherited the descriptor before the launcher execed into pasta; pasta, bwrap and OpenCode do not hold it. By reading the code, with no log tool (neither systemd-cat nor logger) there is no helper and the lock would be released at the exec; that is not tested. It is Feat/bwrap private netns #37's launch code and affects bwopencode2 too, so the fix belongs there (I've asked Thomas A Caswell (@tacaswell) on Feat/bwrap private netns #37); the new paragraph in docs/bw-wrappers.md records what was found.

    Separately, Copilot's fourth review found a real bug with --share-net, and I confirmed it: oc2db_guard put the session lock on bash's first free descriptor (10 or 11), and the launcher's descriptor relay hands the sandbox its data on descriptors 10 and up, opening them over whatever is there. The relay closed the lock, so with bwopenchamber (policy 10, context 11) the lock was released while the sandbox ran; bwopencode2 (context 10, lock 11) kept it by luck. Fixed in lib/opencode2-db-lock.sh: the lock is now on a descriptor from 200 up. A lock on 200 stayed held through the real relay and a real bwrap. Two new checks in tests/test-opencode2-db-guard.sh (82 now) fail on the old code and pass on the new. With pasta, pasta closes the descriptor before the relay runs, so the relay never meets it there and the position described above is unchanged.

  8. --serve-open puts the one-time link on the browser's command line, so another user of the host can read it with ps for the moment the browser starts and sign in first (30-day cookie). The published address already accepts every local user, with the password as the only protection, and the link works once and expires in 5 minutes. A local redirect file would avoid it but could not be tested here. Acceptable, or should it wait for that? (docs/bw-wrappers.md says not to use it on a host where others log in.)

  9. The weak directory check described above (_check_dir_safe on a directory bound whole, which accepts a symlink to a directory containing ~/.config/gh) is on main in bwopencode2 (data, cache, TUI state) and, by reading, in bwclaude, bwcodex, bwcopilot and bwopencode. Reproduced for bwopencode2 and fixed here only for bwopenchamber; a comment on Feat/bwrap private netns #37 has the details and the suggested _bwrap_canonicalize_safe fix.

  10. Not in this PR: the ansible install (pinned @openchamber/web, Node 24.14 or newer), and OpenChamber is not on the approved-tools list, so DSSI approval is needed before any rollout.

Testing

Tested on a workstation with a test install of OpenChamber 2.7.0 (not through ansible), with OpenCode 2.2.7.

A real launch (bwopenchamber --port 24700, pasta):

  • The host has one new listener, 127.H1.H2.1:24700, and nothing on 3000 or on OpenCode's port. Without a password the API gives 401, the same port on 127.0.0.1 is refused, and OpenCode's own port is refused from the host.
  • A browser signed in through an ssh -L tunnel and an agent session worked through the model gateway.
  • OpenChamber's browser terminal runs inside the sandbox: BWRAP_SANDBOX is bwopenchamber, ~/.ssh does not exist, ssh is masked and BWRAP_NET_BACKEND is pasta.
  • After Ctrl-C the OpenCode that OpenChamber started is gone.
  • The database guard refused to start next to an older OpenCode build, as designed.
  • The sign-in key was checked against the real server in a private network namespace: without a key a cookie survives a restart and a new password and jwt-secret is written; with a new key per run the cookie is refused after a restart (401), signing in again works, and no file is written.

Tests and lint

  • tests/test-bwopenchamber.sh: 104 checks through --dry-run (argument refusals, a symlinked data directory (refused when it leads to a directory containing .config/gh), the environment and mounts built, the generated policy file, hostile host variables dropped, password and sign-in key handling, Node and install checks). tests/bwopenchamber-harness accepts the development machine's bwrap, and stubs the port probe, so a running session holding the first port cannot change the result (Copilot found that it did; checked that without the stub the same scenario gives the next port). The library's owner check is not changed for real runs. Two checks in the first version could not fail, because --dry-run prints variables named PASSWORD or SECRET as REDACTED; they now check the names.
  • tests/test-opencode2-db-guard.sh: 82 of 82 pass. tests/test_serve_timeout.py passes. bwopencode2 still runs main when executed directly and through a symlink.
  • pixi run -e dev lint on all files passes (every hook, including actionlint and zizmor), and the commit hook passes on the staged files.

--serve-open and the sign-in block

  • tests/test_serve_signin.py (25 tests, with tests/test_serve_timeout.py 73 pass in the whole suite): the in-sandbox wrapper against a fake server (the password reaches it through curl, including a quote and a backslash; a new code on Enter through a pseudo-terminal; no spinning at end of input; a failed pairing) and the host helper against a stub browser (--app= link, plain link, login page when no link came, a launcher that has gone, a helper that survives the launcher's exec, nothing on --dry-run, no password in the browser's arguments).
  • tests/test-bwopencode2-serve.sh: 57 checks through --dry-run (arguments, --serve-open by itself and with --serve, browser choice, no desktop session, no browser installed, a registered default browser, firefox). tests/bwopencode2-harness accepts the development machine's bwrap and stubs the port probe, as for bwopenchamber.
  • A real launch on babelfish (RHEL 10.2, Wayland) with a stand-in browser script: the helper started it once the server answered, with the right link; a browser-style fetch of the link gave 302 to / and the login cookie (value not logged). With no browser installed it opens nothing and says so. After installing Google Chrome, --serve-open works there.

Not tested: git and worktrees from OpenChamber, an install through ansible on a managed host, Enter for a new link inside the real sandbox's terminal (only through a pseudo-terminal), and --serve-open over ssh -X.

Checklist

  • Edit the sections above with relevant information
  • Update in-repo documentation, if applicable
  • Run pixi run -e dev lint locally (or wait for CI) — see .github/workflows/lint.yml
  • Test the changes on a representative managed host (or runansible deployment)

Assisted-by: opencode:claude-sonnet-5-5

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The documentation needs to clarify that private-network mode does not block local access to the published OpenChamber UI and that the UI password controls access in both modes.

1 open issue
What changed in this PR

Adds bwopenchamber to run OpenChamber and its managed OpenCode server within one bubblewrap sandbox, keeping terminals and tool execution isolated. It builds on #37’s private networking; the current diff also includes that dependency’s changes.

Changes:

  • Reuses OpenCode 2 sandbox setup, database protection, and port allocation.
  • Adds OpenChamber-specific policy, passwords, isolated data storage, tests, and documentation.
  • Includes private-network support, network logging, and CI tooling updates from the dependency.
File Description
tests/​test-bwopenchamber.sh Tests launcher arguments, mounts, environment, and passwords.
tests/​test_serve_timeout.py Checks pairing-request timeout handling.
tests/​test_netlog.py Tests network-log parsing and DNS relay behavior.
tests/​fakes/​pasta-bin/​pasta Provides a fake pasta backend.
tests/​fakes/​bin/​unshare Simulates namespace setup and failures.
tests/​fakes/​bin/​systemd-cat Captures journal output for tests.
tests/​fakes/​bin/​slirp4netns Provides a fake slirp4netns backend.
tests/​fakes/​bin/​logger Captures syslog output for tests.
tests/​fakes/​_nsproxy.py Shares namespace and forwarding test helpers.
tests/​fake-net-run Runs launchers with fake network backends.
tests/​bwopenchamber-harness Adapts launcher setup for isolated tests.
README.md Lists OpenChamber and networking requirements.
pixi.toml Adds actionlint and a unit-test task.
pixi.lock Locks actionlint packages across platforms.
lib/​bwrap_netlog.py Adds network-log condensation and DNS logging.
docs/​bw-wrappers.md Documents networking and OpenChamber operation.
bin/​bwopencode2 Adds server support and permits sourcing shared functions.
bin/​bwopencode Integrates private networking and prek cache mounts.
bin/​bwopenchamber Implements the sandboxed OpenChamber launcher.
bin/​bwcopilot Integrates networking and descriptor-based config delivery.
bin/​bwcodex Integrates networking and descriptor-based file delivery.
bin/​bwclaude Integrates networking and descriptor-based credential delivery.
AI_DISCLOSURE.md Updates AI assistance metadata.
.pre-commit-config.yaml Uses Pixi-managed actionlint.
.github/​workflows/​lint.yml Runs Python unit tests in CI.
.codespell.ignore Recognizes the passt package name.

Review effort: Balanced

Comment thread docs/bw-wrappers.md Resolved
Copilot AI balanced review requested due to automatic review settings November 11, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Critical issues allow saved settings to override the guarded executable and pasta startup to release the database session lock, risking shared-database corruption.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 11, 2026 13:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The test harness probes real host sockets, allowing existing sessions to change port selection and break hard-coded assertions or exhaust the port pool.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Stub host socket probe in dry-run port selection tests

tests/​bwopenchamber-harness:17

The harness still probes real host sockets when choosing the server port. The publish address depends on the UID, not the temporary HOME, so running these tests while a real bwopenchamber or bwopencode2 --serve session occupies port 24700 selects 24701 and fails the hard-coded port and tunnel assertions; a full pool makes otherwise valid launches fail entirely. Please stub the availability probe here so these dry-run fixtures are independent of existing sessions.

Review effort: Balanced

Stuart B. Wilkins (stuwilkins) added a commit to stuwilkins/n2snscripts that referenced this pull request Nov 11, 2026
…ests independent of sessions

Copilot review of NSLS2#43 found two real problems, both checked.

Pinning. The launcher passed OPENCODE_BINARY and the docs called OpenCode pinned. Without a policy file OpenChamber 2.7.0 lets a saved opencodeBinary in settings.json override OPENCODE_BINARY, and settings.json is in the persistent data directory that the agent can write. A fake OpenCode named there ran. Only a policy file outranks the saved setting. The launcher now generates /etc/openchamber/policy.json and mounts it read-only from a descriptor (enterprise mode, the installed OpenCode pinned, allowNetworkAccess true for the private network, no extensions, built-in skills catalogues hidden). With it the installed OpenCode started and the fake never ran, and the server still listened on 0.0.0.0. OPENCHAMBER_ALLOW_NETWORK_ACCESS is dropped: the file governs, and with the file missing the server now fails closed instead of running unpinned.

Tests. The harness probed real sockets on the user's publish address, so a running bwopenchamber or bwopencode2 --serve session holding 24700 made every dry run pick 24701 and fail the checks that expect the first port. The probe is stubbed. Without the stub the same scenario gives 24701; with it 24700. New checks cover the generated policy and that a held port changes nothing.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A critical descriptor collision releases the database session lock before sandbox exit, allowing another host to concurrently open the same NFS-backed SQLite database.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 11, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The network-accessible terminal and agent-readable control credentials require maintainer security review, while managed-host deployment and git/worktree integration remain unvalidated atop draft PR #37.

No open issues 🎉

Review effort: Balanced

Stuart B. Wilkins (stuwilkins) added a commit to stuwilkins/n2snscripts that referenced this pull request Nov 11, 2026
…x relay uses

oc2db_guard took the session lock on bash's first free descriptor (10 or 11). The launcher's descriptor relay hands the sandbox its files and data on descriptors 10 and up and opens them over whatever is there, closing the lock and so releasing it while the sandbox runs. bwopencode2 with --share-net (one data descriptor, the lock on 11) kept it by luck; bwopenchamber (policy 10, context 11, lock 11) lost it. Found in Copilot's review of NSLS2#43 and reproduced with the real relay shim and a real bwrap.

The lock is now on the first free descriptor from 200 up. A lock on 200 stayed held through the real relay and bwrap. With pasta the relay never sees it (pasta closes inherited descriptors first), so that path is unchanged. Two new checks open descriptors 10 to 29 through the real relay and assert the lock is above 199 and still held; both fail on the old code. 82 guard checks and the 95 bwopenchamber checks pass.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings November 11, 2026 16:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The resolver can stop at the first versioned Node binary when no unversioned node exists on PATH, selecting an older qualifying version instead of the documented newest one.

No open issues 🎉

Review effort: Balanced

Stuart B. Wilkins (stuwilkins) added a commit to stuwilkins/n2snscripts that referenced this pull request Nov 11, 2026
…ne on PATH

The resolver treated the first candidate as the node on PATH and stopped there when it was new enough. With no node on PATH the first candidate is the first versioned binary (node-24 sorts before node-25), so it chose that one instead of the newest, which the docs promise. Track the node found on PATH explicitly and prefer only that. A test with a PATH that holds no node and node-24 and node-25 in the search directory fails on the old code (it picked node-24) and passes now; 97 checks pass. Found by Copilot's review of NSLS2#43.

Assisted-by: opencode:claude-sonnet-5-5
Copilot AI balanced review requested due to automatic review settings November 11, 2026 19:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The browser-accessible terminal, agent-readable credentials, and network-sharing escape hatch warrant human security review, compounded by reliance on draft #37 and unvalidated managed deployment and git/worktree integration.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 13, 2026 13:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The lint workflow aborts during actionlint version collection, and unsynchronized port claims allow concurrent launches to select the same port.

1 open issue

Review effort: Balanced

Comment thread .pre-commit-config.yaml Resolved
Copilot AI balanced review requested due to automatic review settings November 13, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because multiple critical sandbox-boundary risks could allow host-side code execution or expose host credentials and session sockets.

No open issues 🎉

Review effort: Balanced

bwopenchamber sources this file for its OpenCode 2 mounts, environment and --serve port pool. Running the launcher, directly or through a symlink, is unchanged.

Assisted-by: opencode:claude-sonnet-5-5
OpenChamber is a web server that starts its own opencode serve and adds a terminal, git and worktree handling. All of that does work, so it all runs in one sandbox: the server, its OpenCode, the shells, git and every tool call. Only the browser is outside, behind an ssh tunnel.

The launcher sources bwopencode2 for the OpenCode 2 mounts, the database guard and the --serve port pool, so one ssh_config alias covers both. The port is published on the user's 127.H1.H2.1; the server listens on 0.0.0.0 inside the private network. A random UI password is set for each session.

Enterprise mode is forced on through the environment and /etc/openchamber/policy.json is not mounted, because a policy file would override it. OPENCODE_BINARY is pinned and no host OPENCODE_* or OPENCHAMBER_* variable reaches the server. OpenChamber's run/ directory, where it writes the UI password in plain text, is a tmpfs. No OpenChamber argument is passed through.

Assisted-by: opencode:claude-sonnet-5-5
SCRIPT_DIR came from $0, which is the running script. When bwopenchamber or a test sources bwopencode2 from another directory, the library was looked up next to that script, so it only worked by accident. BASH_SOURCE[0] is the same value when bwopencode2 runs directly or through a symlink.

Assisted-by: opencode:claude-sonnet-5-5
… limits

OpenChamber 2.7.0 signs sign-in cookies with a key it writes to jwt-secret in its data directory and reuses. A browser that signed in stayed signed in across restarts and after the password changed, and the agent could read the file. The launcher now sets a random OPENCODE_JWT_SECRET for each session; checked against the real server that the old cookie is refused after a restart and that no jwt-secret file is written.

The docs now say that the published 127.H1.H2.1 address is not access control (any local user can connect, the UI password keeps them out), which the first version of this launcher got wrong. They also record that the agent can read the UI and server passwords OpenChamber puts in its environment, checked in a running session, and that hiding them from the agent's shell would not help because /proc/PID/environ is readable by the same user. The agent is told in the sandbox context not to use them.

The checks made on a real launch move from not checked to checked. Two tests that could not fail are fixed: --dry-run prints variables named PASSWORD or SECRET as REDACTED, so they now check the names.

Assisted-by: opencode:claude-sonnet-5-5
Checked in a running session: the agent's shell has OPENCODE_JWT_SECRET set (printenv | grep -c prints 1). The per-session key stops a reusable key being stored, but an agent can still sign a cookie for the current session. Say so under the sign-in key and in the known limit.

Assisted-by: opencode:claude-sonnet-5-5
…ests independent of sessions

Copilot review of NSLS2#43 found two real problems, both checked.

Pinning. The launcher passed OPENCODE_BINARY and the docs called OpenCode pinned. Without a policy file OpenChamber 2.7.0 lets a saved opencodeBinary in settings.json override OPENCODE_BINARY, and settings.json is in the persistent data directory that the agent can write. A fake OpenCode named there ran. Only a policy file outranks the saved setting. The launcher now generates /etc/openchamber/policy.json and mounts it read-only from a descriptor (enterprise mode, the installed OpenCode pinned, allowNetworkAccess true for the private network, no extensions, built-in skills catalogues hidden). With it the installed OpenCode started and the fake never ran, and the server still listened on 0.0.0.0. OPENCHAMBER_ALLOW_NETWORK_ACCESS is dropped: the file governs, and with the file missing the server now fails closed instead of running unpinned.

Tests. The harness probed real sockets on the user's publish address, so a running bwopenchamber or bwopencode2 --serve session holding 24700 made every dry run pick 24701 and fail the checks that expect the first port. The probe is stubbed. Without the stub the same scenario gives 24701; with it 24700. New checks cover the generated policy and that a held port changes nothing.

Assisted-by: opencode:claude-sonnet-5-5
…etwork

The database guard section said the lock is a descriptor that the final exec passes on to bwrap. With a private network the launcher execs into pasta, which closes inherited descriptors, so nothing in the sandbox holds it. On a real launch fuser on the lock file showed only the network log's helper processes (a forked copy of the launcher shell and its condenser) holding it; it was held all session and gone after exit. So the guard works, but through inheritance by a helper started before the exec.

Record that, and the two cases the code implies but that were not tested: no log tool, so no helper, and a helper stopped mid-session. Prompted by a Copilot review summary that said pasta releases the lock: the claim is wrong for the normal launch and right in outline for those cases.

Assisted-by: opencode:claude-sonnet-5-5
…one on PATH

The launcher took the first node on PATH and stopped if it was older than 24.14. On RHEL 10 the default node is 22 and the nodejs24 package installs node-24 next to it, so a new enough Node was installed and the launcher still refused. Resolve it in this order: BWOPENCHAMBER_NODE if set (only that one; an error if too old), the node on PATH if it is new enough, then the newest node-24 or nodejs24 style binary in /usr/bin and /usr/local/bin that is. The error lists what was found with versions and what to do on RHEL 10, RHEL 8 and 9, and with BWOPENCHAMBER_NODE (for example a pixi Node).

Checked on the real host with no stubs: /usr/bin/node and /usr/bin/node-22 are both 22.23.2 and the message lists them; BWOPENCHAMBER_NODE set to a pixi Node 24.22.1 launches. The tests are hermetic by default (the versioned search points at an empty directory) and cover each rule, a binary that is not node and one that is not executable. RHEL 9 (runansible1) has 24.21.0 on PATH from the nodejs:24 module and RHEL 10 offers nodejs24 24.19.0 through Satellite; whether nodejs24 installs a binary called node-24 is inferred from node-22 being there, not checked.

Assisted-by: opencode:claude-sonnet-5-5
…x relay uses

oc2db_guard took the session lock on bash's first free descriptor (10 or 11). The launcher's descriptor relay hands the sandbox its files and data on descriptors 10 and up and opens them over whatever is there, closing the lock and so releasing it while the sandbox runs. bwopencode2 with --share-net (one data descriptor, the lock on 11) kept it by luck; bwopenchamber (policy 10, context 11, lock 11) lost it. Found in Copilot's review of NSLS2#43 and reproduced with the real relay shim and a real bwrap.

The lock is now on the first free descriptor from 200 up. A lock on 200 stayed held through the real relay and bwrap. With pasta the relay never sees it (pasta closes inherited descriptors first), so that path is unchanged. Two new checks open descriptors 10 to 29 through the real relay and assert the lock is above 199 and still held; both fail on the old code. 82 guard checks and the 95 bwopenchamber checks pass.

Assisted-by: opencode:claude-sonnet-5-5
…ne on PATH

The resolver treated the first candidate as the node on PATH and stopped there when it was new enough. With no node on PATH the first candidate is the first versioned binary (node-24 sorts before node-25), so it chose that one instead of the newest, which the docs promise. Track the node found on PATH explicitly and prefer only that. A test with a PATH that holds no node and node-24 and node-25 in the search directory fails on the old code (it picked node-24) and passes now; 97 checks pass. Found by Copilot's review of NSLS2#43.

Assisted-by: opencode:claude-sonnet-5-5
Print the ssh command, a one-time sign-in link and a google-chrome --app
command in one block once the server is up, and a new link when Enter is
pressed. --serve-open starts a browser on the host, outside the sandbox, with
a pairing link of its own.

Assisted-by: opencode:claude-sonnet-5-5
…ut a browser

With no browser installed and none registered, xdg-open on GNOME opens the
link in the text editor, which shows an Unauthorized error and uses up the
one-time link. Use xdg-open only when xdg-mime names a default web browser,
try firefox before it, and otherwise say that nothing will be opened.

Assisted-by: opencode:claude-sonnet-5-5
…ve link

The server redirects and sets the cookie only for Accept: text/html; curl or the GNOME text editor get a JSON token and use up the one-time code.

Assisted-by: opencode:claude-sonnet-5-5
…en browser

The helper inherited the database session lock descriptor and so did the browser it started, which then held the lock for as long as its window stayed open and made the next launch on the same data directory fail. Close every descriptor above 2 in the helper.

Also check the default browser for http, the scheme of the sign-in link, not https.

Assisted-by: opencode:claude-sonnet-5-5
--serve-open is now --serve plus a browser on the same host, so it needs no --serve next to it, and --serve alone still opens nothing. --serve-port also works with --serve-open.

Assisted-by: opencode:claude-sonnet-5-5
… blocked path

The data directory is bound whole and read-write, but it was only checked with _check_dir_safe, which accepts a symlink to a directory that contains ~/.config/gh. Check it in bind mode and mount the resolved path.

Assisted-by: opencode:claude-sonnet-5-5
For the host you are on, print one line when the browser opened, or only a fresh one-time link to open by hand with the password when it did not (no browser, no desktop session, the browser exited with an error within 8 seconds, or the server never answered). --serve prints the same block as before.

Assisted-by: opencode:claude-sonnet-5-5
actionlint became a local pixi hook, so its repo entry is gone and the grep exited 1, stopping every lint job in Collect tool versions under pipefail.

Assisted-by: opencode:claude-sonnet-5-5
…caping, hold bwopenchamber's lock

Copilot's review of NSLS2#37 named two problems in the --serve code, and a third gap is closed here.

- Port claims: two launches that start together and both see a stale claim file could each remove the other's new file and end up with the same port. serve_choose_port now holds an flock on claims.lock in the state directory while it cleans up stale claims and claims a port, and releases it before the sandbox starts (without flock it warns, as the publish-address claim does). tests/test_serve_claims.py starts six launches at once against stale files, and a launch that must wait for a held lock; both fail without the lock.
- Password: both pairing calls already escape a backslash and a double quote before writing curl's config. Add the missing test for the host-side one (serve_request_code), and refuse a BWOPENCODE2_SERVE_PASSWORD with a control character, a newline for one, which would add a second line to curl's config. The help texts and docs say so.
- bwopenchamber registers its database lock with net_hold_fd, as bwopencode2 does since the holder commit in NSLS2#37, so its lock is held under pasta without a log tool. Tests start the real guard against a temporary data directory for both launchers.
- docs/bw-wrappers.md: the lock under a private network is now held by the holder (it described the accident), and the claims lock is described.

Assisted-by: opencode:claude-sonnet-5-5
Assisted-by: opencode:gpt-6-astra
…em directories only

The --serve-open helper runs on the host, outside the sandbox, for as long as it waits for the server (up to a minute) and then starts the browser. It found curl, sleep, setsid, grep and basename through the launcher's PATH, which can include a directory the sandbox can write to (an activated project environment, for one): an agent could replace one of those tools and have it run on the host. Copilot's review of NSLS2#43 reported it.

serve_open_detached now sets PATH=/usr/bin:/bin before it runs the helper, as the launcher already does for the exec, and as the database lock holder does with /usr/bin/sleep. The browser stays the full path chosen before the sandbox started; it and its children get the same PATH, which the docs say. A test puts fakes of the five tools in a directory first on PATH and checks that none ran; it fails without the change.

Assisted-by: opencode:claude-sonnet-5-5
…tories only

The browser is started on the host, outside the sandbox, but it was found with command -v on the launcher's PATH, which can include a directory the sandbox can write to (an activated project environment, ~/.pixi). An agent could plant a chromium or firefox there and have it run outside the sandbox. Copilot's review of NSLS2#43 reported it on the last commit.

The browser, xdg-open and xdg-mime are now looked up in /usr/bin, /usr/local/bin and /snap/bin only. A program is used only when it, the file it resolves to through symlinks and the directories that hold them are owned by root and not writable by group or others; one that is not is skipped. BWOPENCODE2_SERVE_BROWSER takes a name in those directories or an absolute path, under the same rule, and stops the launch with a message when it fails. There is no switch to turn the check off.

The harness takes the directories and the owner from HARNESS_SERVE_OPEN_DIRS and HARNESS_SERVE_OPEN_UID, so the stubs can be owned by the test user; the real rule is tested too. 18 of the new checks fail without the change.

Assisted-by: opencode:claude-sonnet-5-5
…re directory

The negative check for files not owned by root cleared the harness directories and so searched the real system directories: on a workstation with a root-owned Chrome or Firefox it found one and failed. It now keeps the stub directory, where the stubs are refused because the test user owns them. The check that a system browser is found with the real directories still runs only where one is installed, and now looks for any of the launcher's candidates in any of its directories instead of the first one on PATH. Copilot's review of NSLS2#43 reported it.

Assisted-by: opencode:claude-sonnet-5-5
…mal environment, drop BWOPENCODE2_SERVE_BROWSER

Copilot's review of NSLS2#43 said inherited startup and loader variables and replaceable browser paths can run agent-controlled code outside the sandbox.

The helper's curl, sleep, setsid, grep and basename, and the browser, now run under env -i with PATH=/usr/bin:/bin and only the variables a desktop program needs (HOME, USER, LANG, LC_*, DISPLAY, WAYLAND_DISPLAY, XAUTHORITY, XDG_RUNTIME_DIR, DBUS_SESSION_BUS_ADDRESS and a few more). LD_PRELOAD, LD_LIBRARY_PATH (an activated project environment sets it), BASH_ENV, ENV, BROWSER, XDG_DATA_DIRS and the rest no longer reach them. A test starts the helper with those set and a browser that records its environment; it fails without the change.

BWOPENCODE2_SERVE_BROWSER is removed. An absolute path from the caller would have to be checked up to the root, since a root-owned file under a directory the user owns can be swapped by renaming the directory, and the choice is not worth that. The browser is found by name in /usr/bin, /usr/local/bin and /snap/bin only, as before. A leftover variable is ignored, and a test says so.

Assisted-by: opencode:claude-sonnet-5-5
…-open fallback

Copilot's review of NSLS2#43 named Node probing and HTTP handler launches as ways to run agent-controlled code outside the sandbox.

bwopenchamber ran 'node --version' on the host for every candidate, including the node on PATH, which can be in a directory the sandbox can write to (~/.pixi/bin, where pixi global installs node). The probe now runs in a sandbox of its own: bwrap with the file system read-only, all namespaces unshared and an empty environment (env -i, for bwrap too, which keeps it working with bwrap 0.4.0). A replaced node can only print a version; the one chosen runs in the real sandbox as before. A test puts a node on PATH that tries to write a file and is still chosen; the write fails, and the test fails without the change.

bwopencode2 --serve-open no longer falls back to xdg-open. It started whatever ~/.config/mimeapps.list and a .desktop file named, which the launcher cannot check, and xdg-mime, a shell script, ran on the host to decide. Only google-chrome, google-chrome-stable, chromium, chromium-browser and firefox, checked as before, are started; without one the link is printed to open by hand.

Assisted-by: opencode:claude-opus-5-5
Copilot's review of NSLS2#43 named inherited loader variables as a risk. A loader or shell start-up variable in the shell that starts a launcher (LD_PRELOAD, LD_LIBRARY_PATH, BASH_ENV, ENV) takes effect in the launcher's bash before its first line, so the launcher cannot defend against it; re-running under env -i would lose the variables it needs. The new section says not to point them into a directory the sandbox can write to, and lists what the launchers already start with a clean environment.

Assisted-by: opencode:claude-opus-5-5
…and /tmp

Copilot's review of NSLS2#43 (on cdfa67b) said a replaced node could still reach host credentials and Unix sockets from its version probe. It could: the probe bound the whole file system read-only, so a planted node could read ~/.ssh, the N2C tokens in /run/user and connect to Unix sockets such as the D-Bus session bus, which a network namespace does not stop.

The probe now sees, read-only, only /usr, /bin, /sbin, /lib, /lib64 and /etc, the candidate's directory and that of the file it resolves to, and that file's PREFIX/lib (a conda or pixi environment), with an empty /tmp. A node directly in the home directory or above it is not probed. A pixi global trampoline in ~/.pixi/bin starts a node the probe cannot see and is no longer found; BWOPENCHAMBER_NODE can name the real one, as the docs say. The system node, node-24 and a pixi exec node were checked by hand. The test's planted node now reports a usable version only when it could read nothing outside its own directory; it and the home-directory check fail without the change.

Assisted-by: opencode:claude-opus-5-5
@tacaswell

Copy link
Copy Markdown
Contributor

The rebase ran cleanly. I think the issue is I rebased/squashed some commits in #37 so git got a little confused.

~/s/b/n/n2snscripts add_bwopenchamber|…11
✔ 13:35:55 [belanna] @ git rebase upstream/main
warning: skipped previously applied commit e8738f0
warning: skipped previously applied commit 9db2362
warning: skipped previously applied commit 7294e18
warning: skipped previously applied commit e903753
warning: skipped previously applied commit 5d22538
hint: use --reapply-cherry-picks to include skipped commits
hint: Disable this message with "git config set advice.skippedCherryPicks false"
Successfully rebased and updated refs/heads/add_bwopenchamber.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants