I wish modern OSes made this easier. I would love to have an easy bullrtproof way of saying "give me a temp directory for writing, don't let me write anywhere else, clean up my directory after me".
I'm sure this is excessive paranoia, but I have never been confident to release a script that classes a directory, I'm to worked about things like subtle differences in how mktemp works on linux and mac for example.
- enter a user and mount namespace
- mount a tmpfs, e.g. over /tmp
- remount everything else as readonly
alternatively firejail --overlay-tmpfs <command>