From c63929af50518ca638ccad12f2805298cb7f25a1 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Fri, 9 Oct 2026 15:19:38 +0000 Subject: [PATCH] Align Linux sandbox names and docs with bubblewrap and seccomp (#52610) ## Why The Linux sandbox uses bubblewrap for filesystem isolation and seccomp for syscall filtering, but its command type, syscall-filter module, and integration test suite still used Landlock names. ## What changed - Rename `LandlockCommand` to `LinuxSandboxCommand`, `src/landlock.rs` to `src/seccomp.rs`, and `tests/suite/landlock.rs` to `tests/suite/sandbox.rs`, updating imports and existing tests. - Clarify the retained legacy Landlock implementation and its filesystem-policy limitations. - Update the README to describe existing network filtering, `AF_VSOCK` and `io_uring` restrictions, and managed-proxy Unix socket behavior, including allowed Unix socket pairs. Sandbox enforcement behavior is unchanged. GitOrigin-RevId: be4769d5a10b90605990eb58451e83fdf1c31222 --- codex-rs/linux-sandbox/README.md | 17 ++++++++++++++--- codex-rs/linux-sandbox/src/lib.rs | 4 ++-- codex-rs/linux-sandbox/src/linux_run_main.rs | 14 ++++++-------- .../linux-sandbox/src/linux_run_main_tests.rs | 8 ++++---- .../src/{landlock.rs => seccomp.rs} | 10 ++++++---- codex-rs/linux-sandbox/tests/suite/mod.rs | 2 +- .../tests/suite/{landlock.rs => sandbox.rs} | 2 ++ 7 files changed, 35 insertions(+), 22 deletions(-) rename codex-rs/linux-sandbox/src/{landlock.rs => seccomp.rs} (96%) rename codex-rs/linux-sandbox/tests/suite/{landlock.rs => sandbox.rs} (99%) diff --git a/codex-rs/linux-sandbox/README.md b/codex-rs/linux-sandbox/README.md index 95865ded74..b118931623 100644 --- a/codex-rs/linux-sandbox/README.md +++ b/codex-rs/linux-sandbox/README.md @@ -7,6 +7,12 @@ This crate is responsible for producing: - the `codex-exec` CLI can check if its arg0 is `codex-linux-sandbox` and, if so, execute as if it were `codex-linux-sandbox` - this should also be true of the `codex` multitool CLI +The helper uses bubblewrap for filesystem and namespace isolation, and seccomp +for syscall filtering. `src/seccomp.rs` installs `PR_SET_NO_NEW_PRIVS` and the +seccomp filters; it also retains the legacy Landlock filesystem implementation. +`src/linux_run_main.rs` coordinates these stages through `LinuxSandboxCommand`. +End-to-end coverage lives in `tests/suite/sandbox.rs` and the other suite modules. + On Linux, Codex prefers the first `bwrap` found on `PATH` outside the current working directory whenever it is available. If `bwrap` is present but too old to support @@ -45,7 +51,10 @@ commands that would enter the bubblewrap path. `SandboxPolicy` model stay on bubblewrap so nested read-only or denied carveouts are preserved. - When bubblewrap is active, the helper applies `PR_SET_NO_NEW_PRIVS` and a - seccomp network filter in-process. + seccomp filter in-process after establishing the filesystem view. Restricted + network policies block network syscalls; filesystem-restricted policies with + otherwise unrestricted networking still block `AF_VSOCK` sockets. All filter + modes block `io_uring` to prevent bypassing socket-family restrictions. - When bubblewrap is active, the filesystem is read-only by default via `--ro-bind / /`. - When bubblewrap is active, writable roots are layered with `--bind `. - When bubblewrap is active, protected subpaths under writable roots (for @@ -86,8 +95,10 @@ commands that would enter the bubblewrap path. - In managed proxy mode, the helper uses `--unshare-net` plus an internal TCP->UDS->TCP routing bridge so tool traffic reaches only configured proxy endpoints. -- In managed proxy mode, after the bridge is live, seccomp blocks new - AF_UNIX/socketpair creation for the user command. +- In managed proxy mode, after the bridge is live, seccomp allows IP sockets + inside the isolated network namespace and blocks new standalone `AF_UNIX` + sockets unless `dangerously_allow_all_unix_sockets` is granted. Unix socket + pairs remain allowed for communication between related processes. - When bubblewrap is active, it mounts a fresh `/proc` via `--proc /proc` by default. If that mount is denied, it retains the inherited `/proc` and still creates a PID namespace, preserving the existing fallback. `--no-proc` also retains the diff --git a/codex-rs/linux-sandbox/src/lib.rs b/codex-rs/linux-sandbox/src/lib.rs index 549527de21..fa75c702b2 100644 --- a/codex-rs/linux-sandbox/src/lib.rs +++ b/codex-rs/linux-sandbox/src/lib.rs @@ -16,8 +16,6 @@ mod exec_util; #[cfg(target_os = "linux")] mod fd_mount; #[cfg(target_os = "linux")] -mod landlock; -#[cfg(target_os = "linux")] mod launcher; #[cfg(target_os = "linux")] mod linux_run_main; @@ -26,6 +24,8 @@ mod proxy_lifecycle; #[cfg(target_os = "linux")] mod proxy_routing; #[cfg(target_os = "linux")] +mod seccomp; +#[cfg(target_os = "linux")] mod wslg; #[cfg(target_os = "linux")] diff --git a/codex-rs/linux-sandbox/src/linux_run_main.rs b/codex-rs/linux-sandbox/src/linux_run_main.rs index 5c08c8c39a..85bb0aaa80 100644 --- a/codex-rs/linux-sandbox/src/linux_run_main.rs +++ b/codex-rs/linux-sandbox/src/linux_run_main.rs @@ -25,12 +25,12 @@ use crate::bwrap::BwrapOptions; use crate::bwrap::WSL_INTEROP_DIR; use crate::bwrap::WSLG_DISTRO_ROOT; use crate::bwrap::create_bwrap_command_args; -use crate::landlock::apply_permission_profile_to_current_thread; use crate::launcher::exec_bwrap; use crate::launcher::initialize_bwrap_launcher; use crate::launcher::preferred_bwrap_supports_argv0; use crate::proxy_routing::activate_proxy_routes_in_netns; use crate::proxy_routing::prepare_host_proxy_route_spec; +use crate::seccomp::apply_permission_profile_to_current_thread; use codex_network_proxy::ManagedNetworkSandboxContext; use codex_protocol::error::Result as CodexResult; use codex_protocol::models::PermissionProfile; @@ -86,10 +86,8 @@ enum ProtectedCreateRemoval { #[derive(Debug, Parser)] /// CLI surface for the Linux sandbox helper. /// -/// The type name remains `LandlockCommand` for compatibility with existing -/// wiring, but bubblewrap is now the default filesystem sandbox and Landlock -/// is the legacy fallback. -pub struct LandlockCommand { +/// Uses bubblewrap for filesystem isolation and seccomp for syscall filtering. +pub struct LinuxSandboxCommand { /// It is possible that the cwd used in the context of the sandbox policy /// is different from the cwd of the process to spawn. #[arg(long = "sandbox-policy-cwd")] @@ -166,7 +164,7 @@ pub struct LandlockCommand { /// 2. Apply in-process restrictions (no_new_privs + seccomp). /// 3. `execvp` into the final command. pub fn run_main() -> ! { - let LandlockCommand { + let LinuxSandboxCommand { sandbox_policy_cwd, command_cwd, permission_profile, @@ -178,7 +176,7 @@ pub fn run_main() -> ! { no_proc, inherit_pid_namespace, command, - } = LandlockCommand::parse(); + } = LinuxSandboxCommand::parse(); let allow_network_for_proxy = managed_network.is_some(); if command.is_empty() { @@ -348,7 +346,7 @@ pub fn run_main() -> ! { ); } - // Legacy path: Landlock enforcement only, when bwrap sandboxing is not enabled. + // Legacy pipeline: apply in-process restrictions without bubblewrap. if let Err(e) = apply_permission_profile_to_current_thread( &permission_profile, &sandbox_policy_cwd, diff --git a/codex-rs/linux-sandbox/src/linux_run_main_tests.rs b/codex-rs/linux-sandbox/src/linux_run_main_tests.rs index 79a0dca040..3d47173014 100644 --- a/codex-rs/linux-sandbox/src/linux_run_main_tests.rs +++ b/codex-rs/linux-sandbox/src/linux_run_main_tests.rs @@ -587,7 +587,7 @@ fn managed_proxy_inner_command_includes_route_spec() { assert!(args.iter().any(|arg| arg == "--proxy-route-spec")); assert!(args.iter().any(|arg| arg == "{\"routes\":[]}")); - let parsed = LandlockCommand::try_parse_from(args) + let parsed = LinuxSandboxCommand::try_parse_from(args) .expect("inner command should preserve the managed network policy"); assert_eq!(parsed.managed_network, Some(managed_network)); } @@ -595,7 +595,7 @@ fn managed_proxy_inner_command_includes_route_spec() { #[test] fn managed_network_policy_alone_enables_proxy_mode() { - let parsed = LandlockCommand::try_parse_from([ + let parsed = LinuxSandboxCommand::try_parse_from([ "codex-linux-sandbox", "--sandbox-policy-cwd", "/tmp", @@ -613,7 +613,7 @@ fn managed_network_policy_alone_enables_proxy_mode() { #[test] fn malformed_managed_network_policy_is_rejected() { - let error = LandlockCommand::try_parse_from([ + let error = LinuxSandboxCommand::try_parse_from([ "codex-linux-sandbox", "--sandbox-policy-cwd", "/tmp", @@ -658,7 +658,7 @@ fn non_managed_inner_command_omits_route_spec() { }); assert!(!args.iter().any(|arg| arg == "--proxy-route-spec")); - let parsed = LandlockCommand::try_parse_from(args) + let parsed = LinuxSandboxCommand::try_parse_from(args) .expect("unmanaged inner command should preserve ordinary sandbox mode"); assert_eq!(parsed.managed_network, None); } diff --git a/codex-rs/linux-sandbox/src/landlock.rs b/codex-rs/linux-sandbox/src/seccomp.rs similarity index 96% rename from codex-rs/linux-sandbox/src/landlock.rs rename to codex-rs/linux-sandbox/src/seccomp.rs index 140daaf8af..7aecf5a7a1 100644 --- a/codex-rs/linux-sandbox/src/landlock.rs +++ b/codex-rs/linux-sandbox/src/seccomp.rs @@ -1,7 +1,8 @@ //! In-process Linux sandbox primitives: `no_new_privs` and seccomp. //! //! Filesystem restrictions are enforced by bubblewrap in `linux_run_main`. -//! Landlock helpers remain available here as legacy/backup utilities. +//! The legacy Landlock filesystem implementation is retained here, but the +//! helper rejects legacy mode for filesystem-restricted policies. use std::collections::BTreeMap; use std::path::Path; @@ -39,7 +40,8 @@ use seccompiler::apply_filter; /// - enabling `PR_SET_NO_NEW_PRIVS` when restrictions apply, and /// - installing seccomp restrictions for network isolation and VM sockets. /// -/// Filesystem restrictions are intentionally handled by bubblewrap. +/// Filesystem restrictions are normally handled by bubblewrap. The legacy +/// Landlock implementation is only selected by `apply_landlock_fs`. pub(crate) fn apply_permission_profile_to_current_thread( permission_profile: &PermissionProfile, cwd: &Path, @@ -142,8 +144,8 @@ fn set_no_new_privs() -> Result<()> { /// # Errors /// Returns [`CodexErr::Sandbox`] variants when the ruleset fails to apply. /// -/// Note: this is currently unused because filesystem sandboxing is performed -/// via bubblewrap. It is kept for reference and potential fallback use. +/// Retained for the legacy pipeline. The helper currently rejects legacy mode +/// for filesystem-restricted policies, so filesystem sandboxing uses bubblewrap. fn install_filesystem_landlock_rules_on_current_thread( writable_roots: Vec, ) -> Result<()> { diff --git a/codex-rs/linux-sandbox/tests/suite/mod.rs b/codex-rs/linux-sandbox/tests/suite/mod.rs index 8044edf2ad..31e89b5f0f 100644 --- a/codex-rs/linux-sandbox/tests/suite/mod.rs +++ b/codex-rs/linux-sandbox/tests/suite/mod.rs @@ -1,5 +1,5 @@ // Aggregates all former standalone integration tests as modules. mod bundled_bwrap; mod bwrap_path; -mod landlock; mod managed_proxy; +mod sandbox; diff --git a/codex-rs/linux-sandbox/tests/suite/landlock.rs b/codex-rs/linux-sandbox/tests/suite/sandbox.rs similarity index 99% rename from codex-rs/linux-sandbox/tests/suite/landlock.rs rename to codex-rs/linux-sandbox/tests/suite/sandbox.rs index fa22e7a1e4..e0167df88c 100644 --- a/codex-rs/linux-sandbox/tests/suite/landlock.rs +++ b/codex-rs/linux-sandbox/tests/suite/sandbox.rs @@ -1,3 +1,5 @@ +//! End-to-end Linux sandbox coverage for filesystem isolation and syscall filtering. + #![cfg(target_os = "linux")] #![allow(clippy::unwrap_used)] use codex_core::exec::ExecCapturePolicy;