The sandboxed build was failing, because it relied heavily on /usr/bin/env. This is fixed with a lot of shebang patching (both to system packages and to sage-internal packages).