Skip to content

feat(claude): config-level allowRootSandbox opt-in so operators don't need to patch claude.ts for root-launched sessions #2714

Description

@rrmlima

Area

CLI; Platform (Linux); Service lifecycle.

What are you trying to accomplish?

I need to run ocx claude --dangerously-skip-permissions in a root-owned VPS/container deployment without patching src/cli/claude.ts after every OpenCodex upgrade, while preserving OpenCodex's current fail-closed behavior for all operators who do not explicitly opt in.

Claude Code 2.1.205+ exits when all of these are true:

  • process UID is 0;
  • bypass permissions was explicitly requested;
  • IS_SANDBOX != 1;
  • no recognized external sandbox marker is present.

What prevents this today?

Issue #1688 accurately diagnosed the workflow. The upstream resolution intentionally refused to set IS_SANDBOX=1 automatically because UID 0 is not proof of isolation. That is the correct safe default, but root-only deployments have no supported operator-level override in OpenCodex.

The only working local workaround is this source patch in buildClaudeEnv():

if (typeof process.getuid === "function" && process.getuid() === 0) {
  setDefault("IS_SANDBOX", "1");
}

It has been validated across OpenCodex updates, but it leaves the installed package different from the official npm tarball and must be reapplied after upgrades.

What should OpenCodex do?

Expose a deliberately named, default-false config option for operators who explicitly accept this risk, for example:

{
  "claudeCode": {
    "allowRootSandbox": true
  }
}

When and only when all conditions are met:

  1. the config flag is true;
  2. process.getuid() === 0;
  3. the launch explicitly includes --dangerously-skip-permissions;

OpenCodex should call setDefault("IS_SANDBOX", "1") for the child environment and emit a concise warning. An explicitly exported IS_SANDBOX=0 must continue to win. Ordinary Claude launches must remain unchanged.

This preserves the secure default from #1688 while giving VPS/container operators an auditable, supported opt-in instead of requiring an out-of-tree patch.

Example usage or interface

{
  "claudeCode": {
    "allowRootSandbox": true
  }
}
# Explicit operator opt-in + explicit dangerous CLI flag
ocx claude --dangerously-skip-permissions --print "reply OK"

# Expected warning
# OpenCodex: root sandbox override enabled by claudeCode.allowRootSandbox

Expected guards:

# Default config: still fail closed
ocx claude --dangerously-skip-permissions

# Explicit user opt-out wins even when config is true
IS_SANDBOX=0 ocx claude --dangerously-skip-permissions

# Ordinary launch: no override injected
ocx claude --print "reply OK"

Alternatives or workarounds

  • Patch src/cli/claude.ts after every npm update: works but creates permanent package drift.
  • Export IS_SANDBOX=1 manually: not centrally auditable and easy to apply too broadly.
  • Run OpenCodex as a non-root user: preferable where possible, but not always available in existing root-owned VPS/container deployments.
  • Create/verify a real OS sandbox: strongest design, but significantly larger in scope; the proposed flag remains an explicit risk acceptance, not a claim that UID 0 is isolated.

Additional context

Checks

  • I searched existing issues and documentation.
  • This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
  • I removed secrets and personal data.

Activity

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

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions