Skip to content

Add experimental bwrap sandbox backend - #6

Open
kain88-de wants to merge 3 commits into
mainfrom
sandbox-bwrap
Open

kain88-de wants to merge 3 commits into
mainfrom
sandbox-bwrap

Conversation

@kain88-de

Copy link
Copy Markdown
Contributor

The podman backend needs a locally built image, and the agent CLI baked into it drifts behind the host's until someone rebuilds. Claude Code and Codex CLI sandbox with bubblewrap over the host's own filesystem instead, which removes the image entirely.

backend = "bwrap" mirrors the podman layout (/workspace, /opt/scripts, /home/sandbox) so workflows work under either backend. The sandbox root starts empty and only gets the host's /usr and /etc read-only; that hides $HOME and the sockets under /run/user (D-Bus session bus, keyring, ssh-agent), which a Landlock-only approach would have left reachable. The step's program is resolved on the host PATH and its directory mounted read-only, so agents installed outside /usr (~/.local, linuxbrew) run at the host's version.

Host /opt stays hidden: it is read-only, so bwrap could not create the /opt/scripts mount point inside it.

@kain88-de
kain88-de requested review from cellador and a balanced review from Copilot November 24, 2026 20: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.

🟡 Changes recommended

Unconditionally mounting an executable’s parent directory can expose home-directory credentials inside the sandbox, violating the backend’s isolation guarantee.

7 open issues
What changed in this PR

Adds an experimental Bubblewrap sandbox backend that runs host-installed tools without a container image, while retaining Podman as the default and matching its workflow directory layout.

Changes:

  • Adds backend selection to workflow configuration and sandbox command construction.
  • Implements Bubblewrap isolation, mounts, networking, and host executable resolution.
  • Documents the experimental backend and adds configuration, command-generation, and sandbox tests.
File Description
USAGE.md Documents backend selection, behavior, requirements, and limitations.
crates/​otter-core/​src/​types.rs Adds the backend configuration enum and parsing tests.
crates/​otter-core/​src/​sandbox.rs Passes workflow backend selection into sandbox configuration.
crates/​otter-core/​src/​process.rs Resolves and exposes host executables for Bubblewrap.
crates/​agentbox/​src/​main.rs Keeps the standalone CLI explicitly configured for Podman.
crates/​agentbox/​src/​lib.rs Adds Bubblewrap command construction and isolation tests.

Review effort: Balanced

Comment thread crates/otter-core/src/process.rs Resolved
Comment thread crates/agentbox/src/lib.rs Resolved
Comment thread crates/otter-core/src/process.rs Resolved
Comment thread crates/otter-core/src/process.rs Resolved
Comment thread crates/otter-core/src/process.rs Resolved
Comment thread crates/otter-core/src/process.rs Resolved
Comment thread crates/otter-core/src/process.rs Resolved

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 Bwrap TTY configuration permits host-shell command injection on systems allowing TIOCSTI, while executable mounting also mishandles hidden symlink chains and relative PATH entries.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Resolve relative PATH entries against the step working directory

crates/​otter-core/​src/​process.rs:218

Relative or empty entries in the login PATH are resolved against the service's current directory here, not the step's working directory. With PATH="." and a tool in both directories, this can expose and run the service directory's tool instead of the workspace's tool. Pass the step's working directory into this helper and resolve relative PATH entries against it before checking executability and constructing the mount.

Low severity Document writable Claude home mounts as a sandbox exception

USAGE.md:476

This isolation description omits writable host-home mounts: for Claude agent steps, resolve_sandbox_config automatically mounts ~/.claude and ~/.claude.json into /home/sandbox. Those files contain authentication, configuration and session data that the sandboxed agent can read and modify. Document this exception so users do not mistake the fresh home directory for isolation of their Claude data.

7 resolved since last review

Review effort: Balanced

Comment thread crates/agentbox/src/lib.rs Resolved
Comment thread crates/otter-core/src/process.rs Resolved

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

Active issues can break symlinked CLIs by relocating them away from adjacent dependencies and disable DNS when resolver symlink chains include hidden aliases.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Resolver mount omits intermediate aliases used by resolv.conf

crates/​agentbox/​src/​lib.rs:103

Mounting only the canonical resolver target leaves /etc/resolv.conf dangling when it points through a hidden alias, such as /var/run/NetworkManager/resolv.conf with /var/run -> /run. Only /run/NetworkManager/resolv.conf is mounted in that case, so DNS fails with the default bridge networking. Preserve the path that /etc/resolv.conf follows, including intermediate aliases, and add a regression test for this layout.

2 resolved since last review

Review effort: Balanced

Comment thread crates/otter-core/src/process.rs Outdated
Comment on lines +227 to +228
let destination = if invocation != resolved {
Path::new("/opt/otter/bin").join(invocation.file_name().unwrap())

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 to weigh an unpublished documentation concern about a workaround unavailable to bwrap workflow users.

1 open issue

Review effort: Balanced

@cellador cellador left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested this locally and works as expected. Nice work. A few nits inline, mainly an idea about the cpu_quota combination.

Could you squash the fix(bwrap)/test(bwrap) follow-ups into e641b19 though? Or into a few logical commits, before merging? Most of them fix things introduced earlier in this same PR, and the two merge commits don't need to land on main either.

let mut sandbox = sandbox.clone();
sandbox.env_vars.extend(secrets.iter().cloned());
let wrapped = agentbox::wrap_command(cmd_args, &sandbox);
let cmd_args = if sandbox.backend == agentbox::Backend::Bwrap {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just and idea which I like, but not blocking as it's listed in the experimental section.

Claude:

With backend = "bwrap" and a cpu_quota, agent steps arrive here already wrapped as systemd-run --scope --user … -- claude …, because the agent runners (e.g. agent_runner/claude.rs) apply the limiter regardless of the sandbox. expose_host_binary then only exposes systemd-run, and the step fails with Failed to find executable claude. Even if claude were found, systemd-run --user couldn't reach the user bus, since /run/user is hidden.

Since bwrap runs as a direct child of the daemon, unlike Podman, could we apply the limiter around bwrap itself, here? Then cpu_quota would just work for shell and agent steps.

));
}

let backend = match wf.backend {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude:

Related: for bwrap, the cpus computed above is never used, and steps/shell.rs skips the limiter for any sandbox, so shell steps silently lose the quota. My step with cpu_quota = "50%" saw all 8 cores and ran in cgroup 0::/, and nothing was logged. If we don't wire it up in this PR, I'd rather warn, or reject the combination at load time, than have the docs be the only place this shows up.

]);
}

args.push("--clearenv".into());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bit of a nit since Podman's -e already does the same, but --setenv NAME value puts the requires secrets into bwrap's argv, where any local user can read them via ps. With bwrap we don't have to: bwrap passes its own environment through to the sandboxed process. So we could drop --clearenv/--setenv and build the exact sandbox env on the bwrap process in build_subprocess_command instead.

The podman backend needs a locally built image, and the agent CLI baked
into it drifts behind the host's until someone rebuilds. Claude Code and
Codex CLI sandbox with bubblewrap over the host's own filesystem
instead, which removes the image entirely.

`backend = "bwrap"` mirrors the podman layout (/workspace, /opt/scripts,
/home/sandbox) so workflows work under either backend. The sandbox root
starts empty and only gets the host's /usr and /etc read-only; that
hides $HOME and the sockets under /run/user (D-Bus session bus, keyring,
ssh-agent), which a Landlock-only approach would have left reachable.

The step's program is resolved on the host PATH and only its executable
file is mounted, not its directory, so a tool in ~/.local/bin does not
expose its neighbours. Resolution has to hold up against what PATH
lookups meet in practice: relative entries and commands (resolved from
the workspace), non-executable candidates, and symlink chains through
hidden directories, while keeping the invocation name tools like
busybox dispatch on. Absolute commands are validated before any host
path is exposed. /etc/resolv.conf is often a symlink into /run, which
the sandbox replaces with tmpfs, so the real resolver file is mounted
explicitly. The controlling terminal is always detached, so a sandboxed
step cannot inject input into the user's terminal.

Host /opt stays hidden: it is read-only, so bwrap could not create the
/opt/scripts mount point inside it.
Tests write their mock scripts from the test process while parallel
tests spawn subprocesses. A subprocess forked in that window inherits
the open write handle until it execs, and executing the script then
fails with ETXTBSY. Letting a child process write the file means the
test process never holds a write handle that a fork could inherit.

The sync_all that was there could not prevent this; durability was
never the problem.
Trying the bwrap backend means installing both otter and agentbox from
this checkout, and agentbox is not part of the releases. One command
does both with the locked dependencies.

It also restarts a running service. Otherwise the service keeps running
the replaced binary, so the CLI and the service silently run different
versions and `otter status` reports the old service's stale update check.
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.

3 participants