[bug] workspace-write sandbox blocks GPU access (no /dev/nvidia* in bwrap namespace)

Open 💬 4 comments Opened Apr 26, 2026 by jeanibarz
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

Summary

When running codex exec --sandbox workspace-write (or read-only) on Linux, any subprocess that attempts to use a CUDA GPU fails with RuntimeError: Found no NVIDIA driver on your system. The bubblewrap-based sandbox does not bind-mount /dev/nvidia* or /dev/nvidiactl into the sandbox namespace, so PyTorch / TensorFlow / any GPU-using tool sees no driver.

Reproduction

# Confirm GPU works outside the sandbox
$ python3 -c "import torch; print(torch.cuda.is_available())"
True

# Same command via Codex with workspace-write
$ codex exec --sandbox workspace-write \
    "python3 -c 'import torch; print(torch.cuda.is_available())'"
# Output:
RuntimeError: Found no NVIDIA driver on your system. Please check that you
have an NVIDIA GPU and installed a driver from
http://www.nvidia.com/Download/index.aspx

The full traceback originates from torch.cuda._lazy_init calling torch._C._cuda_init, which fails because /dev/nvidiactl is not accessible in the sandbox namespace.

Environment

  • codex-cli 0.125.0-alpha.3+looper.7dc18d9c4
  • WSL2 (6.6.87.2-microsoft-standard-WSL2) on Windows host
  • NVIDIA RTX 3090, driver 580.x, CUDA 12.4
  • bubblewrap available on PATH

Why this matters

Any agent task that needs to invoke CUDA workloads as a subprocess (training, inference, profiling, ML benchmarks) is blocked unless the user falls back to --sandbox danger-full-access, which removes ALL sandbox protections (network egress, filesystem isolation). This is a poor security trade-off for an otherwise-narrow requirement: the task only needs /dev/nvidia* access, not unrestricted filesystem write or network.

A concrete example: I'm building an autonomous research loop where a Codex agent designs surgery on a transformer model, runs an evaluation harness (which loads the model on GPU), and records results. The sandbox's network and filesystem isolation are exactly what I want — except the harness can't run because the sandbox blocks /dev/nvidiactl.

Suggested fix(es)

In ascending order of effort:

  1. Auto-detect GPU and bind-mount when present. When bubblewrap detects /dev/nvidia* exists on the host, add --dev-bind /dev/nvidia0 /dev/nvidia0 etc. by default in non-read-only modes. Low risk — these device files are present only on systems with NVIDIA drivers, and exposing them doesn't grant network or filesystem-write access.
  1. Add a gpu_passthrough config flag. Extend SandboxPolicy::WorkspaceWrite with a gpu_passthrough: bool field. When true, bind-mount /dev/nvidia* and /dev/nvidiactl. Document the security trade-off (a malicious agent could spin GPU compute, potentially exhausting power or melting silicon, but cannot exfiltrate via network or write outside cwd).
  1. Extend writable_roots to support device files. Allow paths like /dev/nvidia0 in writable_roots. Codex translates these to bubblewrap --dev-bind rather than --bind. Treats it as opt-in.

(1) is friendliest to the common case of "user has GPU, wants Codex to use it"; (2) gives explicit consent; (3) maximally generic.

Workaround in the meantime

--sandbox danger-full-access works but defeats the purpose. I'm using it for now and documenting the limitation in my project's RFC as a blocking prerequisite for moving to production.

Related code paths

  • ~/git/codex/codex-rs/sandboxing/src/bwrap.rs — bwrap invocation
  • ~/git/codex/codex-rs/protocol/src/protocol.rs — SandboxPolicy::WorkspaceWrite definition (writable_roots, network_access, exclude_tmpdir_env_var, exclude_slash_tmp — no GPU/dev option today)

Happy to draft a PR if (1) is the preferred direction.

View original on GitHub ↗

4 Comments

github-actions[bot] contributor · 4 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #19488
  • #18204

Powered by Codex Action

AlimTleuliyev · 2 months ago

@jeanibarz @etraut-openai

Was this fixed?

jeanibarz · 2 months ago

@AlimTleuliyev no, this hasn't been fixed — the issue is still open, there's no PR referencing it, and the sandbox code on main (codex-rs/sandboxing/src/bwrap.rs, codex-rs/core/src/landlock.rs) still has no GPU/device-passthrough handling.

That said, I want to correct my own original report, because the root-cause diagnosis is wrong for the WSL2 environment I filed it under, and anyone implementing the /dev/nvidia* fix as written would ship a no-op on WSL2.

On WSL2, /dev/nvidia* and /dev/nvidiactl don't exist at all. CUDA is exposed via:

  • the /dev/dxg device node, plus
  • driver shims in /usr/lib/wsl/lib/ (libcuda.so.1, libnvidia-ml.so.1, etc.)

So torch.cuda.is_available() == True outside the sandbox works through /dev/dxg + /usr/lib/wsl/lib, never through /dev/nvidiactl. The original "sandbox doesn't bind-mount /dev/nvidia*" framing was copied from native-Linux CUDA setups and doesn't apply here — there's nothing at those paths to bind.

Corrected scope of the bug:

  • Native Linux + NVIDIA driver: bwrap namespace omits /dev/nvidia* / /dev/nvidiactl — the original report.
  • WSL2: bwrap namespace would need to expose /dev/dxg and bind-mount /usr/lib/wsl/lib (and keep /usr/lib/wsl/lib on the loader path) — a different set of paths.

A correct fix should therefore detect the platform's actual GPU surface rather than hard-coding /dev/nvidia*. Suggestion (1) from the original report still holds in spirit — auto-detect and bind the GPU device(s) in non-read-only modes — but the detection has to cover the WSL2 /dev/dxg + /usr/lib/wsl/lib case, not just /dev/nvidia0.

Apologies for the misleading device paths in the original write-up.

pva · 1 month ago

Extending writable_roots to support device files is also a very wanted feature to allow codex to run qemu (for /dev/kvm device access).