Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces an experimental REST API service for Ray Sandbox, allowing users to manage sandboxes externally via a FastAPI application on Ray Serve. It also adds support for private network namespaces bridged by pasta (passt) and multi-uid user-namespace mapping to preserve file ownership within sandboxes. The review feedback highlights two critical issues: a missing json import in image_utils.py that will cause a runtime NameError, and a potential unhandled OSError in idmap.py if subprocess.Popen fails outside of the try block.
d633a27 to
f2f0c1b
Compare
…ns via pasta (#65820) ## Description `network="public"` sandboxes currently run with runsc `--network=host` in the Ray worker's own network namespace: every sandbox on a node shares one port space, so concurrent workloads that bind a fixed port collide and can reach each other's listeners. The concrete failure is terminal-bench's QEMU tasks (`qemu-startup`, `qemu-alpine-ssh`), which start QEMU with `hostfwd=tcp::2222-:22` and then SSH to `localhost:2222` from inside the same sandbox. Under co-tenancy the second bind gets `EADDRINUSE`, and a verifier can connect to a *different* sandbox's guest. This PR gives each `public` sandbox a private user+network namespace pair bridged by pasta (passt) user-mode networking, the rootless-Podman topology: - a tiny holder process (`unshare --user --map-root-user --net`) pins the namespaces for the sandbox's lifetime; - `pasta` attaches from the pod side (`--netns/--userns /proc/$PID/ns/*`) and runs in the **foreground** inside the sandbox's process group, so teardown's `killpg` takes it with the rest of the tree. `-t/-u/-T/-U none --no-map-gw` make it egress-only: in-sandbox binds are never republished on the pod, pod-local services are unreachable from the sandbox loopback, and there is no inbound path; - `runsc run` executes inside via `nsenter` as mapped root. `--rootless` is dropped because nesting a second userns breaks the gofer's `/proc` magic-link derefs; since rootless mode is also what tolerated cgroup permission failures, the wrapper forces `--ignore-cgroups` for rootless configs. runsc still gets `--network=host`, but "host" is now private to the sandbox. Mount and pid namespaces stay shared, so the bundle and control sockets under `--root` keep working for pod-side `state`/`exec`/`kill`/`delete`. ### What `public` does and does not isolate `public` isolates sandboxes from each other and from the node's own services. It does **not** isolate them from the network the node sits on: pasta relays every outbound connection through the pod's own sockets and has no destination filter, so a `public` sandbox can reach other Ray nodes (including the head node's GCS and dashboard ports), other pods, and any internal service the node can reach. The docs now say this explicitly and keep `none` as the recommendation for untrusted code. Closing that gap needs egress policy outside pasta: a node-level netfilter rule set (which needs `CAP_NET_ADMIN` in the pod netns), or a second, intermediate user+network namespace we own and can firewall with nftables before handing traffic to the pod-side pasta. That is a follow-up, not part of this PR. ### Why not `pasta [flags] runsc ...` pasta can spawn a command in namespaces it creates itself, which would collapse the holder, pidfile, and nsenter into one wrapper. Prototyped in a privileged container (non-root, pasta from source, `pasta <flags> --foreground -- runsc ... run ...`): the command runs as uid 0 with a fixed `0 <uid> 1` map inside new user, net, **pid, mount, ipc, and uts** namespaces. runsc boots fine, but the pod side loses control of it: `runsc exec` fails with `waiting on pid 2: sandbox is not running` because the state file records the inner pid, and `runsc state` silently reports `running` whenever some unrelated pod process happens to have that pid. Every control call would have to be wrapped in `nsenter -U -n -p -m -t <child>` (that does work), and the single-uid map rules out the multi-uid mapping #65823 needs. The holder + attach shape keeps pid and mount namespaces shared for exactly that reason; with pasta in the foreground it costs one extra `sleep` process. Requires `pasta` and `nsenter` on nodes for `public` sandboxes. Docs updated (requirements, mode table with a warning admonition, install snippets, troubleshooting). Per-exec `user` and `write_file(append=)` moved to #65942 per review. ## Related issues Related to #65633. Per-exec user support split into #65942. ## Additional information Tested with `TEST_SANDBOX=1` in a privileged `rayproject/ray:nightly-py312` container on arm64 as the non-root `ray` user, with pasta built from source: two concurrent `public` sandboxes both bind `0.0.0.0:2222` and each reaches its own listener on `127.0.0.1:2222`; the worker namespace shows nothing on 2222; no address names one sandbox from another; egress and generated-resolv.conf DNS work; `delete_sandbox` and the create-failure path leave no pasta process behind (the tests diff the set of running pasta pids). The exact pasta flag list, the `--foreground`/pidfile gate, and the forced `--ignore-cgroups` are pinned by argv-level unit tests that run without runsc or pasta. ``` TEST_SANDBOX=1 pytest ray/experimental/sandbox/tests/test_gvisor_backend.py -k "netns or build_run_command or requires_pasta" 10 passed ``` --------- Signed-off-by: xyuzh <[email protected]>
0a1a4e5 to
a0cb869
Compare
|
Rebuilt on the current #65820 head (which now includes master with #65748) as a single commit, a0cb869. Two things changed beyond conflict resolution:
Verified in a privileged container with |
a0cb869 to
f8bb2b2
Compare
| Container root maps to the worker's own ids (so the bundle and cache | ||
| files it already owns stay accessible); container 1..count map onto the | ||
| subordinate range, giving every other uid a host representation. | ||
| ``sudo_mapfile`` records how mapping works on this node: False means |
There was a problem hiding this comment.
I think we should remove sudo_mapfile and only allow the newuidmap/newgidmap code path. It will make the PR simpler and the sudo path needs more permissions and doesn't extend the range of infra that this PR can be used in: If somebody has sudo, they can easily set up newuidmap/newgidmap. Plus if allowPrivilegeEscalation: false in k8s, sudo also won't work, so adding the sudo_mapfile functionality doesn't really add anything.
There was a problem hiding this comment.
Removed. IdMap no longer has sudo_mapfile, map_ids_into only runs newuidmap/newgidmap, and the probe just checks that those helpers can write a throwaway namespace's map. The branch is rebuilt as one commit on master with the simplification from your top-level comment as well.
|
I think we should significantly simplify this PR: Don't support both single and multi uid images, either the newuid mechanism is available, in which case we generate multi uid images and run sandboxes in multi uid mode, or it isn't / it is deactivated with the env variable, in which case we generate single uid images and run sandboxes in single uid mode. This should significantly simplify the code. Also, I think there is no reason to tie multi-uid vs. single-uid to the networking mode, is there? These should be independent. |
f8bb2b2 to
aeeb0f2
Compare
|
Done, and it did simplify things a lot. The branch is now one commit on master with:
Net effect versus the previous revision: about 500 fewer lines. Verified in the privileged container with |
Rootless sandboxes map the whole container to one host uid: every file reads as root, chown to any other user fails with EINVAL, and ownership baked into image layers (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattens away, failing workloads that spread ownership across users. A node is now either multi-uid or single-uid. detect_idmap() decides once per process: when the uidmap package's setuid newuidmap/newgidmap helpers and /etc/subuid + /etc/subgid ranges for the worker user are usable, every rootless sandbox runs as mapped root inside a user namespace that maps "0 <worker-id> 1" plus "1 <subbase> <count>" (the rootless-Podman model), independent of its network mode; otherwise, or with RAY_SANDBOX_SINGLE_UID=1, sandboxes keep the single-uid namespace. The holder + nsenter shape that network="public" already uses carries the mapping; single-uid nodes wrap only "public". The image cache follows the same decision. Extraction records each layer's non-root owners (whiteout-aware, a later root-owned layer drops the entry) and, on a multi-uid node, applies them to the freshly extracted tree inside a mapped user namespace (chown, then the mode restored so setuid/setgid bits survive) before the tree is promoted. The .extracted marker records the layout version and the mapping, so a node that switches modes re-extracts once, keeping the pins of sandboxes already running on the old tree. Trees holding subordinate-owned files are removed through a mapped namespace, in eviction and in sandbox teardown alike. Traversing another user's 0700 directory as root additionally needs CAP_DAC_OVERRIDE, which Docker's default capability set carries and the bare runsc-spec default does not; documented in troubleshooting. Signed-off-by: xyuzh <[email protected]>
aeeb0f2 to
66bbac7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.
Reviewed by Cursor Bugbot for commit 66bbac7. Configure here.
| args.append(f"--overlay2=root:dir={overlay_dir}") | ||
| args.extend(["run", "--bundle", root_dir, sandbox_id]) | ||
| if not wrap: | ||
| return args |
There was a problem hiding this comment.
Privileged public sandboxes lose pasta isolation
High Severity
wrap is gated on rootless, so rootless=False plus network="public" skips the pasta holder and runs runsc with --network host on the worker. Create still requires pasta, but never uses it, so those sandboxes share the host port space and lose the private netns isolation public is documented to provide.
Reviewed by Cursor Bugbot for commit 66bbac7. Configure here.
| users = [] | ||
| if os.path.exists(target_dir): | ||
| shutil.rmtree(target_dir, ignore_errors=True) | ||
| _remove_image_tree(target_dir) |
There was a problem hiding this comment.
Mode-switch re-extract can brick the cache
High Severity
Replacing a multi-uid cache deletes the live tree with the current process idmap, not the mapping recorded in .extracted. A switch to single-uid (or a different subordinate range) cannot finish the delete, os.replace then fails on the non-empty directory, and the image is left half-removed with no marker, so later pulls of that image keep failing.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 66bbac7. Configure here.
|
Putting this on hold rather than pushing it further. The EROFS root filesystem is the better answer to the problem this PR solves: gVisor mounts the image inside the Sentry, so the image's uids and gids (and any What carries over from here is the extraction side: Plan: prototype the EROFS rootfs in the image cache (flattened ownership-true tar → Marked as draft until that prototype lands or shows a reason to fall back to this approach. |
|
The EROFS prototype is up as #65992 (draft): images are cached as EROFS root filesystems built without root, and image-baked ownership, |
|
Closing in favor of #65992, which caches images as EROFS root filesystems so image uids live inside gVisor and need no host mapping. That removes the newuidmap, subid-range, and mapped-namespace machinery this PR added, and it works where child uid_map writes are blocked. The ownership-recording extraction from this branch carried over into #65992; the rest stays here for reference. |
Rootless gVisor served each image's extracted directory through the gofer, so every file inside the sandbox read as the worker's uid (root), image-baked ownership (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattened away, and chown to another uid failed. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823). Cache each image as an EROFS file instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and the private overlay upper layer and never need a host representation: files keep their real owners and chown works for any uid, from an unprivileged worker, with no id mapping and no user namespace. The image is built without root: extraction records each layer's non-root owners (whiteout-aware), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor reads only the flat-plain layout) and 4 KiB blocks. The rootfs then comes from the `dev.gvisor.spec.rootfs.*` annotations with a "self" overlay anchored at a per-sandbox directory, so `--overlay2` is no longer passed. The cache holds one file per image instead of a tree; the image's /etc/passwd and /etc/group are kept beside it for user-name resolution. Without a capable mkfs.erofs, or with RAY_SANDBOX_ROOTFS=dir, images are extracted as before. The `.extracted` marker records the layout, so a node that switches re-pulls once (keeping the pins of running sandboxes). runsc applies no rootfs overlay to a read-only root and cannot create mount points in an immutable image, so the standard mount points are seeded at build time and readonly=True keeps its semantics; the one gap is readonly=True with an explicit workdir, which falls back to a private writable overlay (warned and documented) until runsc honors a requested overlay on a read-only root. Signed-off-by: xyuzh <[email protected]>
Rootless gVisor served each image's extracted directory through the gofer, so every file inside the sandbox read as the worker's uid (root), image-baked ownership (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattened away, and chown to another uid failed. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823). Cache each image as an EROFS file instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and the private overlay upper layer and never need a host representation: files keep their real owners and chown works for any uid, from an unprivileged worker, with no id mapping and no user namespace. The image is built without root: extraction records each layer's non-root owners (whiteout-aware), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor reads only the flat-plain layout) and 4 KiB blocks. The rootfs then comes from the `dev.gvisor.spec.rootfs.*` annotations with a "self" overlay anchored at a per-sandbox directory, so `--overlay2` is no longer passed. The cache holds one file per image instead of a tree; the image's /etc/passwd and /etc/group are kept beside it for user-name resolution. Without a capable mkfs.erofs, or with RAY_SANDBOX_ROOTFS=dir, images are extracted as before. The `.extracted` marker records the layout, so a node that switches re-pulls once (keeping the pins of running sandboxes). runsc applies no rootfs overlay to a read-only root and cannot create mount points in an immutable image, so the standard mount points are seeded at build time and readonly=True keeps its semantics; the one gap is readonly=True with an explicit workdir, which falls back to a private writable overlay (warned and documented) until runsc honors a requested overlay on a read-only root. Signed-off-by: xyuzh <[email protected]>
Rootless gVisor served each image's extracted directory through the gofer, so every file inside the sandbox read as the worker's uid (root), image-baked ownership (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattened away, and chown to another uid failed. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823). Cache each image as an EROFS file instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and the private overlay upper layer and never need a host representation: files keep their real owners and chown works for any uid, from an unprivileged worker, with no id mapping and no user namespace. The image is built without root: extraction records each layer's non-root owners (whiteout-aware, and hardlinks under their own name), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor reads only the flat-plain layout) and 4 KiB blocks. The rootfs then comes from the `dev.gvisor.spec.rootfs.*` annotations with a "self" overlay anchored at a per-sandbox directory, so runsc gets no `--overlay2`. The cache holds one file per image instead of a tree. EROFS is the only layout: the extracted-directory code path is gone, so mkfs.erofs 1.7+ is a hard requirement on worker nodes next to runsc, and a pull checks for it before downloading anything. The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, a rename leaving the gofer's open root fd alone) and it goes on a later pull once no sandbox uses the image. The CI corebuild image builds erofs-utils v1.9.4 from source, since Ubuntu 22.04 packages 1.4 and the sandbox tests boot real sandboxes. runsc applies no rootfs overlay to a read-only root and cannot create mount points in an immutable image, so the standard mount points are seeded at build time and readonly=True keeps its semantics; the one gap is readonly=True with an explicit workdir, which runs on a private writable overlay (warned and documented) until runsc honors a requested overlay on a read-only root. Signed-off-by: xyuzh <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]>
Rootless gVisor served each image's extracted directory through the gofer, so every file inside the sandbox read as the worker's uid (root), image-baked ownership (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattened away, and chown to another uid failed. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823). Cache each image as an EROFS file instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and the private overlay upper layer and never need a host representation: files keep their real owners and chown works for any uid, from an unprivileged worker, with no id mapping and no user namespace. The image is built without root: extraction records each layer's non-root owners (whiteout-aware, and hardlinks under their own name), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor reads only the flat-plain layout) and 4 KiB blocks. The rootfs then comes from the `dev.gvisor.spec.rootfs.*` annotations with a "self" overlay anchored at a per-sandbox directory, so runsc gets no `--overlay2`. The cache holds one file per image instead of a tree. EROFS is the only layout: the extracted-directory code path is gone, so mkfs.erofs 1.7+ is a hard requirement on worker nodes next to runsc, and a pull checks for it before downloading anything. The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, a rename leaving the gofer's open root fd alone) and it goes on a later pull once no sandbox uses the image. The CI corebuild image builds erofs-utils v1.9.4 from source, since Ubuntu 22.04 packages 1.4 and the sandbox tests boot real sandboxes. runsc applies no rootfs overlay to a read-only root and cannot create mount points in an immutable image, so the standard mount points are seeded at build time and readonly=True keeps its semantics; the one gap is readonly=True with an explicit workdir, which runs on a private writable overlay (warned and documented) until runsc honors a requested overlay on a read-only root. Signed-off-by: xyuzh <[email protected]>
Rootless gVisor served each image's extracted directory through the gofer, so every file inside the sandbox read as the worker's uid (root), image-baked ownership (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattened away, and chown to another uid failed. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823). Cache each image as an EROFS file instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and the private overlay upper layer and never need a host representation: files keep their real owners and chown works for any uid, from an unprivileged worker, with no id mapping and no user namespace. The image is built without root: extraction records each layer's non-root owners (whiteout-aware, and hardlinks under their own name), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor reads only the flat-plain layout) and 4 KiB blocks. The rootfs then comes from the `dev.gvisor.spec.rootfs.*` annotations with a "self" overlay anchored at a per-sandbox directory, so runsc gets no `--overlay2`. The cache holds one file per image instead of a tree. EROFS is the only layout: the extracted-directory code path is gone, so mkfs.erofs 1.7+ is a hard requirement on worker nodes next to runsc, and a pull checks for it before downloading anything. The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, a rename leaving the gofer's open root fd alone) and it goes on a later pull once no sandbox uses the image. The CI corebuild image builds erofs-utils v1.9.4 from source, since Ubuntu 22.04 packages 1.4 and the sandbox tests boot real sandboxes. runsc applies no rootfs overlay to a read-only root and cannot create mount points in an immutable image, so the standard mount points are seeded at build time and readonly=True keeps its semantics; the one gap is readonly=True with an explicit workdir, which runs on a private writable overlay (warned and documented) until runsc honors a requested overlay on a read-only root. Signed-off-by: xyuzh <[email protected]>
Rootless gVisor served each image's extracted directory through the gofer, so every file inside the sandbox read as the worker's uid (root), image-baked ownership (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattened away, and chown to another uid failed. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823). Cache each image as an EROFS file instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and the private overlay upper layer and never need a host representation: files keep their real owners and chown works for any uid, from an unprivileged worker, with no id mapping and no user namespace. The image is built without root: extraction records each layer's non-root owners (whiteout-aware, and hardlinks under their own name), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor reads only the flat-plain layout) and 4 KiB blocks. The rootfs then comes from the `dev.gvisor.spec.rootfs.*` annotations with a "self" overlay anchored at a per-sandbox directory, so runsc gets no `--overlay2`. The cache holds one file per image instead of a tree. EROFS is the only layout: the extracted-directory code path is gone, so mkfs.erofs 1.7+ is a hard requirement on worker nodes next to runsc, and a pull checks for it before downloading anything. The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, a rename leaving the gofer's open root fd alone) and it goes on a later pull once no sandbox uses the image. The CI corebuild image builds erofs-utils v1.9.4 from source, since Ubuntu 22.04 packages 1.4 and the sandbox tests boot real sandboxes. runsc applies no rootfs overlay to a read-only root and cannot create mount points in an immutable image, so the standard mount points are seeded at build time and readonly=True keeps its semantics; the one gap is readonly=True with an explicit workdir, which runs on a private writable overlay (warned and documented) until runsc honors a requested overlay on a read-only root. Extraction resolves each member's parent inside the tree, with the tree as `/`: an absolute symlink target restarts at the root and `..` never climbs above it. A member under a symlinked directory (UsrMerge's `bin -> usr/bin`, Debian's `/var/run -> /run`) so lands where the image means it, its owner is recorded under that canonical path, which is where the re-pack finds it, and whiteouts delete through the same resolution; before, a relative link left the owner keyed under the link path and the built image had the file as root, and an absolute link dropped the member altogether. The `/tmp` and mount-point seeding use the same resolver, so an image whose `etc`, `dev` or `tmp` links to a host directory gets its seeds inside the tree, never on the host; seeded and extracted files are created with O_NOFOLLOW, and a hardlink to a symlink links the symlink. Signed-off-by: xyuzh <[email protected]>
Rootless gVisor served each image's extracted directory through the gofer, so every file inside the sandbox read as the worker's uid (root), image-baked ownership (postfix's 0700 uid-101 spool, mailman's uid-38 data) flattened away, and chown to another uid failed. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823). Cache each image as an EROFS file instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and the private overlay upper layer and never need a host representation: files keep their real owners and chown works for any uid, from an unprivileged worker, with no id mapping and no user namespace. The image is built without root: extraction records each layer's non-root owners (whiteout-aware, and hardlinks under their own name), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor reads only the flat-plain layout) and 4 KiB blocks. The rootfs then comes from the `dev.gvisor.spec.rootfs.*` annotations with a "self" overlay anchored at a per-sandbox directory, so runsc gets no `--overlay2`. The cache holds one file per image instead of a tree. EROFS is the only layout: the extracted-directory code path is gone, so mkfs.erofs 1.7+ is a hard requirement on worker nodes next to runsc, and a pull checks for it before downloading anything. The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, a rename leaving the gofer's open root fd alone) and it goes on a later pull once no sandbox uses the image. The CI corebuild image builds erofs-utils v1.9.4 from source, since Ubuntu 22.04 packages 1.4 and the sandbox tests boot real sandboxes. runsc applies no rootfs overlay to a read-only root and cannot create mount points in an immutable image, so the standard mount points are seeded at build time and readonly=True keeps its semantics; the one gap is readonly=True with an explicit workdir, which runs on a private writable overlay (warned and documented) until runsc honors a requested overlay on a read-only root. Extraction resolves each member's parent inside the tree, with the tree as `/`: an absolute symlink target restarts at the root and `..` never climbs above it. A member under a symlinked directory (UsrMerge's `bin -> usr/bin`, Debian's `/var/run -> /run`) so lands where the image means it, its owner is recorded under that canonical path, which is where the re-pack finds it, and whiteouts delete through the same resolution; before, a relative link left the owner keyed under the link path and the built image had the file as root, and an absolute link dropped the member altogether. The `/tmp` and mount-point seeding use the same resolver, so an image whose `etc`, `dev` or `tmp` links to a host directory gets its seeds inside the tree, never on the host; seeded and extracted files are created with O_NOFOLLOW, and a hardlink to a symlink links the symlink. Signed-off-by: xyuzh <[email protected]>
## Description Rootless gVisor serves each image's extracted directory through the gofer, so every file inside a sandbox reads as the worker's uid (root), image-baked ownership (postfix's `0700` uid-101 spool, mailman's uid-38 data) flattens away, and `chown` to another uid fails. Fixing that on the host needs subordinate id ranges and setuid helpers (#65823), which many environments can't provide. This caches each image as an **EROFS root filesystem** instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and in the private overlay upper layer and never need a host representation: files keep their real owners and `chown` works for any uid, from an unprivileged worker, with no id mapping and no user namespace of ours. - **Build without root.** Extraction records each layer's non-root owners (whiteout-aware; a later root-owned layer drops the entry; hardlinks are recorded under their own name so the re-pack keeps the owner whichever name it emits first), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor's EROFS reader maps the image and only handles the flat-plain layout) and 4 KiB blocks. The extracted tree is deleted afterwards; the cache holds one file per image plus the image config. - **Mount via annotations.** The bundle gets `dev.gvisor.spec.rootfs.source/type/overlay`; the `self` overlay is anchored at a per-sandbox directory, and runsc no longer gets `--overlay2`. `readonly=True` keeps its semantics because the standard mount points (`/proc`, `/sys`, `/dev`, `/dev/pts`, `/dev/shm`, `/run`, `/tmp`, `/etc/{resolv.conf,hosts,hostname}`) are seeded into the image at build time; runsc applies no rootfs overlay to a read-only root and can't create mount points in an immutable image. - **Paths resolve inside the tree.** Extraction resolves each member's parent with the extracted tree as `/` (an absolute symlink target restarts at the root, `..` never climbs above it), so a member under a symlinked directory (UsrMerge's `bin -> usr/bin`, Debian's `/var/run -> /run`) lands where the image means it, its owner is recorded under that canonical path (where the re-pack finds it), and whiteouts delete through the same resolution. Before, a relative link left the owner keyed under the link path and the built image had the file as `0:0`; an absolute link dropped the member. The `/tmp` and mount-point seeding use the same resolver, so an image whose `etc`, `dev` or `tmp` links to a host directory gets its seeds inside the tree, never on the host; created files use `O_NOFOLLOW`, and a hardlink to a symlink links the symlink itself. - **EROFS is the only layout.** Per review, the extracted-directory layout (and its `RAY_SANDBOX_ROOTFS=dir` switch) is gone, so `mkfs.erofs` 1.7+ is a hard requirement on worker nodes next to `runsc`. A pull checks for it before downloading anything and fails with an error naming what to install. Ubuntu 24.04 and Debian 13 package a new enough erofs-utils; Ubuntu 22.04's is 1.4 and predates `--tar`, so nodes built on today's `rayproject/ray` images need it built from source (the docs carry the recipe). The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, since a rename leaves the gofer's open root fd alone) and it is deleted on a later pull once no sandbox uses the image. - **CI.** The sandbox tests boot real sandboxes with `TEST_SANDBOX=1`, so the `corebuild` image now builds erofs-utils v1.9.4 from source (pinned to the tag's commit). Unit tests build images through a fake `mkfs.erofs` from `conftest.py` and inspect the resulting tar, so they run anywhere. **One known gap.** `readonly=True` with an explicit `workdir` runs on a private writable overlay (warned at spec time and documented): runsc drops the requested rootfs overlay for read-only roots, and an immutable image can't grow the workdir mount point. The clean fix is a small upstream change to runsc (`initGoferConfs`) to honor an explicitly requested rootfs overlay on a read-only root; `mountAll` already makes the root writable only while creating mount points. The test for the intended behavior is skipped with that reason and a new test pins today's behavior. Together with a Sentry-side network adapter that proxies to the host without `unshare --net`, this leaves no host requirements beyond `runsc` and `mkfs.erofs`. ## Related issues Supersedes #65823 (closed). Related to #65820 and #66004. **Merge order: this PR first.** #65942 (per-exec user), #65633 (HTTP API), and #65839 (gRPC facade) are stacked on this branch in that order; each carries the commits below it until those merge, so their diffs on GitHub include this commit until it lands. #65942 resolves `exec(user=<name>)` inside the running sandbox, so it works unchanged on this cache layout. ## Additional information Validated on x86_64 as well: an Anyscale staging cluster (`anyscale/ray:2.58.0-py312` + runsc release-20260817 + erofs-utils 1.9.4, three 8-CPU nodes) running Terminal-Bench 2.1 with the oracle agent through the `ray.experimental.sandbox` Python API. The `mailman` task, which depends on image-baked postfix/mailman file ownership surviving inside the sandbox, scores 0 on the directory layout and 1.0 with this change; the other 88 tasks are unchanged (89 trials, 0 errored). That is the exact ownership scenario this PR exists for, on a real cluster rather than a privileged dev container. Measured in a privileged `rayproject/ray:nightly-py312` container on arm64 (erofs-utils 1.9.4 built from source, runsc release-20260817): | image | pull + build | `rootfs.erofs` | extracted tree | | --- | --- | --- | --- | | python:3.10-slim | 7.1 s | 156.8 MB | 147 MB | | ubuntu:24.04 | 4.6 s | 108.0 MB | 104 MB | `mkfs.erofs` itself takes about 2 s for python:3.10-slim; `-E^inline_data` costs roughly 6% over the tree size, and the tree is gone afterwards, so the cache shrinks. A cache hit no longer walks an extracted tree for eviction accounting either (one file per image), which removes the ~60 ms per `pull_image` that @OneSizeFitsQuorum profiled on the directory layout. Runtime tests in that container as the unprivileged `ray` user with `TEST_SANDBOX=1` (`test_gvisor_backend.py`, `test_image_utils.py`, `test_image_manager.py`): 79 passed, 1 skipped (the readonly + workdir case above); the `ray.init` smoke test was run on its own. The run started from the cache the directory layout had left on that node, which the first pull rebuilt to the format-3 marker. They cover image-baked ownership from a local tar (`101:0:700`, `101:104:2710` setgid dir, a setuid tool), root traversing another user's `0700` directory, `chown` to arbitrary uids and `chown -R` with setgid inheritance, a readonly EROFS root with writable `/tmp`, `network="host"` egress, the `network="public"` netns suite, and the existing lifecycle, overlay isolation, and workdir suites. Unit tests cover ownership recording across layers including hardlinks, the owner-restoring tar filter, the build through a fake `mkfs.erofs`, the missing/too-old `mkfs.erofs` error, the format-3 re-pull with and without running sandboxes, and the EROFS OCI spec. Signed-off-by: xyuzh <[email protected]>
…5992) ## Description Rootless gVisor serves each image's extracted directory through the gofer, so every file inside a sandbox reads as the worker's uid (root), image-baked ownership (postfix's `0700` uid-101 spool, mailman's uid-38 data) flattens away, and `chown` to another uid fails. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823), which many environments can't provide. This caches each image as an **EROFS root filesystem** instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and in the private overlay upper layer and never need a host representation: files keep their real owners and `chown` works for any uid, from an unprivileged worker, with no id mapping and no user namespace of ours. - **Build without root.** Extraction records each layer's non-root owners (whiteout-aware; a later root-owned layer drops the entry; hardlinks are recorded under their own name so the re-pack keeps the owner whichever name it emits first), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor's EROFS reader maps the image and only handles the flat-plain layout) and 4 KiB blocks. The extracted tree is deleted afterwards; the cache holds one file per image plus the image config. - **Mount via annotations.** The bundle gets `dev.gvisor.spec.rootfs.source/type/overlay`; the `self` overlay is anchored at a per-sandbox directory, and runsc no longer gets `--overlay2`. `readonly=True` keeps its semantics because the standard mount points (`/proc`, `/sys`, `/dev`, `/dev/pts`, `/dev/shm`, `/run`, `/tmp`, `/etc/{resolv.conf,hosts,hostname}`) are seeded into the image at build time; runsc applies no rootfs overlay to a read-only root and can't create mount points in an immutable image. - **Paths resolve inside the tree.** Extraction resolves each member's parent with the extracted tree as `/` (an absolute symlink target restarts at the root, `..` never climbs above it), so a member under a symlinked directory (UsrMerge's `bin -> usr/bin`, Debian's `/var/run -> /run`) lands where the image means it, its owner is recorded under that canonical path (where the re-pack finds it), and whiteouts delete through the same resolution. Before, a relative link left the owner keyed under the link path and the built image had the file as `0:0`; an absolute link dropped the member. The `/tmp` and mount-point seeding use the same resolver, so an image whose `etc`, `dev` or `tmp` links to a host directory gets its seeds inside the tree, never on the host; created files use `O_NOFOLLOW`, and a hardlink to a symlink links the symlink itself. - **EROFS is the only layout.** Per review, the extracted-directory layout (and its `RAY_SANDBOX_ROOTFS=dir` switch) is gone, so `mkfs.erofs` 1.7+ is a hard requirement on worker nodes next to `runsc`. A pull checks for it before downloading anything and fails with an error naming what to install. Ubuntu 24.04 and Debian 13 package a new enough erofs-utils; Ubuntu 22.04's is 1.4 and predates `--tar`, so nodes built on today's `rayproject/ray` images need it built from source (the docs carry the recipe). The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, since a rename leaves the gofer's open root fd alone) and it is deleted on a later pull once no sandbox uses the image. - **CI.** The sandbox tests boot real sandboxes with `TEST_SANDBOX=1`, so the `corebuild` image now builds erofs-utils v1.9.4 from source (pinned to the tag's commit). Unit tests build images through a fake `mkfs.erofs` from `conftest.py` and inspect the resulting tar, so they run anywhere. **One known gap.** `readonly=True` with an explicit `workdir` runs on a private writable overlay (warned at spec time and documented): runsc drops the requested rootfs overlay for read-only roots, and an immutable image can't grow the workdir mount point. The clean fix is a small upstream change to runsc (`initGoferConfs`) to honor an explicitly requested rootfs overlay on a read-only root; `mountAll` already makes the root writable only while creating mount points. The test for the intended behavior is skipped with that reason and a new test pins today's behavior. Together with a Sentry-side network adapter that proxies to the host without `unshare --net`, this leaves no host requirements beyond `runsc` and `mkfs.erofs`. ## Related issues Supersedes ray-project#65823 (closed). Related to ray-project#65820 and ray-project#66004. **Merge order: this PR first.** ray-project#65942 (per-exec user), ray-project#65633 (HTTP API), and ray-project#65839 (gRPC facade) are stacked on this branch in that order; each carries the commits below it until those merge, so their diffs on GitHub include this commit until it lands. ray-project#65942 resolves `exec(user=<name>)` inside the running sandbox, so it works unchanged on this cache layout. ## Additional information Validated on x86_64 as well: an Anyscale staging cluster (`anyscale/ray:2.58.0-py312` + runsc release-20260817 + erofs-utils 1.9.4, three 8-CPU nodes) running Terminal-Bench 2.1 with the oracle agent through the `ray.experimental.sandbox` Python API. The `mailman` task, which depends on image-baked postfix/mailman file ownership surviving inside the sandbox, scores 0 on the directory layout and 1.0 with this change; the other 88 tasks are unchanged (89 trials, 0 errored). That is the exact ownership scenario this PR exists for, on a real cluster rather than a privileged dev container. Measured in a privileged `rayproject/ray:nightly-py312` container on arm64 (erofs-utils 1.9.4 built from source, runsc release-20260817): | image | pull + build | `rootfs.erofs` | extracted tree | | --- | --- | --- | --- | | python:3.10-slim | 7.1 s | 156.8 MB | 147 MB | | ubuntu:24.04 | 4.6 s | 108.0 MB | 104 MB | `mkfs.erofs` itself takes about 2 s for python:3.10-slim; `-E^inline_data` costs roughly 6% over the tree size, and the tree is gone afterwards, so the cache shrinks. A cache hit no longer walks an extracted tree for eviction accounting either (one file per image), which removes the ~60 ms per `pull_image` that @OneSizeFitsQuorum profiled on the directory layout. Runtime tests in that container as the unprivileged `ray` user with `TEST_SANDBOX=1` (`test_gvisor_backend.py`, `test_image_utils.py`, `test_image_manager.py`): 79 passed, 1 skipped (the readonly + workdir case above); the `ray.init` smoke test was run on its own. The run started from the cache the directory layout had left on that node, which the first pull rebuilt to the format-3 marker. They cover image-baked ownership from a local tar (`101:0:700`, `101:104:2710` setgid dir, a setuid tool), root traversing another user's `0700` directory, `chown` to arbitrary uids and `chown -R` with setgid inheritance, a readonly EROFS root with writable `/tmp`, `network="host"` egress, the `network="public"` netns suite, and the existing lifecycle, overlay isolation, and workdir suites. Unit tests cover ownership recording across layers including hardlinks, the owner-restoring tar filter, the build through a fake `mkfs.erofs`, the missing/too-old `mkfs.erofs` error, the format-3 re-pull with and without running sandboxes, and the EROFS OCI spec. Signed-off-by: xyuzh <[email protected]>
…ns via pasta (ray-project#65820) ## Description `network="public"` sandboxes currently run with runsc `--network=host` in the Ray worker's own network namespace: every sandbox on a node shares one port space, so concurrent workloads that bind a fixed port collide and can reach each other's listeners. The concrete failure is terminal-bench's QEMU tasks (`qemu-startup`, `qemu-alpine-ssh`), which start QEMU with `hostfwd=tcp::2222-:22` and then SSH to `localhost:2222` from inside the same sandbox. Under co-tenancy the second bind gets `EADDRINUSE`, and a verifier can connect to a *different* sandbox's guest. This PR gives each `public` sandbox a private user+network namespace pair bridged by pasta (passt) user-mode networking, the rootless-Podman topology: - a tiny holder process (`unshare --user --map-root-user --net`) pins the namespaces for the sandbox's lifetime; - `pasta` attaches from the pod side (`--netns/--userns /proc/$PID/ns/*`) and runs in the **foreground** inside the sandbox's process group, so teardown's `killpg` takes it with the rest of the tree. `-t/-u/-T/-U none --no-map-gw` make it egress-only: in-sandbox binds are never republished on the pod, pod-local services are unreachable from the sandbox loopback, and there is no inbound path; - `runsc run` executes inside via `nsenter` as mapped root. `--rootless` is dropped because nesting a second userns breaks the gofer's `/proc` magic-link derefs; since rootless mode is also what tolerated cgroup permission failures, the wrapper forces `--ignore-cgroups` for rootless configs. runsc still gets `--network=host`, but "host" is now private to the sandbox. Mount and pid namespaces stay shared, so the bundle and control sockets under `--root` keep working for pod-side `state`/`exec`/`kill`/`delete`. ### What `public` does and does not isolate `public` isolates sandboxes from each other and from the node's own services. It does **not** isolate them from the network the node sits on: pasta relays every outbound connection through the pod's own sockets and has no destination filter, so a `public` sandbox can reach other Ray nodes (including the head node's GCS and dashboard ports), other pods, and any internal service the node can reach. The docs now say this explicitly and keep `none` as the recommendation for untrusted code. Closing that gap needs egress policy outside pasta: a node-level netfilter rule set (which needs `CAP_NET_ADMIN` in the pod netns), or a second, intermediate user+network namespace we own and can firewall with nftables before handing traffic to the pod-side pasta. That is a follow-up, not part of this PR. ### Why not `pasta [flags] runsc ...` pasta can spawn a command in namespaces it creates itself, which would collapse the holder, pidfile, and nsenter into one wrapper. Prototyped in a privileged container (non-root, pasta from source, `pasta <flags> --foreground -- runsc ... run ...`): the command runs as uid 0 with a fixed `0 <uid> 1` map inside new user, net, **pid, mount, ipc, and uts** namespaces. runsc boots fine, but the pod side loses control of it: `runsc exec` fails with `waiting on pid 2: sandbox is not running` because the state file records the inner pid, and `runsc state` silently reports `running` whenever some unrelated pod process happens to have that pid. Every control call would have to be wrapped in `nsenter -U -n -p -m -t <child>` (that does work), and the single-uid map rules out the multi-uid mapping ray-project#65823 needs. The holder + attach shape keeps pid and mount namespaces shared for exactly that reason; with pasta in the foreground it costs one extra `sleep` process. Requires `pasta` and `nsenter` on nodes for `public` sandboxes. Docs updated (requirements, mode table with a warning admonition, install snippets, troubleshooting). Per-exec `user` and `write_file(append=)` moved to ray-project#65942 per review. ## Related issues Related to ray-project#65633. Per-exec user support split into ray-project#65942. ## Additional information Tested with `TEST_SANDBOX=1` in a privileged `rayproject/ray:nightly-py312` container on arm64 as the non-root `ray` user, with pasta built from source: two concurrent `public` sandboxes both bind `0.0.0.0:2222` and each reaches its own listener on `127.0.0.1:2222`; the worker namespace shows nothing on 2222; no address names one sandbox from another; egress and generated-resolv.conf DNS work; `delete_sandbox` and the create-failure path leave no pasta process behind (the tests diff the set of running pasta pids). The exact pasta flag list, the `--foreground`/pidfile gate, and the forced `--ignore-cgroups` are pinned by argv-level unit tests that run without runsc or pasta. ``` TEST_SANDBOX=1 pytest ray/experimental/sandbox/tests/test_gvisor_backend.py -k "netns or build_run_command or requires_pasta" 10 passed ``` --------- Signed-off-by: xyuzh <[email protected]>
…5992) ## Description Rootless gVisor serves each image's extracted directory through the gofer, so every file inside a sandbox reads as the worker's uid (root), image-baked ownership (postfix's `0700` uid-101 spool, mailman's uid-38 data) flattens away, and `chown` to another uid fails. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823), which many environments can't provide. This caches each image as an **EROFS root filesystem** instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and in the private overlay upper layer and never need a host representation: files keep their real owners and `chown` works for any uid, from an unprivileged worker, with no id mapping and no user namespace of ours. - **Build without root.** Extraction records each layer's non-root owners (whiteout-aware; a later root-owned layer drops the entry; hardlinks are recorded under their own name so the re-pack keeps the owner whichever name it emits first), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor's EROFS reader maps the image and only handles the flat-plain layout) and 4 KiB blocks. The extracted tree is deleted afterwards; the cache holds one file per image plus the image config. - **Mount via annotations.** The bundle gets `dev.gvisor.spec.rootfs.source/type/overlay`; the `self` overlay is anchored at a per-sandbox directory, and runsc no longer gets `--overlay2`. `readonly=True` keeps its semantics because the standard mount points (`/proc`, `/sys`, `/dev`, `/dev/pts`, `/dev/shm`, `/run`, `/tmp`, `/etc/{resolv.conf,hosts,hostname}`) are seeded into the image at build time; runsc applies no rootfs overlay to a read-only root and can't create mount points in an immutable image. - **Paths resolve inside the tree.** Extraction resolves each member's parent with the extracted tree as `/` (an absolute symlink target restarts at the root, `..` never climbs above it), so a member under a symlinked directory (UsrMerge's `bin -> usr/bin`, Debian's `/var/run -> /run`) lands where the image means it, its owner is recorded under that canonical path (where the re-pack finds it), and whiteouts delete through the same resolution. Before, a relative link left the owner keyed under the link path and the built image had the file as `0:0`; an absolute link dropped the member. The `/tmp` and mount-point seeding use the same resolver, so an image whose `etc`, `dev` or `tmp` links to a host directory gets its seeds inside the tree, never on the host; created files use `O_NOFOLLOW`, and a hardlink to a symlink links the symlink itself. - **EROFS is the only layout.** Per review, the extracted-directory layout (and its `RAY_SANDBOX_ROOTFS=dir` switch) is gone, so `mkfs.erofs` 1.7+ is a hard requirement on worker nodes next to `runsc`. A pull checks for it before downloading anything and fails with an error naming what to install. Ubuntu 24.04 and Debian 13 package a new enough erofs-utils; Ubuntu 22.04's is 1.4 and predates `--tar`, so nodes built on today's `rayproject/ray` images need it built from source (the docs carry the recipe). The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, since a rename leaves the gofer's open root fd alone) and it is deleted on a later pull once no sandbox uses the image. - **CI.** The sandbox tests boot real sandboxes with `TEST_SANDBOX=1`, so the `corebuild` image now builds erofs-utils v1.9.4 from source (pinned to the tag's commit). Unit tests build images through a fake `mkfs.erofs` from `conftest.py` and inspect the resulting tar, so they run anywhere. **One known gap.** `readonly=True` with an explicit `workdir` runs on a private writable overlay (warned at spec time and documented): runsc drops the requested rootfs overlay for read-only roots, and an immutable image can't grow the workdir mount point. The clean fix is a small upstream change to runsc (`initGoferConfs`) to honor an explicitly requested rootfs overlay on a read-only root; `mountAll` already makes the root writable only while creating mount points. The test for the intended behavior is skipped with that reason and a new test pins today's behavior. Together with a Sentry-side network adapter that proxies to the host without `unshare --net`, this leaves no host requirements beyond `runsc` and `mkfs.erofs`. ## Related issues Supersedes ray-project#65823 (closed). Related to ray-project#65820 and ray-project#66004. **Merge order: this PR first.** ray-project#65942 (per-exec user), ray-project#65633 (HTTP API), and ray-project#65839 (gRPC facade) are stacked on this branch in that order; each carries the commits below it until those merge, so their diffs on GitHub include this commit until it lands. ray-project#65942 resolves `exec(user=<name>)` inside the running sandbox, so it works unchanged on this cache layout. ## Additional information Validated on x86_64 as well: an Anyscale staging cluster (`anyscale/ray:2.58.0-py312` + runsc release-20260817 + erofs-utils 1.9.4, three 8-CPU nodes) running Terminal-Bench 2.1 with the oracle agent through the `ray.experimental.sandbox` Python API. The `mailman` task, which depends on image-baked postfix/mailman file ownership surviving inside the sandbox, scores 0 on the directory layout and 1.0 with this change; the other 88 tasks are unchanged (89 trials, 0 errored). That is the exact ownership scenario this PR exists for, on a real cluster rather than a privileged dev container. Measured in a privileged `rayproject/ray:nightly-py312` container on arm64 (erofs-utils 1.9.4 built from source, runsc release-20260817): | image | pull + build | `rootfs.erofs` | extracted tree | | --- | --- | --- | --- | | python:3.10-slim | 7.1 s | 156.8 MB | 147 MB | | ubuntu:24.04 | 4.6 s | 108.0 MB | 104 MB | `mkfs.erofs` itself takes about 2 s for python:3.10-slim; `-E^inline_data` costs roughly 6% over the tree size, and the tree is gone afterwards, so the cache shrinks. A cache hit no longer walks an extracted tree for eviction accounting either (one file per image), which removes the ~60 ms per `pull_image` that @OneSizeFitsQuorum profiled on the directory layout. Runtime tests in that container as the unprivileged `ray` user with `TEST_SANDBOX=1` (`test_gvisor_backend.py`, `test_image_utils.py`, `test_image_manager.py`): 79 passed, 1 skipped (the readonly + workdir case above); the `ray.init` smoke test was run on its own. The run started from the cache the directory layout had left on that node, which the first pull rebuilt to the format-3 marker. They cover image-baked ownership from a local tar (`101:0:700`, `101:104:2710` setgid dir, a setuid tool), root traversing another user's `0700` directory, `chown` to arbitrary uids and `chown -R` with setgid inheritance, a readonly EROFS root with writable `/tmp`, `network="host"` egress, the `network="public"` netns suite, and the existing lifecycle, overlay isolation, and workdir suites. Unit tests cover ownership recording across layers including hardlinks, the owner-restoring tar filter, the build through a fake `mkfs.erofs`, the missing/too-old `mkfs.erofs` error, the format-3 re-pull with and without running sandboxes, and the EROFS OCI spec. Signed-off-by: xyuzh <[email protected]>
…ns via pasta (ray-project#65820) ## Description `network="public"` sandboxes currently run with runsc `--network=host` in the Ray worker's own network namespace: every sandbox on a node shares one port space, so concurrent workloads that bind a fixed port collide and can reach each other's listeners. The concrete failure is terminal-bench's QEMU tasks (`qemu-startup`, `qemu-alpine-ssh`), which start QEMU with `hostfwd=tcp::2222-:22` and then SSH to `localhost:2222` from inside the same sandbox. Under co-tenancy the second bind gets `EADDRINUSE`, and a verifier can connect to a *different* sandbox's guest. This PR gives each `public` sandbox a private user+network namespace pair bridged by pasta (passt) user-mode networking, the rootless-Podman topology: - a tiny holder process (`unshare --user --map-root-user --net`) pins the namespaces for the sandbox's lifetime; - `pasta` attaches from the pod side (`--netns/--userns /proc/$PID/ns/*`) and runs in the **foreground** inside the sandbox's process group, so teardown's `killpg` takes it with the rest of the tree. `-t/-u/-T/-U none --no-map-gw` make it egress-only: in-sandbox binds are never republished on the pod, pod-local services are unreachable from the sandbox loopback, and there is no inbound path; - `runsc run` executes inside via `nsenter` as mapped root. `--rootless` is dropped because nesting a second userns breaks the gofer's `/proc` magic-link derefs; since rootless mode is also what tolerated cgroup permission failures, the wrapper forces `--ignore-cgroups` for rootless configs. runsc still gets `--network=host`, but "host" is now private to the sandbox. Mount and pid namespaces stay shared, so the bundle and control sockets under `--root` keep working for pod-side `state`/`exec`/`kill`/`delete`. ### What `public` does and does not isolate `public` isolates sandboxes from each other and from the node's own services. It does **not** isolate them from the network the node sits on: pasta relays every outbound connection through the pod's own sockets and has no destination filter, so a `public` sandbox can reach other Ray nodes (including the head node's GCS and dashboard ports), other pods, and any internal service the node can reach. The docs now say this explicitly and keep `none` as the recommendation for untrusted code. Closing that gap needs egress policy outside pasta: a node-level netfilter rule set (which needs `CAP_NET_ADMIN` in the pod netns), or a second, intermediate user+network namespace we own and can firewall with nftables before handing traffic to the pod-side pasta. That is a follow-up, not part of this PR. ### Why not `pasta [flags] runsc ...` pasta can spawn a command in namespaces it creates itself, which would collapse the holder, pidfile, and nsenter into one wrapper. Prototyped in a privileged container (non-root, pasta from source, `pasta <flags> --foreground -- runsc ... run ...`): the command runs as uid 0 with a fixed `0 <uid> 1` map inside new user, net, **pid, mount, ipc, and uts** namespaces. runsc boots fine, but the pod side loses control of it: `runsc exec` fails with `waiting on pid 2: sandbox is not running` because the state file records the inner pid, and `runsc state` silently reports `running` whenever some unrelated pod process happens to have that pid. Every control call would have to be wrapped in `nsenter -U -n -p -m -t <child>` (that does work), and the single-uid map rules out the multi-uid mapping ray-project#65823 needs. The holder + attach shape keeps pid and mount namespaces shared for exactly that reason; with pasta in the foreground it costs one extra `sleep` process. Requires `pasta` and `nsenter` on nodes for `public` sandboxes. Docs updated (requirements, mode table with a warning admonition, install snippets, troubleshooting). Per-exec `user` and `write_file(append=)` moved to ray-project#65942 per review. ## Related issues Related to ray-project#65633. Per-exec user support split into ray-project#65942. ## Additional information Tested with `TEST_SANDBOX=1` in a privileged `rayproject/ray:nightly-py312` container on arm64 as the non-root `ray` user, with pasta built from source: two concurrent `public` sandboxes both bind `0.0.0.0:2222` and each reaches its own listener on `127.0.0.1:2222`; the worker namespace shows nothing on 2222; no address names one sandbox from another; egress and generated-resolv.conf DNS work; `delete_sandbox` and the create-failure path leave no pasta process behind (the tests diff the set of running pasta pids). The exact pasta flag list, the `--foreground`/pidfile gate, and the forced `--ignore-cgroups` are pinned by argv-level unit tests that run without runsc or pasta. ``` TEST_SANDBOX=1 pytest ray/experimental/sandbox/tests/test_gvisor_backend.py -k "netns or build_run_command or requires_pasta" 10 passed ``` --------- Signed-off-by: xyuzh <[email protected]>
…5992) ## Description Rootless gVisor serves each image's extracted directory through the gofer, so every file inside a sandbox reads as the worker's uid (root), image-baked ownership (postfix's `0700` uid-101 spool, mailman's uid-38 data) flattens away, and `chown` to another uid fails. Fixing that on the host needs subordinate id ranges and setuid helpers (ray-project#65823), which many environments can't provide. This caches each image as an **EROFS root filesystem** instead. gVisor mounts it inside the Sentry, so uids and gids live in the image and in the private overlay upper layer and never need a host representation: files keep their real owners and `chown` works for any uid, from an unprivileged worker, with no id mapping and no user namespace of ours. - **Build without root.** Extraction records each layer's non-root owners (whiteout-aware; a later root-owned layer drops the entry; hardlinks are recorded under their own name so the re-pack keeps the owner whichever name it emits first), the tree is re-packed as a tar whose headers carry them, and `mkfs.erofs --tar` (erofs-utils 1.7+) turns that into the image with `-E^inline_data` (gVisor's EROFS reader maps the image and only handles the flat-plain layout) and 4 KiB blocks. The extracted tree is deleted afterwards; the cache holds one file per image plus the image config. - **Mount via annotations.** The bundle gets `dev.gvisor.spec.rootfs.source/type/overlay`; the `self` overlay is anchored at a per-sandbox directory, and runsc no longer gets `--overlay2`. `readonly=True` keeps its semantics because the standard mount points (`/proc`, `/sys`, `/dev`, `/dev/pts`, `/dev/shm`, `/run`, `/tmp`, `/etc/{resolv.conf,hosts,hostname}`) are seeded into the image at build time; runsc applies no rootfs overlay to a read-only root and can't create mount points in an immutable image. - **Paths resolve inside the tree.** Extraction resolves each member's parent with the extracted tree as `/` (an absolute symlink target restarts at the root, `..` never climbs above it), so a member under a symlinked directory (UsrMerge's `bin -> usr/bin`, Debian's `/var/run -> /run`) lands where the image means it, its owner is recorded under that canonical path (where the re-pack finds it), and whiteouts delete through the same resolution. Before, a relative link left the owner keyed under the link path and the built image had the file as `0:0`; an absolute link dropped the member. The `/tmp` and mount-point seeding use the same resolver, so an image whose `etc`, `dev` or `tmp` links to a host directory gets its seeds inside the tree, never on the host; created files use `O_NOFOLLOW`, and a hardlink to a symlink links the symlink itself. - **EROFS is the only layout.** Per review, the extracted-directory layout (and its `RAY_SANDBOX_ROOTFS=dir` switch) is gone, so `mkfs.erofs` 1.7+ is a hard requirement on worker nodes next to `runsc`. A pull checks for it before downloading anything and fails with an error naming what to install. Ubuntu 24.04 and Debian 13 package a new enough erofs-utils; Ubuntu 22.04's is 1.4 and predates `--tar`, so nodes built on today's `rayproject/ray` images need it built from source (the docs carry the recipe). The `.extracted` marker moves to format 3, so a cache left by an earlier Ray re-pulls once; sandboxes still running on an old extracted tree keep it (the tree moves into the rebuilt entry, since a rename leaves the gofer's open root fd alone) and it is deleted on a later pull once no sandbox uses the image. - **CI.** The sandbox tests boot real sandboxes with `TEST_SANDBOX=1`, so the `corebuild` image now builds erofs-utils v1.9.4 from source (pinned to the tag's commit). Unit tests build images through a fake `mkfs.erofs` from `conftest.py` and inspect the resulting tar, so they run anywhere. **One known gap.** `readonly=True` with an explicit `workdir` runs on a private writable overlay (warned at spec time and documented): runsc drops the requested rootfs overlay for read-only roots, and an immutable image can't grow the workdir mount point. The clean fix is a small upstream change to runsc (`initGoferConfs`) to honor an explicitly requested rootfs overlay on a read-only root; `mountAll` already makes the root writable only while creating mount points. The test for the intended behavior is skipped with that reason and a new test pins today's behavior. Together with a Sentry-side network adapter that proxies to the host without `unshare --net`, this leaves no host requirements beyond `runsc` and `mkfs.erofs`. ## Related issues Supersedes ray-project#65823 (closed). Related to ray-project#65820 and ray-project#66004. **Merge order: this PR first.** ray-project#65942 (per-exec user), ray-project#65633 (HTTP API), and ray-project#65839 (gRPC facade) are stacked on this branch in that order; each carries the commits below it until those merge, so their diffs on GitHub include this commit until it lands. ray-project#65942 resolves `exec(user=<name>)` inside the running sandbox, so it works unchanged on this cache layout. ## Additional information Validated on x86_64 as well: an Anyscale staging cluster (`anyscale/ray:2.58.0-py312` + runsc release-20260817 + erofs-utils 1.9.4, three 8-CPU nodes) running Terminal-Bench 2.1 with the oracle agent through the `ray.experimental.sandbox` Python API. The `mailman` task, which depends on image-baked postfix/mailman file ownership surviving inside the sandbox, scores 0 on the directory layout and 1.0 with this change; the other 88 tasks are unchanged (89 trials, 0 errored). That is the exact ownership scenario this PR exists for, on a real cluster rather than a privileged dev container. Measured in a privileged `rayproject/ray:nightly-py312` container on arm64 (erofs-utils 1.9.4 built from source, runsc release-20260817): | image | pull + build | `rootfs.erofs` | extracted tree | | --- | --- | --- | --- | | python:3.10-slim | 7.1 s | 156.8 MB | 147 MB | | ubuntu:24.04 | 4.6 s | 108.0 MB | 104 MB | `mkfs.erofs` itself takes about 2 s for python:3.10-slim; `-E^inline_data` costs roughly 6% over the tree size, and the tree is gone afterwards, so the cache shrinks. A cache hit no longer walks an extracted tree for eviction accounting either (one file per image), which removes the ~60 ms per `pull_image` that @OneSizeFitsQuorum profiled on the directory layout. Runtime tests in that container as the unprivileged `ray` user with `TEST_SANDBOX=1` (`test_gvisor_backend.py`, `test_image_utils.py`, `test_image_manager.py`): 79 passed, 1 skipped (the readonly + workdir case above); the `ray.init` smoke test was run on its own. The run started from the cache the directory layout had left on that node, which the first pull rebuilt to the format-3 marker. They cover image-baked ownership from a local tar (`101:0:700`, `101:104:2710` setgid dir, a setuid tool), root traversing another user's `0700` directory, `chown` to arbitrary uids and `chown -R` with setgid inheritance, a readonly EROFS root with writable `/tmp`, `network="host"` egress, the `network="public"` netns suite, and the existing lifecycle, overlay isolation, and workdir suites. Unit tests cover ownership recording across layers including hardlinks, the owner-restoring tar filter, the build through a fake `mkfs.erofs`, the missing/too-old `mkfs.erofs` error, the format-3 re-pull with and without running sandboxes, and the EROFS OCI spec. Signed-off-by: xyuzh <[email protected]>
## Description This PR adds GPU support to Ray Sandboxes by leveraging [CDI](https://github.com/cncf-tags/container-device-interface) (Container Device Interface) to inject GPU device nodes and their supported user-mode driver files into a gVisor sandbox at runtime. This PR builds on #66470, which adds the overlayfs rootfs that GPU sandboxes boot from, and on #66469 and #66528 underneath it. Only the last five commits are new here. The change is implemented as follows. - **Generic CDI framework**: We added a vendor-agnostic CDI module that can be used to parse CDI specs and merge devices from them with a standard OCI image spec. The implementation of this module is kept free of any Ray imports so it stays a candidate for extraction into a standalone library at some point in the future. As part of this, the`AcceleratorManager` class gains two new optional methods, `get_cdi_kind()`/`generate_cdi_spec()`. These methods are implemented by an `AcceleratorManager` to both generate a spec with the full set of CDI devices associated with the accelerator, as well as advertise what kind of CDI devices are associated with it (e.g. `nvidia.com/gpu`). - **NVIDIA specific implementation** : We extended the `NvidiaGPUAcceleratorManager` to be CDI aware and implement the `get_cdi_kind()`/`generate_cdi_spec()` methods mentioned above. At present, we generate CDI devices by shelling out to `nvidia-ctk cdi generate`, but the preferred long-term path is to build (or leverage) a canonical python library for CDI maintained upstream. Since gVisor only supports NVIDIA GPUs at the moment, the `GVisorSandboxBackend` gates GPU passthrough to CDI kinds it actually supports (i.e. `nvidia.com/gpu`), rejecting anything else rather than attempting unverified passthrough. - **`num_gpus` and `gpu_ids`**: When creating a `Sandbox` actor, you can now pass a `num_gpus` field in addition to the existing `cpu` and `memory` fields (similar to what is possible when creating a non-sandboxed actor). When doing so, the sandbox auto-inherits the full Ray GPU assignment derived from `num_gpus` (with no way to limit it further when calling `remote()` later on, unlike for cpus and memory). When creating a sandbox via `SandboxRuntime.create()` (i.e. within a pre-existing actor), there is no `num_gpus` field supported. Instead, we allow passing a `gpu_ids` field as an explicit parameter to specify which of the GPUs that have been granted to the surrounding actor should be isolated inside the sandbox. This allows a single actor with multiple GPUs to manage several sandboxes, each pinned to a different GPU. - **Overlayfs rootfs for GPU sandboxes**: NVIDIA's CDI spec relies on `createContainer` hooks that create library symlinks and update the ldcache in the sandbox's rootfs, and runsc creates mount points there for the driver files and device nodes. The default EROFS rootfs is read-only and shared by every sandbox of an image, so any sandbox with `gpu_ids` now runs on #66470's overlayfs rootfs. These writes land in the sandbox's own upper layer, and the cached image stays untouched. - **53 new unit tests and 9 real-GPU CI tests**: We added `test_cdi.py` and `test_cdi_lib.py` under `ray/experimental/sandbox/tests/`, and extended the existing suites there and under `ray/tests/accelerators/`. The real-GPU tests run via two new Buildkite jobs (`core: sandbox gpu tests`, 1 GPU; `core: sandbox multi gpu tests`, 4 GPUs). Validated end-to-end on an NVIDIA L4 GPU and a machine with 4 NVIDIA A100 GPUs. We also tested on a machine with 4 NVIDIA GB200 GPUs (ARM64/Grace CPU). All of the NVML-based tests passed, but the CUDA tests failed (because gVisor does not yet fully support GB200). Once gVisor supports GB200 we will need to revisit things to ensure that multi-node NVLink is properly supported as well. ## AI assistance Developed with Claude Code (Sonnet 5), including driving the hardware validation above. I reviewed every changed line and take responsibility for the change end-to-end. ## Related issues No tracking issue. Sibling of other active sandbox work: image cache LRU eviction (#65748), per-sandbox netns (#65820), HTTP API (#65633), gRPC facade (#65839), multi-uid netns (#65823); none overlap with this change. ## Duplicate check Searched open/closed issues and PRs for `sandbox gpu`, `CDI`, `gvisor`, `nvproxy`, `nvidia-ctk`, and `container device interface` — nothing addresses GPU or CDI support for Ray Sandboxes. ## Testing - `test_gvisor_gpu.py` (real `nvidia-ctk` generation, device injection, `--nvproxy` boot, `nvidia-smi` inside the sandbox, and a real CUDA kernel launch via NVIDIA's `vectorAdd` sample) — passes on a machine with an NVIDIA L4 GPU and a machine with 4 A100 GPUs. - `test_gvisor_multi_gpu.py` (all four tests, needing 4 GPUs) — only relies on NVML to test. Passes on both a machine with 4 A100 GPUs and a machine with 4 GB200 GPUs, each sandbox pinned to a distinct GPU. - `python/ray/experimental/sandbox/tests/` (full directory, including the above) — on the L4: 228 passed, 10 skipped. On the GB200 machine, as root: 283 passed, 3 failed, 1 skipped. As the non-root user `ray`: 269 passed, 3 failed, 15 skipped. The failures are the known CUDA failure (`test_sandbox_gpu_cuda_vectoradd_runs_a_real_kernel`, see above) and `test_netns_egress_and_dns` and `test_netns_udp_flows_do_not_cross`, which need public DNS that this machine's network doesn't provide. The skipped tests need a worker that can mount in the host's user namespace, which `ray` can't in this Docker test rig, or the CI sandbox job. - `pre-commit run` — passed (`SKIP=vale`; its Go/cgo toolchain doesn't build in this environment). ### Testing manually Building the published `ray` image needs a wheel via `./build-wheel.sh`, which needs Anyscale's internal `cr.ray.io`/Bazel-remote-cache access to build in reasonable time. To avoid long build times, we instead overlay this branch's changed `.py` files onto a stock published `rayproject/ray:2.58.0` image, allowing us to test without a core rebuild since nothing outside pure Python changed. These tests require a machine with an NVIDIA GPU, Docker, and the `nvidia-container-toolkit-base` package installed. Dockerfile: https://gist.github.com/klueska/9f1297a5d7f5a7b7cf9b31b3fb393feb Save it locally, then build from a checkout of this branch (the repo itself is the build context): ```bash cd ray curl -fsSL -o Dockerfile.sandbox-gpu-test https://gist.githubusercontent.com/klueska/9f1297a5d7f5a7b7cf9b31b3fb393feb/raw docker build -t ray-cdi-gpu-test:latest -f Dockerfile.sandbox-gpu-test . ``` Run it. Each test runs twice, once as root and once as the non-root user `ray`. `--device nvidia.com/gpu=all` for GPU access; `--privileged` is needed for gVisor in this specific nested-Docker test rig. `--basetemp` keeps pytest's temporary directories out of `/tmp`, which `test_image_utils.py::test_seeding_stays_inside_the_tree` requires: ```bash # Pure-logic CDI tests + real-nvidia-ctk accelerator tests, no gVisor/root needed: docker run --rm --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_cdi.py \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_cdi_lib.py \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/tests/accelerators/test_nvidia_gpu.py # The real end-to-end GPU sandbox test: exercises real nvidia-ctk generation, device injection, # and gVisor --nvproxy passthrough. No host setup needed -- nvidia-persistenced can be running # or not, both are handled. # The two commands below run these tests as root and as the non-root user ray. docker run --rm --privileged --user root --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_gpu.py docker run --rm --privileged --user ray --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_gpu.py # The four 4-GPU tests: three check that concurrent sandboxes each get a distinct GPU (separate # Sandbox actors, SandboxRuntime.create, and one actor pinning each of its sandboxes via # gpu_ids=...), and one checks that a single sandbox given 2 GPUs sees both. # Needs a machine with 4 GPUs; `--device nvidia.com/gpu=all` must expose at least 4. # The two commands below run these tests as root and as the non-root user ray. docker run --rm --privileged --user root --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_multi_gpu.py docker run --rm --privileged --user ray --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_multi_gpu.py # Full sandbox suite (mocked-GPU config/scheduling tests + real-gVisor CPU and GPU tests): # The two commands below run these tests as root and as the non-root user ray. docker run --rm --privileged --user root --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/ docker run --rm --privileged --user ray --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/ ``` --------- Signed-off-by: Kevin Klues <[email protected]> Signed-off-by: Philipp Moritz <[email protected]> Co-authored-by: Philipp Moritz <[email protected]>
## Description This PR makes the `lint: API param coverage` step a required check by removing `soft_fail: true`. The step was added in #64788 on 2026-08-11. A comment in the step said to remove `soft_fail` "once the false-positive rate is confirmed low." This PR measures that rate from the step's CI history and fixes the four failure patterns the history turned up. While the step only warns, undocumented parameters still land on master. #65633, #66602, and #66950 all merged with the check failing. ### Warn-phase metrics These numbers come from every `premerge` build from 2026-08-11 to 2026-10-29, pulled from the Buildkite API. | | Runs | PRs | |---|--:|--:| | Completed runs of the step | 3,453 | | | Passed | 3,398 | | | Failed | 55 | 23 | | Canceled, which isn't a check outcome | 211 | | Each failure falls into one of three groups: | Failure type | PRs | Runs | Detail | |---|--:|--:|---| | Correct finding | 15 | 42 | A new parameter on a `@PublicAPI` callable has no `Args:` entry. Two of these PRs, #65823 and #65839, were stacked on #65633 before it merged and report its findings again. | | False positive | 3 | 4 | #64399 flagged the `v` argument of a pydantic `@field_validator`. #66255 flagged the private kwarg `_direct_http`. #67258 flagged an option of the `ray start` Click command, which `help=` documents. | | Infrastructure | 5 | 9 | The step printed `could not determine merge-base` and no findings. The branches of #65437 and #65809 forked 520 and 598 master commits before their builds. The step's `git fetch --depth=500` makes the full CI clone shallow, so their merge-base wasn't in the fetched history. | That's 13 spurious failures out of 3,453 runs, about 0.4%, or 13 of 55 failures. Each one would block a PR once the step is required, so this PR fixes all four patterns before removing `soft_fail`. ### Changes - **`_`-prefixed parameters:** `api_param_coverage.py` skips parameters whose names start with `_`. That's Ray's convention for private kwargs, such as `ray.put(_owner=...)`, `tune.run(_remote=...)`, and `Deployment.options(_internal=...)`. On master, 31 public callables have such parameters. - **Pydantic validators and Click commands:** The script skips callables decorated with `field_validator`, `model_validator`, `validator`, `root_validator`, `command`, or `group`. On master, this removes 59 callables from scope. All of them are Click commands, such as `ray start` and `ray job submit`, or pydantic validators on Serve config models. None of them is a Python API whose parameters a docstring documents. - **Property setters:** The script also skips callables decorated with `@<name>.setter`. A setter's `value` is documented on the property's getter, which is the docstring Sphinx renders, not in an `Args:` section of its own. - **Shallow-clone merge-base:** When `git merge-base` fails after the depth-500 fetch, `ci/lint/lint.sh` runs `git fetch --unshallow` and retries. A branch within 500 commits of the base never reaches that path. The Python check still fails closed if the base can't be resolved after that. - **Step definition:** `.buildkite/lint.rayci.yml` drops `soft_fail: true` and the warn-phase comment. The `--blocking` help text in `cmd_check_api_param_coverage.py` no longer describes a warn phase. ## Related issues Follow-up to #64788. ## Additional information ### Testing - `pytest ci/ray_ci/doc/test_api_param_coverage.py`: 40 passed. That's the 28 existing tests plus 12 new cases covering `_` params, each validator spelling, Click command forms, and property setters. The test comments name the real PR that motivated each one. - **Replay against real PRs:** I ran the master and patched versions of the check against the exact commit and base of every failing run in each of the 18 PRs with findings. Master reproduces all 18 failures. The patched check passes #64399, #66255, and #67258, and reports the same findings as master on the other 15. - **Merge-base fix:** In a local repo with 600 commits on `master` and a branch forked at commit 50, `git fetch --depth=500` followed by `git merge-base` fails, which reproduces the CI failure. With the new `lint.sh` block, it resolves the correct fork commit. A branch forked 10 commits back resolves without the fallback. - `pre-commit run` on the changed files passes, including ruff, black, shellcheck, and docstyle. ### Duplicate check `gh pr list --state open --search "param coverage"` and `--search "api_param_coverage"` return no open PR that touches this check. The script hasn't changed since #65391 on 2026-08-14. ### AI assistance I used Claude Code to pull and classify the Buildkite history, draft the changes, and run the replay. I reviewed every changed line and the classification of every failing PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…#65898) ## Description This PR adds GPU support to Ray Sandboxes by leveraging [CDI](https://github.com/cncf-tags/container-device-interface) (Container Device Interface) to inject GPU device nodes and their supported user-mode driver files into a gVisor sandbox at runtime. This PR builds on ray-project#66470, which adds the overlayfs rootfs that GPU sandboxes boot from, and on ray-project#66469 and ray-project#66528 underneath it. Only the last five commits are new here. The change is implemented as follows. - **Generic CDI framework**: We added a vendor-agnostic CDI module that can be used to parse CDI specs and merge devices from them with a standard OCI image spec. The implementation of this module is kept free of any Ray imports so it stays a candidate for extraction into a standalone library at some point in the future. As part of this, the`AcceleratorManager` class gains two new optional methods, `get_cdi_kind()`/`generate_cdi_spec()`. These methods are implemented by an `AcceleratorManager` to both generate a spec with the full set of CDI devices associated with the accelerator, as well as advertise what kind of CDI devices are associated with it (e.g. `nvidia.com/gpu`). - **NVIDIA specific implementation** : We extended the `NvidiaGPUAcceleratorManager` to be CDI aware and implement the `get_cdi_kind()`/`generate_cdi_spec()` methods mentioned above. At present, we generate CDI devices by shelling out to `nvidia-ctk cdi generate`, but the preferred long-term path is to build (or leverage) a canonical python library for CDI maintained upstream. Since gVisor only supports NVIDIA GPUs at the moment, the `GVisorSandboxBackend` gates GPU passthrough to CDI kinds it actually supports (i.e. `nvidia.com/gpu`), rejecting anything else rather than attempting unverified passthrough. - **`num_gpus` and `gpu_ids`**: When creating a `Sandbox` actor, you can now pass a `num_gpus` field in addition to the existing `cpu` and `memory` fields (similar to what is possible when creating a non-sandboxed actor). When doing so, the sandbox auto-inherits the full Ray GPU assignment derived from `num_gpus` (with no way to limit it further when calling `remote()` later on, unlike for cpus and memory). When creating a sandbox via `SandboxRuntime.create()` (i.e. within a pre-existing actor), there is no `num_gpus` field supported. Instead, we allow passing a `gpu_ids` field as an explicit parameter to specify which of the GPUs that have been granted to the surrounding actor should be isolated inside the sandbox. This allows a single actor with multiple GPUs to manage several sandboxes, each pinned to a different GPU. - **Overlayfs rootfs for GPU sandboxes**: NVIDIA's CDI spec relies on `createContainer` hooks that create library symlinks and update the ldcache in the sandbox's rootfs, and runsc creates mount points there for the driver files and device nodes. The default EROFS rootfs is read-only and shared by every sandbox of an image, so any sandbox with `gpu_ids` now runs on ray-project#66470's overlayfs rootfs. These writes land in the sandbox's own upper layer, and the cached image stays untouched. - **53 new unit tests and 9 real-GPU CI tests**: We added `test_cdi.py` and `test_cdi_lib.py` under `ray/experimental/sandbox/tests/`, and extended the existing suites there and under `ray/tests/accelerators/`. The real-GPU tests run via two new Buildkite jobs (`core: sandbox gpu tests`, 1 GPU; `core: sandbox multi gpu tests`, 4 GPUs). Validated end-to-end on an NVIDIA L4 GPU and a machine with 4 NVIDIA A100 GPUs. We also tested on a machine with 4 NVIDIA GB200 GPUs (ARM64/Grace CPU). All of the NVML-based tests passed, but the CUDA tests failed (because gVisor does not yet fully support GB200). Once gVisor supports GB200 we will need to revisit things to ensure that multi-node NVLink is properly supported as well. ## AI assistance Developed with Claude Code (Sonnet 5), including driving the hardware validation above. I reviewed every changed line and take responsibility for the change end-to-end. ## Related issues No tracking issue. Sibling of other active sandbox work: image cache LRU eviction (ray-project#65748), per-sandbox netns (ray-project#65820), HTTP API (ray-project#65633), gRPC facade (ray-project#65839), multi-uid netns (ray-project#65823); none overlap with this change. ## Duplicate check Searched open/closed issues and PRs for `sandbox gpu`, `CDI`, `gvisor`, `nvproxy`, `nvidia-ctk`, and `container device interface` — nothing addresses GPU or CDI support for Ray Sandboxes. ## Testing - `test_gvisor_gpu.py` (real `nvidia-ctk` generation, device injection, `--nvproxy` boot, `nvidia-smi` inside the sandbox, and a real CUDA kernel launch via NVIDIA's `vectorAdd` sample) — passes on a machine with an NVIDIA L4 GPU and a machine with 4 A100 GPUs. - `test_gvisor_multi_gpu.py` (all four tests, needing 4 GPUs) — only relies on NVML to test. Passes on both a machine with 4 A100 GPUs and a machine with 4 GB200 GPUs, each sandbox pinned to a distinct GPU. - `python/ray/experimental/sandbox/tests/` (full directory, including the above) — on the L4: 228 passed, 10 skipped. On the GB200 machine, as root: 283 passed, 3 failed, 1 skipped. As the non-root user `ray`: 269 passed, 3 failed, 15 skipped. The failures are the known CUDA failure (`test_sandbox_gpu_cuda_vectoradd_runs_a_real_kernel`, see above) and `test_netns_egress_and_dns` and `test_netns_udp_flows_do_not_cross`, which need public DNS that this machine's network doesn't provide. The skipped tests need a worker that can mount in the host's user namespace, which `ray` can't in this Docker test rig, or the CI sandbox job. - `pre-commit run` — passed (`SKIP=vale`; its Go/cgo toolchain doesn't build in this environment). ### Testing manually Building the published `ray` image needs a wheel via `./build-wheel.sh`, which needs Anyscale's internal `cr.ray.io`/Bazel-remote-cache access to build in reasonable time. To avoid long build times, we instead overlay this branch's changed `.py` files onto a stock published `rayproject/ray:2.58.0` image, allowing us to test without a core rebuild since nothing outside pure Python changed. These tests require a machine with an NVIDIA GPU, Docker, and the `nvidia-container-toolkit-base` package installed. Dockerfile: https://gist.github.com/klueska/9f1297a5d7f5a7b7cf9b31b3fb393feb Save it locally, then build from a checkout of this branch (the repo itself is the build context): ```bash cd ray curl -fsSL -o Dockerfile.sandbox-gpu-test https://gist.githubusercontent.com/klueska/9f1297a5d7f5a7b7cf9b31b3fb393feb/raw docker build -t ray-cdi-gpu-test:latest -f Dockerfile.sandbox-gpu-test . ``` Run it. Each test runs twice, once as root and once as the non-root user `ray`. `--device nvidia.com/gpu=all` for GPU access; `--privileged` is needed for gVisor in this specific nested-Docker test rig. `--basetemp` keeps pytest's temporary directories out of `/tmp`, which `test_image_utils.py::test_seeding_stays_inside_the_tree` requires: ```bash # Pure-logic CDI tests + real-nvidia-ctk accelerator tests, no gVisor/root needed: docker run --rm --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_cdi.py \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_cdi_lib.py \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/tests/accelerators/test_nvidia_gpu.py # The real end-to-end GPU sandbox test: exercises real nvidia-ctk generation, device injection, # and gVisor --nvproxy passthrough. No host setup needed -- nvidia-persistenced can be running # or not, both are handled. # The two commands below run these tests as root and as the non-root user ray. docker run --rm --privileged --user root --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_gpu.py docker run --rm --privileged --user ray --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_gpu.py # The four 4-GPU tests: three check that concurrent sandboxes each get a distinct GPU (separate # Sandbox actors, SandboxRuntime.create, and one actor pinning each of its sandboxes via # gpu_ids=...), and one checks that a single sandbox given 2 GPUs sees both. # Needs a machine with 4 GPUs; `--device nvidia.com/gpu=all` must expose at least 4. # The two commands below run these tests as root and as the non-root user ray. docker run --rm --privileged --user root --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_multi_gpu.py docker run --rm --privileged --user ray --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/test_gvisor_multi_gpu.py # Full sandbox suite (mocked-GPU config/scheduling tests + real-gVisor CPU and GPU tests): # The two commands below run these tests as root and as the non-root user ray. docker run --rm --privileged --user root --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/ docker run --rm --privileged --user ray --device nvidia.com/gpu=all ray-cdi-gpu-test:latest \ python3 -m pytest --basetemp=/home/ray/pytest-tmp -v \ /home/ray/anaconda3/lib/python3.10/site-packages/ray/experimental/sandbox/tests/ ``` --------- Signed-off-by: Kevin Klues <[email protected]> Signed-off-by: Philipp Moritz <[email protected]> Co-authored-by: Philipp Moritz <[email protected]> Signed-off-by: Pawel Beza <[email protected]> Cherry-picked-from: c46d1e6 Co-authored-by: Copilot <[email protected]> Copilot-Session: 0baa3cf-af4e-472e-ad89-8f02c6e8be11


