Skip to content

Restricted Linux sandbox breaks connected Unix socket sends and asyncio wakeups #33793

Open

Description

@everySympathy

Summary

The restricted Linux network seccomp filter unconditionally denies sendto(2). On Linux, send(2) is implemented as sendto(..., dest_addr = NULL), so this also breaks writes to already-connected Unix-domain sockets.

One visible consequence is that Python asyncio cross-thread wakeups stop working inside the default Codex workspace sandbox. loop.call_soon_threadsafe() writes to asyncio's AF_UNIX wakeup socket; the write receives EPERM, asyncio suppresses that OSError, and the event loop remains asleep.

Reproduction

On current main (315195492c), build Codex and run:

./target/debug/codex sandbox -P :workspace -C /tmp /usr/bin/python3 -c 'import asyncio, threading; loop=asyncio.new_event_loop(); threading.Thread(target=loop.run_forever, daemon=True).start(); print(asyncio.run_coroutine_threadsafe(asyncio.sleep(0, result=42), loop).result(timeout=2))'

Expected:

42

Actual:

TimeoutError

This also causes Daft's native runner to hang on a simple collect() operation.

Isolation

  • The same program succeeds outside the Codex sandbox.
  • It succeeds with the same bubblewrap filesystem isolation and a full-network Codex profile.
  • It succeeds with plain bubblewrap plus --unshare-net.
  • It fails only when Codex's restricted network seccomp filter is installed.

Root cause and possible fix

In codex-rs/linux-sandbox/src/landlock.rs, restricted mode unconditionally denies SYS_sendto.

A narrowly scoped fix is to deny sendto only when its fifth argument (dest_addr) is non-null. This permits send() on an already-connected socket, including AF_UNIX socketpairs used for local IPC, while continuing to deny sends to explicit destinations such as unconnected Unix datagram socket paths.

I have a tested patch with regression coverage for both sides of this boundary:

  • connected AF_UNIX socket send() succeeds;
  • sendto() with an explicit destination still returns EPERM.

The codex-linux-sandbox test suite passes (120/120), and both the minimal asyncio reproducer and the original Daft collect() scenario pass with the patched binary.

Activity

  1. added
    bug
    CLI
    sandbox
    on Jul 17, 2026
  2. everySympathy commented on Jul 17, 2026

    @everySympathy
    Author

    A tested patch is available here:

    I attempted to open a draft PR against openai/codex:main, but GitHub rejected both the GraphQL and REST creation paths for this external account:

    GraphQL: everySympathy does not have the correct permissions to execute CreatePullRequest
    

    The branch is ready if a maintainer would like to invite the contribution or pull the commit directly.

  3. Artem-B commented on Aug 30, 2026

    @Artem-B

    Additional reproduction through Bun subprocess stdin

    I hit the same SYS_sendto denial through Bun's subprocess API. This affects tools that pass input to child processes, not only Python asyncio.

    Environment

    • Codex CLI: 0.151.0
    • Bun: 1.3.6
    • OS: WSL2, Linux 6.6.114.1-microsoft-standard-WSL2, x86_64
    • Sandbox: managed workspace-write profile with restricted network access

    Inside the sandbox, /proc/self/status reports:

    NoNewPrivs:      1
    Seccomp:         2
    Seccomp_filters: 1
    

    Use case

    The failure occurred while configuring open-pstack. Its external model runner uses Bun to start Claude Code in print mode and send the prompt through stdin:

    const child = Bun.spawn([executable, ...args], {
      stdin: "pipe",
      stdout: "pipe",
      stderr: "pipe",
    });
    
    child.stdin.write(prompt);
    await child.stdin.end();

    Bun represents this stdin connection as a FileSink. The flush performed by FileSink.end() uses send(), which Linux implements as:

    sendto(fd, buffer, length, flags, NULL, 0)

    Codex rejects the call with EPERM. Claude receives EOF without any prompt bytes and exits with:

    Input must be provided either through stdin or as a prompt argument when using --print
    

    The original runner did not await stdin.end(), so it hid the EPERM rejection. Awaiting it reports the sandbox failure but cannot make the write succeed.

    Minimal Bun reproduction

    Save this as repro.ts:

    const child = Bun.spawn(
      [
        "/bin/sh",
        "-c",
        'IFS= read -r line; printf "child read: %s\\n" "$line"',
      ],
      {
        stdin: "pipe",
        stdout: "pipe",
        stderr: "pipe",
      },
    );
    
    const written = child.stdin.write("BUN_PIPE_TEST\n");
    console.log("write returned:", written);
    
    try {
      await child.stdin.end();
      console.log("stdin.end succeeded");
    } catch (error) {
      console.error("stdin.end failed:", error);
    }
    
    const exitCode = await child.exited;
    const stdout = await new Response(child.stdout).text();
    const stderr = await new Response(child.stderr).text();
    
    console.log("exit code:", exitCode);
    console.log("stdout:", JSON.stringify(stdout));
    console.log("stderr:", JSON.stringify(stderr));

    Run it from a Codex shell under the restricted Linux sandbox:

    bun repro.ts

    Actual result:

    write returned: 14
    stdin.end failed: EPERM: operation not permitted, send
    exit code: 0
    stdout: "child read: \n"
    stderr: ""
    

    Run the same command in a normal terminal or with danger-full-access.

    Expected result:

    write returned: 14
    stdin.end succeeded
    exit code: 0
    stdout: "child read: BUN_PIPE_TEST\n"
    stderr: ""
    

    A direct syscall control produces the same result:

    python3 -c 'import socket; a,b=socket.socketpair(); print(a.send(b"x"))'

    Inside the restricted sandbox:

    PermissionError: [Errno 1] Operation not permitted
    

    Outside the sandbox:

    1
    

    Isolation and workaround

    Both of these alternatives work inside the same restricted sandbox:

    • Writing with write(2) instead of send(2).
    • Supplying the complete input to Bun at spawn time:
    const child = Bun.spawn([executable, ...args], {
      stdin: new Blob([prompt]),
      stdout: "pipe",
      stderr: "pipe",
    });

    Node's child_process stdin pipe also works because it uses the ordinary pipe and write(2) path.

    This supports the fix proposed in this issue: permit sendto when dest_addr == NULL and addrlen == 0. That keeps explicit-destination sendto() calls blocked while restoring connected Unix-socket writes used by Bun, Python asyncio,
    and other local IPC implementations.

  4. GustavoDRL commented on Sep 9, 2026

    @GustavoDRL

    Codex Linux sandbox: AF_UNIX regression confirmation

    Upstream issues: #33793 and #24933

    Environment

    • Codex CLI: 0.153.4
    • OS: Arch Linux / Omarchy
    • Kernel: 7.1.9-arch1-2 x86_64
    • Python: CPython 3.13.15
    • Sandbox: managed workspace-write, network restricted

    Actual result inside the sandbox

    socket.socketpair(AF_UNIX, SOCK_STREAM) succeeds, but send() on the
    connected socket returns PermissionError: [Errno 1] Operation not permitted.
    Consequently, asyncio.to_thread() cannot wake the selector during executor
    shutdown and asyncio.run() hangs in epoll_wait.

    A real pytest invocation hit the same path twice:

    tests/test_briefing.py::TestNadaInterrompePorRotina::test_dia_tranquilo_nao_pede_nada

    Both hung processes were eventually aborted and recorded by systemd-coredump as
    SIGABRT. Their main thread was in epoll_wait; the executor worker was parked
    in concurrent.futures.thread._worker.

    Control result outside the sandbox

    • Minimal asyncio.to_thread(lambda: 42): returns 42 immediately.
    • Original affected pytest: 1 passed in 0.10s.
    • Entire tests/test_briefing.py: 29 passed in 0.59s.
    • No new coredump was created.

    Expected boundary

    Allow sendto(..., dest_addr = NULL) for already-connected sockets, including
    AF_UNIX socketpairs, while continuing to reject sendto() with an explicit
    destination. This preserves external-network isolation while restoring local
    IPC and asyncio cross-thread wakeups.

    Reproducer

    Run codex-sandbox-af-unix-regression.py inside and outside the restricted
    Linux sandbox. It must finish in under two seconds and print PASS.

  5. benmccann commented on Sep 20, 2026

    @benmccann

    @etraut-openai would you be able to land everySympathy@582a47d ? Codex is constantly hitting sandbox issues when coding in Python today

  6. pershin-daniil commented on Nov 2, 2026

    @pershin-daniil

    Additional affected program: rustup --version aborts in wait-timeout

    Confirmed on 2026-11-02. This is another consequence of the connected Unix-socket send restriction: a read-only Rust toolchain version check aborts with SIGABRT, rather than hanging.

    Environment

    • Codex CLI: 0.166.0 (codex --version on the affected machine)
    • OS: Arch Linux / Omarchy, x86_64
    • Kernel: 7.2.8-9-omarchy
    • glibc: 2.44+r50+g1848099f063e-1
    • Sandbox: managed workspace-write, restricted network
    • rustup: 1.29.2 (d8c92c676 2026-10-21)
    • Active rustc: 1.99.1 (58cf8f9c3 2026-10-13)
    • Dependency identified in the panic: wait-timeout 0.2.1

    Affected command and original stderr

    The command was run by Codex's shell tool inside the restricted sandbox, with an installed default stable toolchain:

    "$HOME/.cargo/bin/rustup" --version

    Relevant excerpt from the captured output:

    rustup 1.29.2 (d8c92c676 2026-10-21)
    info: This is the version for the rustup toolchain manager, not the rustc compiler.
    
    thread 'main' (49) panicked at /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wait-timeout-0.2.1/src/unix.rs:233:17:
    bad error on write fd: Operation not permitted (os error 1)
    
    thread 'main' (49) panicked at /rustc/58cf8f9c35b355199727627d07ae34a4e2846d67/library/core/src/panicking.rs:225:5:
    panic in a function that cannot unwind
    
    thread caused non-unwinding panic. aborting.
    

    Python subprocess.run() recorded return code -6.

    systemd-coredump metadata and GDB backtrace excerpt

    Selected metadata (home path normalized):

    Timestamp:    2026-11-02 19:17:01 +03:00
    PID:          16634
    Command Line: $HOME/.cargo/bin/rustup --version
    Signal:       6 (ABRT), si_code: SI_TKILL
    NSpid:        16634 49
    NoNewPrivs:   1
    Seccomp:      2
    Seccomp_filters: 1
    VmRSS:        16036 kB
    Threads:      9
    

    GDB backtrace excerpt; addresses omitted:

    #0  ?? () from /usr/lib/libc.so.6
    #1  raise () from /usr/lib/libc.so.6
    #2  abort () from /usr/lib/libc.so.6
    #3  std::sys::pal::unix::abort_internal ()
    #4  std::process::abort ()
    #5  std::panicking::panic_with_hook ()
    #6  std::panicking::panic_handler::{closure#0} ()
    #7  std::sys::backtrace::__rust_end_short_backtrace::<std::panicking::panic_handler::{closure#0}, !> ()
    #8  __rustc::rust_begin_unwind ()
    #9  core::panicking::panic_nounwind_fmt ()
    #10 core::panicking::panic_nounwind ()
    #11 core::panicking::panic_cannot_unwind ()
    #12 wait_timeout::imp::sigchld_handler ()
    #13 <signal handler called>
    #14 ?? () from /usr/lib/libc.so.6
    #15 poll () from /usr/lib/libc.so.6
    #16 <rustup::toolchain::Toolchain>::rustc_version ()
    #17 rustup::cli::rustup_mode::main::{closure#0}::{closure#0} ()
    

    The other eight threads were parked in Tokio worker / I/O waits. No OOM event was found in the kernel journal around the crash. Some libc frames lack debug symbols.

    Control outside the sandbox

    The same binary and command were rerun with per-command require_escalated at 19:17:42 +03:00, without changing the Rust installation:

    rustup 1.29.2 (d8c92c676 2026-10-21)
    info: This is the version for the rustup toolchain manager, not the rustc compiler.
    info: the currently active `rustc` version is `rustc 1.99.1 (58cf8f9c3 2026-10-13)`
    

    Exit code: 0.

    Independent local-IPC check inside the restricted sandbox

    import socket, os
    
    for name in ('send', 'write'):
        a, b = socket.socketpair()
        try:
            n = a.send(b'x') if name == 'send' else os.write(a.fileno(), b'x')
            print(f'AF_UNIX socketpair {name}: OK ({n} byte)')
        except OSError as e:
            print(f'AF_UNIX socketpair {name}: errno={e.errno} {e.strerror}')
        finally:
            a.close()
            b.close()

    Observed output:

    AF_UNIX socketpair send: errno=1 Operation not permitted
    AF_UNIX socketpair write: OK (1 byte)
    

    This matches the restriction described in this issue. The Rust-specific failure is that wait-timeout panics on the denied notification write inside its SIGCHLD handler; the non-unwinding panic then aborts the process. No syscall trace of the original rustup process was captured; the evidence here is its stderr, core backtrace, sandbox metadata, outside-sandbox control, and independent socket test.

    Only relevant, sanitized log excerpts are included; no raw core dump or environment dump is attached.

    Prepared by GPT-6 via Codex; posted at the user's request.

  7. rkboot7850-bit commented on Nov 30, 2026

    @rkboot7850-bit

    We observed a related local IPC compatibility problem on Codex CLI 0.169.0, Linux x86_64, kernel 7.0.0-44-generic, workspace-write with restricted networking. In our existing Python transport tests, creation of a process-owned AF_UNIX SOCK_SEQPACKET socketpair succeeds, but sending a packet returns EPERM. Socket type validation with getsockopt(SOL_SOCKET, SO_TYPE) also appears to fail before peer credential validation (SO_PEERCRED). We did not obtain an exact syscall trace, so the attribution of the latter failure is not conclusive. The command child reports NoNewPrivs=1, Seccomp=2, Seccomp_filters=1.

    Reviewing the exact rust-v0.169.0 and rust-v0.172.0 tagged Linux seccomp source, the Restricted branch denies sendto, getsockopt and setsockopt. Related reports: #39140, #47452, #57231.

    Could maintainers confirm whether there is an officially supported Linux local-IPC permission profile or release that supports these operations for authenticated local Unix-domain communication while preserving filesystem isolation and external-network denial? In particular, does any supported profile cover process-owned socketpairs and pathname-bound AF_UNIX SOCK_SEQPACKET endpoints with kernel peer-credential checks? We would appreciate the supported version/configuration, applicable security guarantees, and recommended acceptance procedure. We are not requesting disabling the sandbox or broadly enabling networking.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIbugsandbox

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions