bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Hermetic sandbox doesn't expose basic system binaries and libraries by default.

Open tjgq opened this issue 3 years ago • 4 comments

When using --experimental_use_hermetic_linux_sandbox on Linux, it's impossible to run any executable requiring an interpreter that isn't an explicit input. Most notably, none of #!/bin/sh, #!/bin/bash or #/usr/bin/env bash work, which means none of Bazel's embedded scripts (genrule-setup.sh, test-setup.sh, etc) work.

A trivial genrule or sh_test serves as a repro.

This can be worked around using --sandbox_add_mount_pair to mount additional directories in the sandbox; /bin, /lib and /lib64 appear to be enough for Bash scripts, but this is likely system-dependent.

cc @larsrc-google since we were discussing this today.

tjgq avatar May 11 '23 15:05 tjgq

Note that this might be working as intended, as you might want to mount these directories from an isolated sysroot (like a nix store) rather than your actual system copies.

prasvelagapudiagility avatar Nov 14 '23 14:11 prasvelagapudiagility

IMHO this is working as intended, I think the --experimental_use_hermetic_linux_sandbox CLI docs are quite clear:

If set to true, do not mount root, only mount whats provided with sandbox_add_mount_pair. Input files will be hardlinked to the sandbox instead of symlinked to from the sandbox. If action input files are located on a filesystem different from the sandbox, then the input files will be copied instead.

So, the sandbox is empty and you have to mount what you need.

jjmaestro avatar Aug 21 '24 14:08 jjmaestro

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

github-actions[bot] avatar Oct 26 '25 01:10 github-actions[bot]

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please post @bazelbuild/triage in a comment here and we'll take a look. Thanks!

github-actions[bot] avatar Jan 24 '26 01:01 github-actions[bot]