CODEX_UNSAFE_ALLOW_NO_SANDBOX should move up a little bit

Resolved 💬 1 comment Opened May 26, 2025 by doggy8088 Closed Sep 5, 2025

In the codex-cli/src/utils/agent/handle-exec-command.ts, the CODEX_UNSAFE_ALLOW_NO_SANDBOX condition might need to rearrange:

https://github.com/openai/codex/blob/6b5b184f21504c99eeeee56b9d607eb8576f96db/codex-cli/src/utils/agent/handle-exec-command.ts#L294-L328

The suggested adjustments are:

async function getSandbox(runInSandbox: boolean): Promise<SandboxType> {
  if (runInSandbox) {
    if (CODEX_UNSAFE_ALLOW_NO_SANDBOX) {
      // Allow running without a sandbox if the user has explicitly marked the
      // environment as already being sufficiently locked-down.
      return SandboxType.NONE;
    } else if (process.platform === "darwin") {
      // On macOS we rely on the system-provided `sandbox-exec` binary to
      // enforce the Seatbelt profile.  However, starting with macOS 14 the
      // executable may be removed from the default installation or the user
      // might be running the CLI on a stripped-down environment (for
      // instance, inside certain CI images).  Attempting to spawn a missing
      // binary makes Node.js throw an *uncaught* `ENOENT` error further down
      // the stack which crashes the whole CLI.
      if (await isSandboxExecAvailable) {
        return SandboxType.MACOS_SEATBELT;
      } else {
        throw new Error(
          "Sandbox was mandated, but 'sandbox-exec' was not found in PATH!",
        );
      }
    } else if (process.platform === "linux") {
      // TODO: Need to verify that the Landlock sandbox is working. For example,
      // using Landlock in a Linux Docker container from a macOS host may not
      // work.
      return SandboxType.LINUX_LANDLOCK;
    }

    // For all else, we hard fail if the user has requested a sandbox and none is available.
    throw new Error("Sandbox was mandated, but no sandbox is available!");
  } else {
    return SandboxType.NONE;
  }
}

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