[bug] workspace-write sandbox blocks GPU access (no /dev/nvidia* in bwrap namespace)
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:
- Auto-detect GPU and bind-mount when present. When bubblewrap detects
/dev/nvidia*exists on the host, add--dev-bind /dev/nvidia0 /dev/nvidia0etc. by default in non-read-onlymodes. Low risk — these device files are present only on systems with NVIDIA drivers, and exposing them doesn't grant network or filesystem-write access.
- Add a
gpu_passthroughconfig flag. ExtendSandboxPolicy::WorkspaceWritewith agpu_passthrough: boolfield. 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).
- Extend
writable_rootsto support device files. Allow paths like/dev/nvidia0inwritable_roots. Codex translates these to bubblewrap--dev-bindrather 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::WorkspaceWritedefinition (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.
4 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
@jeanibarz @etraut-openai
Was this fixed?
@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/nvidiactldon't exist at all. CUDA is exposed via:/dev/dxgdevice node, plus/usr/lib/wsl/lib/(libcuda.so.1,libnvidia-ml.so.1, etc.)So
torch.cuda.is_available() == Trueoutside 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:
/dev/nvidia*//dev/nvidiactl— the original report./dev/dxgand bind-mount/usr/lib/wsl/lib(and keep/usr/lib/wsl/libon 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-onlymodes — but the detection has to cover the WSL2/dev/dxg+/usr/lib/wsl/libcase, not just/dev/nvidia0.Apologies for the misleading device paths in the original write-up.
Extending writable_roots to support device files is also a very wanted feature to allow codex to run qemu (for /dev/kvm device access).