Repository navigation
feat(bwopenchamber): add bwopenchamber and bwopencode2 --serve-open - #43
Open
Stuart B. Wilkins (stuwilkins) wants to merge 54 commits into
Open
Stuart B. Wilkins (stuwilkins) wants to merge 54 commits into
Stuart B. Wilkins (stuwilkins) wants to merge 54 commits into
Conversation
Runs opencode2 serve inside the sandbox on 127.0.0.1, so tools stay sandboxed, with one server per invocation on the first free port of a fixed range (24700-24709 by default) so one ssh_config block covers every session. The password is random for each session unless BWOPENCODE2_SERVE_PASSWORD is set, and reaches the server only as OPENCODE_PASSWORD. Ports are claimed with a host-side file so two launchers cannot pick the same one. --serve-ssh-config prints the matching ssh_config block. Assisted-by: opencode:claude-sonnet-5-5
The web UI opens on a page that asks for a pairing link or the password, and opencode pair points at the shared service, which the wrapper refuses. Inside the sandbox a small wrapper now starts the server, waits for it, asks it for a pairing code and prints the link, so the browser can sign in without typing the password. The password reaches curl on stdin, never on a command line. Use password still works after the link expires. Assisted-by: opencode:claude-sonnet-5-5
pasta, which will start bwrap in a private network namespace, closes every inherited descriptor above 2, so the --file and --ro-bind-data descriptors opened by the launcher would never reach bwrap. The launcher now only reserves descriptor numbers and records their source (a host file, or generated text carried in the environment); a fixed bash relay opens them at those numbers and execs bwrap. bwcodex no longer stages temporary copies of its config and daemon settings, and --dry-run shows real descriptor numbers instead of placeholders. Assisted-by: opencode:claude-opus-5-5
pasta (package passt) now starts each sandbox in its own network namespace. Outbound connections still leave from the host's address, but the host's loopback services are unreachable and the sandbox's listeners are invisible to the host. There is no fallback to the host network: without a working pasta the launchers exit 3. Crossing the boundary is a per-port, per-launch opt-in: - --publish PORT[:SANDBOXPORT] binds a per-user, per-session host address 127.H1.H2.S (--publish-addr overrides it, e.g. for OAuth); - --host-port PORT[:SANDBOXPORT] makes the host's 127.0.0.1:PORT reachable as host.internal, with a deny list (CUPS, Docker, X11, Tailscale, the OpenCode 2 service); - --net-log FILE records every flow. pasta maps the caller to uid 0 in its user namespace, so bwrap now runs the agent as the real uid in a nested one (--unshare-user --uid --gid); without it the agent would be root with a full capability set there. bwrap also restores the real hostname that pasta replaces. /etc/resolv.conf and /etc/hosts are generated, the context file gains a Network section, and BWRAP_NET_* describe the forwards. This breaks --serve, will fix later. Assisted-by: opencode:claude-opus-5-5
Document the pasta requirement, --publish / --publish-addr / --host-port / --net-log, the per-user publish addresses and what they do not guarantee, host.internal and the loopback-trust caveat, and the descriptor relay. Assisted-by: opencode:claude-opus-5-5
passt is in RHEL 9 but not RHEL 8. Without a working pasta the sandbox now shares the host network as before, with a warning, instead of refusing to start. --local-net chooses the host network explicitly and silences the warning. The forwarding options still need pasta: with --local-net they are an error, and without pasta they stop the launch (exit 3). BWRAP_NET_MODE tells the sandbox which mode it is in, and the context file describes both. Assisted-by: opencode:claude-opus-5-5
Use bwrap's own term for sharing the host network namespace. Assisted-by: opencode:claude-opus-5-5
Without a usable private network namespace the launchers now exit 3 naming the reason, instead of warning and sharing the host network. Only --share-net shares it. BWRAP_NET_BACKEND (pasta or none) replaces BWRAP_NET_MODE, ready for a second backend. Assisted-by: opencode:claude-opus-5-5
RHEL 8 has slirp4netns but no passt. When pasta is not usable, the launchers now use slirp4netns: util-linux unshare gives the launcher a user namespace that owns a new network namespace, bwrap runs the sandbox in it as the real user, and a background helper attaches slirp4netns (--disable-host-loopback, 192.168.254.0/24, built-in DNS) before releasing the sandbox through --block-fd. The launcher still execs in the foreground; slirp4netns exits with bwrap (--sync-fd). On a setup failure the helper kills the blocked sandbox before the tool starts. unshare, not bwrap --unshare-net, makes the namespaces: bwrap's devpts setup nests the sandbox in a second user namespace, from which slirp4netns would have no rights over the network namespace. --publish works through the slirp4netns API socket; --host-port and --net-log need pasta. --net-backend restricts the choice to one backend. Assisted-by: opencode:claude-opus-5-5
Document the selection order (pasta, slirp4netns, else stop unless --share-net), --net-backend, what each backend supports, and how the slirp4netns launch works. Assisted-by: opencode:claude-opus-5-5
--serve now adds its port to --publish: the server binds 0.0.0.0 inside the private namespace and is reached on the host at the user's publish address 127.H1.H2.S (normally .1), with both backends. With --share-net it binds 127.H1.H2.1 itself. The port is chosen free on that address, the printed ssh -L command and pairing links name it, and --serve-ssh-config forwards to it. net_publish_prefix exposes the per-user prefix. Assisted-by: opencode:claude-opus-5-5
The slirp4netns pipes and API socket were in a mktemp directory under XDG_RUNTIME_DIR or TMPDIR, whose parent was not checked: another user able to write it could swap the directory during the launch. They now go in a per-launch session directory under $XDG_RUNTIME_DIR/bwrap-net, else /tmp/bwrap-net-UID, used only when no other user can change its parent and it is the user's own 0700 directory. TMPDIR is never used. Both locations are blocked paths, so no sandbox of the user can mount them and reach another sandbox's API socket. Assisted-by: opencode:claude-opus-5-5
The slirp4netns helper kept polling after the launcher had gone (for example when unshare failed) and then sent SIGKILL to the saved pid, which by then could belong to another process. It now exits quietly as soon as its parent is no longer the launcher, and before killing it checks that the launcher is still its parent and that the sandbox pid is the launcher's child. Assisted-by: opencode:claude-opus-5-5
The publish address came from one ss snapshot, and the backend binds it only after exec, so two launches at the same moment could pick the same address and port. The choice is now made under flock in the runtime directory, and each launch leaves a claim (launcher pid and start time, host ports) that later launches respect; claims whose process is gone are removed. --serve port claims also record the start time, so a reused pid does not keep them alive. Assisted-by: opencode:claude-opus-5-5
The header still said that without pasta the sandbox shares the host network with a warning; the launch tries slirp4netns and otherwise stops unless --share-net is given. Assisted-by: opencode:claude-opus-5-5
pasta writes one log file, and the network log becomes an always-on journal record in the next commit; a file the user names is easier to edit, lose, or leave where the agent can write it. Assisted-by: opencode:claude-opus-5-5
…m log Every launch writes start and end records (tag bwrap-net, a session id also given to the sandbox as BWRAP_SESSION) with systemd-cat, else logger; with neither it warns and runs without the log. There is no option to turn it off. With pasta every flow is logged too: pasta runs with --debug and a FIFO as --log-file (huge --log-size, as its rotation fails on a FIFO) and as its stderr, and a supervisor outside the sandbox copies each line to the log, holding the FIFO open so pasta never blocks. The descriptor relay prints a marker and reopens the user's stderr, so pasta's setup lines go to the log, and if pasta fails before the marker its lines are shown on the terminal. Assisted-by: opencode:claude-opus-5-5
tests/fake-net-run runs a launcher against fake pasta, slirp4netns, unshare, systemd-cat and logger, where /dev/net/tun is missing (as in a development sandbox). The fakes really create or join the namespaces and forward TCP, so --publish, --serve and the network log can be tested end to end; failure modes are read from $FAKE_NET_DIR. Assisted-by: opencode:claude-opus-5-5
A --serve session could move to another session index when one of its ports was busy on 127.H1.H2.1, and the --serve-ssh-config alias then did not reach it. --serve now fixes the session's publish address to .1: its port is chosen free and unclaimed there, a clash with another --publish port stops the launch with the reason, and --publish-addr is refused with --serve. The fake pasta now handles comma-separated port lists and never starts the command when its setup failed. Assisted-by: opencode:claude-opus-5-5
pasta's -T takes no listening address ("Listening address not allowed
for -T"): it always listens on the namespace's loopback. So
--host-port PORT[:SANDBOXPORT] now passes -T SANDBOXPORT:PORT and the
agent reaches the host service at 127.0.0.1:SANDBOXPORT; host.internal,
127.0.42.1 and BWRAP_NET_HOST_ADDR are gone. That sandbox port is held
by pasta, so a --publish to it is refused, and the context file says
the agent cannot serve on it.
The fake pasta now rejects an address on -T/-U and listens on the
namespace's loopback, as the real one does; it had accepted the old
form, which is why the tests passed.
Assisted-by: opencode:claude-opus-5-5
pasta's debug log has about 34 lines per connection (state changes, timers, ACK bookkeeping) plus a doubled setup dump, and only addresses. lib/bwrap_netlog.py condense now turns it into one logfmt line when a connection opens and one when it closes (with its duration), a fail line for connections that never became active, and pasta's warnings and errors; 5000 lines of a real session became 280. To name destinations, bwrap_netlog.py dns runs as a DNS relay on 127.53.0.1:53 in the sandbox's network namespace, started by the descriptor relay before bwrap (it waits until the relay listens, at most 0.25 s) and dropping its capabilities after binding. It logs one dns line per lookup and forwards to pasta's DNS address, which resolv.conf lists second so lookups go on working if the relay is down. The condenser adds name= to connections from the answers. Both need Python 3.6+ (platform-python on RHEL 8); without it the log is unfiltered as before. Assisted-by: opencode:claude-opus-5-5
Unit tests (pixi run -e dev test) against part of a real pasta debug log with documentation addresses, and a DNS relay against a local fake upstream. The fake pasta now writes pasta's debug format for its forwards and answers DNS on --dns-forward, so the launchers' log can be checked end to end with tests/fake-net-run. Assisted-by: opencode:claude-opus-5-5
On a real session the first IPv6 connections were logged without a name: the client connected as soon as it had the answer, before the relay had written its dns line. The relay now logs first. CNAMEs go to cname= so answers= holds addresses only. Assisted-by: opencode:claude-opus-5-5
…rk log name= did not say what it was. Connection and dns lines now use domain= (the domain the relay looked up), which is also what an allow-list is written in. Assisted-by: opencode:claude-opus-5-5
The upstream actionlint hook is language: golang: prek downloads a Go toolchain and builds it in every fresh environment, which is where sandboxed sessions' connections to go.dev, dl.google.com and proxy.golang.org came from. conda-forge has actionlint 1.7.12, the pinned version, so it now runs from the pixi dev environment like the other linters. Assisted-by: opencode:claude-opus-5-5
~/.cache/prek (or $PREK_HOME, passed through) is shared with the host when it exists, like the npm, pixi and ccache caches. A sandbox no longer sets up every hook environment again, and so no longer builds gitleaks from source with a freshly downloaded Go toolchain (go.dev, dl.google.com, proxy.golang.org) each session. As with the other caches, the agent can change what is in it, and prek runs hooks from it on the host. Assisted-by: opencode:claude-opus-5-5
Assisted-by: opencode:gpt-6-sol
2 of 4 tasks
Only the start and end records carried user=, so a dns, open, close or fail line could be attributed only by looking up its session. Every record now begins session=ID user=NAME, written by the condenser (--user) and by the fallback supervisor used without Python. The name is the account of the launcher process (id -un), not $USER, which the caller can set, and characters that could split a logfmt field are replaced. The start and end records use the same value. Assisted-by: opencode:claude-sonnet-5-5
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
Stuart B. Wilkins (stuwilkins)
force-pushed
the
add_bwopenchamber
branch
from
November 15, 2026 21:55
ffc9ba2 to
67026cb
Compare
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
There was a problem hiding this comment.
🔵 Needs a closer look
The browser terminal requires human security/operations sign-off on documented credential exposure and --share-net tradeoffs, plus managed-host integration validation, while its sandbox/network behavior depends on unmerged PR #37.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
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
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 thessh -Lcommand, a one-time sign-in link and agoogle-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 ofbwopenchamber.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 forbwopenchamberand its sign-in, database-lock and data-directory fixes, and six forbwopencode2 --serve-openand 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-openterminal output). Once #37 merges, the diff here shrinks to those.Description
Why a launcher of its own, and not
bwopencode2 --servebehind 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
bin/bwopencode2(it now runsmainonly when executed, and finds its library from its own file) for the OpenCode 2 mounts, environment, database guard and the--serveport pool, so a fix made there applies to both. Moving that shared code intolib/is deliberately left for after Feat/bwrap private netns #37 lands, becausebwopencode2is being rewritten there.--serve(24700-24709), published on the user's127.H1.H2.1; one ssh_config block (--ssh-config) covers both. The server listens on0.0.0.0inside the private network, as--servedoes.BWOPENCODE2_SERVE_PASSWORD), passed only in the sandbox environment.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./etc/openchamber/policy.jsonthat 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: truefor the private network, no extensions. It is a file, not environment variables, because without one a savedopencodeBinaryin OpenChamber'ssettings.json(which the agent can write) overridesOPENCODE_BINARY; only a policy file outranks it. Copilot's review found this: a fake OpenCode named insettings.jsonran with the environment alone, and did not run with the file.OPENCODE_*orOPENCHAMBER_*variable reaches the server, and no OpenChamber argument is passed through.PATH:BWOPENCHAMBER_NODEif set, else thenodeonPATHif it is 24.14 or newer, else the newestnode-24/nodejs24in/usr/binand/usr/local/binthat is (RHEL 10 keepsnodejs22 as the default andnodejs24installsnode-24beside it). With nonodeonPATHit 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/nodeand/usr/bin/node-22(both 22.23.2), andBWOPENCHAMBER_NODEset 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, fromnodejs24, installed next to the default 22.23.2), and a real launch started the server, the pinned OpenCode and the browser terminal'snode-pty. The matching install is NSLS2/ansible#5064.~/.config/gh) is refused, and the resolved path is what is mounted (found in Copilot's review;_check_dir_safehad accepted it).~/.local/share/bwopenchamber, apart from any OpenChamber run outside a sandbox. Itsrun/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-openssh -Lcommand and the ssh_config alias, the one-time sign-in link forhttp://127.0.0.1:PORT, the same link as agoogle-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-openis--serveplus a browser on the same host, so it works by itself (--serve --serve-openmeans the same) and--servealone 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(orgoogle-chrome-stable,chromium,chromium-browser), elsefirefox, elsexdg-openbut only whenxdg-mimenames a default web browser forhttp(the scheme of the link).BWOPENCODE2_SERVE_BROWSERnames another one. With no desktop session (DISPLAYandWAYLAND_DISPLAYunset) or no browser it opens nothing and says so;--dry-runopens nothing.--serve-openterminal 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).--serveoutput is unchanged.xdg-openis guarded: on a workstation with no browser,xdg-openhanded the link to the GNOME text editor, which showed "Could Not Open File, HTTP Client Error: Unauthorized"./and sets the cookie only forAccept: text/html;curlor 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 hasOPENCHAMBER_UI_PASSWORD,OPENCODE_SERVER_PASSWORD,OPENCODE_PASSWORDand the newOPENCODE_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)
Sourcing
bwopencode2is the smallest change but couples the two launchers. Is a follow-up PR that moves the shared code intolib/after Feat/bwrap private netns #37 the right way to untangle it?Sharing the
--serveport pool and claim directory means one alias covers both. Any objection to the two sharing it?--share-netis 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?The published
127.H1.H2.1address 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?OpenChamber's own outbound traffic (update checks, GitHub) goes through the private network and is logged, but nothing filters it.
On a real launch
ss -ltnpshows the published socket owned byplatform-python(the network log's helper) and not bypasta. Is that expected?Copilot's review summary of the second push says pasta startup "releases the database session lock", with no detail. Checked on a real launch (
fuseron the lock file while abwopencode2session 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 launcherexeced into pasta; pasta,bwrapand OpenCode do not hold it. By reading the code, with no log tool (neithersystemd-catnorlogger) there is no helper and the lock would be released at theexec; that is not tested. It is Feat/bwrap private netns #37's launch code and affectsbwopencode2too, so the fix belongs there (I've asked Thomas A Caswell (@tacaswell) on Feat/bwrap private netns #37); the new paragraph indocs/bw-wrappers.mdrecords what was found.Separately, Copilot's fourth review found a real bug with
--share-net, and I confirmed it:oc2db_guardput 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 withbwopenchamber(policy 10, context 11) the lock was released while the sandbox ran;bwopencode2(context 10, lock 11) kept it by luck. Fixed inlib/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 realbwrap. Two new checks intests/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.--serve-openputs the one-time link on the browser's command line, so another user of the host can read it withpsfor 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.mdsays not to use it on a host where others log in.)The weak directory check described above (
_check_dir_safeon a directory bound whole, which accepts a symlink to a directory containing~/.config/gh) is onmaininbwopencode2(data, cache, TUI state) and, by reading, inbwclaude,bwcodex,bwcopilotandbwopencode. Reproduced forbwopencode2and fixed here only forbwopenchamber; a comment on Feat/bwrap private netns #37 has the details and the suggested_bwrap_canonicalize_safefix.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):127.H1.H2.1:24700, and nothing on 3000 or on OpenCode's port. Without a password the API gives 401, the same port on127.0.0.1is refused, and OpenCode's own port is refused from the host.ssh -Ltunnel and an agent session worked through the model gateway.BWRAP_SANDBOXisbwopenchamber,~/.sshdoes not exist,sshis masked andBWRAP_NET_BACKENDispasta.jwt-secretis 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-harnessaccepts the development machine'sbwrap, 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-runprints variables named PASSWORD or SECRET asREDACTED; they now check the names.tests/test-opencode2-db-guard.sh: 82 of 82 pass.tests/test_serve_timeout.pypasses.bwopencode2still runsmainwhen executed directly and through a symlink.pixi run -e dev linton all files passes (every hook, including actionlint and zizmor), and the commit hook passes on the staged files.--serve-openand the sign-in blocktests/test_serve_signin.py(25 tests, withtests/test_serve_timeout.py73 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'sexec, nothing on--dry-run, no password in the browser's arguments).tests/test-bwopencode2-serve.sh: 57 checks through--dry-run(arguments,--serve-openby itself and with--serve, browser choice, no desktop session, no browser installed, a registered default browser, firefox).tests/bwopencode2-harnessaccepts the development machine'sbwrapand stubs the port probe, as forbwopenchamber.302to/and the login cookie (value not logged). With no browser installed it opens nothing and says so. After installing Google Chrome,--serve-openworks 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-openoverssh -X.Checklist
pixi run -e dev lintlocally (or wait for CI) — see.github/workflows/lint.ymlrunansibledeployment)Assisted-by: opencode:claude-sonnet-5-5