Repository navigation
Add --dev-bind to pass host devices into the sandbox - #13
Merged
Merged
Conversation
The sandbox gets a minimal /dev from `--dev /dev`, and the only way to add to it was --bind. bwrap mounts a plain bind nodev, so a device passed that way shows up inside but cannot be opened: $ ai-bwrap bash --bind /dev/kfd -- -c 'ls /dev/kfd; : < /dev/kfd' /dev/kfd /usr/bin/bash: line 1: /dev/kfd: Permission denied That rules out anything that needs a GPU, e.g. building and testing HIP or CUDA code from inside the sandbox. --dev-bind PATH and the EXTRA_DEV_BINDS config hook emit --dev-bind-try instead, which keeps device access. They are appended after `--dev /dev` like the other extra binds, which is what lets them land on top of it, and they are added to the overlay mask list for the same reason the others are. The README shows the config for an AMD GPU with ROCm. That needs /sys and /opt/rocm as well, which the existing read-only binds already cover, so there is no GPU-specific option. Tests: 30-options and 50-config assert that the option and the config hook become a device bind, and 60-confinement runs a real sandbox with --dev-bind /dev/null and writes to it, which fails with a plain bind. Generated-by: Claude Opus 5.5 (Claude Code) Signed-off-by: Thorsten Liebig <thorsten.liebig@gmx.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new
--dev-bind PATHoption and anEXTRA_DEV_BINDSconfig hook, which pass a host device into the sandbox with--dev-bind-try.Why
The sandbox gets a minimal
/devfrom--dev /dev, and the only way to add to it is--bind. bwrap mounts a plain bindnodev, so a device passed that way shows up inside but cannot be opened:That rules out anything that needs a GPU. I ran into it trying to build and test HIP code (AMD, ROCm) from inside the sandbox.
Scope
--dev /dev, like the other extra binds, so they land on top of it. They are also added to the overlay mask list, as the other extra binds are./sysand, for ROCm,/opt/rocm; the existing read-only binds cover those. The README shows the config for an AMD GPU as an example:--helpand the changelog are updated with it.Tests
30-options:--dev-bindwithout a value is an error; the option becomes a device bind.50-config:EXTRA_DEV_BINDSreaches the sandbox.60-confinement: a real sandbox with--dev-bind /dev/nullwrites to it, which fails with a plain bind.shellcheck ai-bwrap scripts/screenshots.shis clean and./tests/run.shpasses locally (91 passed, 3 skipped for agents that are not installed).AI disclosure
This change, including the tests, docs and this description, was generated with Claude Code (Claude Opus 5.5) and reviewed by me. The failing
--bind /dev/kfdexample above is from my own machine.🤖 Generated with Claude Code