openai/codex · error

failed to redirect stderr for bubblewrap

Error message

failed to redirect stderr for bubblewrap: {err}

What it means

Redirecting the child's stderr to the capture pipe via dup2 failed in the bwrap preflight child. This panic in run_bwrap_in_child_capture_stderr fires when dup2(write_fd, STDERR_FILENO) returns negative — fd exhaustion or an invalid descriptor — so the child cannot route bubblewrap's stderr into the pipe and aborts before exec.

Solutions

  1. Check the errno in the message (EMFILE/EBADF are common)
  2. Raise fd limits with `ulimit -n` if descriptors are exhausted
  3. Verify the pipe fds were not closed prematurely in the child path
  4. Retry the sandboxed command if the failure looks transient
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at codex-rs/linux-sandbox/src/linux_run_main.rs:1448 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/bff0fc36eff4e97c. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/linux-sandbox/src/linux_run_main.rs:1448

    }
    let read_fd = pipe_fds[0];
    let write_fd = pipe_fds[1];

    let pid = unsafe { libc::fork() };
    if pid < 0 {
        let err = std::io::Error::last_os_error();
        panic!("failed to fork for bubblewrap: {err}");
    }

    if pid == 0 {
        reset_forwarded_signal_handlers_to_default();
        setup_signal_mask.restore();
        // Child: redirect stderr to the pipe, then run bubblewrap.
        unsafe {
            close_fd_or_panic(read_fd, "close read end in bubblewrap child");
            if libc::dup2(write_fd, libc::STDERR_FILENO) < 0 {
                let err = std::io::Error::last_os_error();
                panic!("failed to redirect stderr for bubblewrap: {err}");
            }
            close_fd_or_panic(write_fd, "close write end in bubblewrap child");
        }

        exec_bwrap(args, preserved_files);
    }

    let signal_forwarders = install_bwrap_signal_forwarders(pid);
    setup_signal_mask.restore();
    // Parent: close the write end and read stderr while the child runs.
    close_fd_or_panic(write_fd, "close write end in bubblewrap parent");

    // SAFETY: `read_fd` is a valid owned fd in the parent.
    let mut read_file = unsafe { File::from_raw_fd(read_fd) };
    let mut stderr_bytes = Vec::new();
    let mut limited_reader = (&mut read_file).take(MAX_PREFLIGHT_STDERR_BYTES);
    if let Err(err) = limited_reader.read_to_end(&mut stderr_bytes) {
        panic!("failed to read bubblewrap stderr: {err}");

View on GitHub (pinned to 339751715c)