Repository navigation
[core][sandbox] Start fewer processes per sandbox exec and file write - #67876
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a combine_output option to the sandbox execution backend, allowing stdout and stderr to be returned together as raw bytes in ExecResult.output. It also optimizes the write_file method in the gVisor backend by using GNU install for non-append writes to avoid spawning a shell. However, the review feedback points out that using install -D introduces behavioral regressions, such as destroying symlinks and overwriting existing file permissions (e.g., resetting executable permissions to 0644). It is recommended to revert to the shell-based approach or find an alternative that preserves symlinks and permissions.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
Reviewed by Cursor Bugbot for commit b8ddb1c. Configure here.
b8ddb1c to
90e8fda
Compare
Add opt-in combine_output=True to return stdout and stderr together as raw bytes, avoiding temporary-file/base64 wrappers. Default exec behavior remains unchanged. Use install -D for non-append file writes, reducing sandbox processes from four to one. Fall back to the existing shell path if install fails; append writes keep the existing path. Co-authored-by: Copilot <[email protected]> Copilot-Session: e497cab1-3277-4bd2-9e98-f73d7ddfe20a Signed-off-by: Pawel Beza <[email protected]> Signed-off-by: Pawel Beza <[email protected]>
90e8fda to
c142335
Compare
| "exec", | ||
| "-cwd", | ||
| exec_cwd, | ||
| Non-append writes use tee when possible. The shell fallback creates |
There was a problem hiding this comment.
If you want to improve this going forward, we could ship a small statically linked binary to do this work as part of the Ray wheel (e.g. built via bazel, x86_64 and ARM depending on the wheel architecture), and then invoke it via runsc exec --exec-fd. This would both have the best performance in all cases, and would also have no dependence on any tools installed in the image.
ray-project#67876 added exec's combine_output, which leaves stderr as None and returns the merged bytes in ExecResult.output. The OOM note now goes at the end of output with combine_output, and into stderr without it. ray-project#67688 runs every runsc exec through the launcher's wrap_command, so the unit test's stand-in cgroup no longer passes through _wrap_workload. Signed-off-by: xyuzh <[email protected]>

Description
This PR reduces the work needed to execute commands and write files inside gVisor sandboxes.
combine_output=Truetoexecandexec_async. Stdout and stderr share one pipe, andExecResult.outputcontains the merged raw bytes without UTF-8 decoding. Callers can replace a temporary-file/base64 wrapper with a direct command. The option defaults toFalse; ordinary direct exec still starts one process.teeprocess when the parent directory exists, preserving existing permissions, ownership, symlinks, and hardlinks. Missing directories or unavailableteeuse the existing shell fallback. Append operations retain the existing shell path.Additional information
Median latency over 40 paired runs: