Currently, if we try to run a command within a sandbox, we fail with
an unclear error if the program is not installed. This is because our
FileNotFoundError exception handler is never triggered as the program
we run via subprocess is almost always "sh" or "bwrap". Let's make sure
we also check for the actual program we're going to run in the sandbox
and show a clear error if it's not available.
# expect it to pick.
assert nfd == SD_LISTEN_FDS_START + i
+ # First, check if the sandbox works at all before executing the command.
+ if sandbox and (rc := subprocess.run(sandbox + ["true"]).returncode) != 0:
+ log_process_failure(sandbox, cmdline, rc)
+ raise subprocess.CalledProcessError(rc, sandbox + cmdline)
+
+ if subprocess.run(sandbox + ["sh", "-c", f"command -v {cmdline[0]}"], stdout=subprocess.DEVNULL).returncode != 0:
+ die(f"{cmdline[0]} not found.", hint=f"Is {cmdline[0]} installed on the host system?")
+
if (
foreground and
sandbox and