scap/sh.py is a copy of https://amoffat.github.io/sh/ . It is a nice syntax sugar to execute commands, pipe them etc. Unfortunately it is also a reimplementation from scratch of subprocess. @hashar encountered at least two issues with it: one with stream output not being properly captured and an annoying bug attempting to blindly close a million or file descriptors (T204762).
If at all possible, we should revisit our use of scap/sh.git and if it is not too much work, drop it in favor of subprocess.