Description
Rootless sandboxes map the whole container to one host uid: every file reads as root,
chownto any other user fails withEINVAL, and ownership baked into image layers (postfix's0700uid-101 spool, mailman's uid-38 data) flattens away, so workloads that spread ownership across users fail.A node is now either multi-uid or single-uid, and everything follows that one decision:
detect_idmap()runs once per process. When theuidmappackage's setuidnewuidmap/newgidmaphelpers and/etc/subuid+/etc/subgidranges for the worker user are usable (verified by writing a throwaway namespace's map), the node is multi-uid. Missing helpers, missing ranges,no_new_privs, a probe failure, orRAY_SANDBOX_SINGLE_UID=1make it single-uid, with the reason logged once. There is nosudopath.0 <worker-id> 1plus1 <subbase> <count>(the rootless-Podman model), whatever its network mode. The holder +nsentershape thatnetwork="public"already uses carries the mapping;--netand pasta are added only forpublic. Single-uid nodes wrap onlypublic, exactly as before. Privileged runsc (rootless=False) is untouched..extractedmarker records the layout version and the mapping, so a node that switches modes re-extracts once, and that re-pull keeps the pins of sandboxes already running on the old tree.rm -rfinside a mapped namespace when a plainrmtreeleaves entries behind.Traversing another user's
0700directory as root additionally needsCAP_DAC_OVERRIDE, which Docker's default capability set carries and the barerunsc specdefault does not; documented in troubleshooting. The HTTP service's best-effort/etc/subuidseeding at boot belongs to #65633.Related issues
Follow-up to #65820. Related to #65633.
Additional information
Tested with
TEST_SANDBOX=1in a privilegedrayproject/ray:nightly-py312container on arm64 as the non-rootrayuser, withuidmapinstalled,ray:100000:65536in/etc/subuidand/etc/subgid, and pasta built from source: runtimechownto arbitrary uids inside apublicsandbox and host-visibly on a workdir bind atsubuid_base + uid; the samechownin anetwork="none"sandbox; image-baked ownership (0700uid-101 dir,02710setgid dir) surviving into the sandbox from a local tar image; and the mailman-shaped adduser +chown -R+ setgid inheritance flow. The netns suite (same-port binds, egress and DNS, teardown, failed create) passes alongside, 28 tests in total. Argv-level unit tests pin the multi-uid holder script forpublic,none, andhost, and the cache tests cover ownership recording across layers, the mode-specific marker, mode-switch re-extraction, owner application with mode restore, and eviction.