I’ve created a tool for similar of use-cases: https://codeberg.org/contr/contr
You could run your workload inside, say, an alpine container:
<pre style="background-color:#ffffff;">
<span style="color:#323232;">cd path/to/evil/dir
</span><span style="color:#323232;">contr alpine
</span><span style="color:#323232;">❯ # inside container, run dangerous program
</span><span style="color:#323232;">❯ ./dangerous_program
</span>
If the program needs extra dependencies, you’ll have to write a Containerfile and build an image with the dependencies installed – there’s an example in the repository. Just installing the dependencies at runtime inside the container is also an option, but all changes inside the container are lost on exit.