How to run processes in with limited resources in Linux (no Docker needed)

It's super powerful and simple:

# This will be OOM-killed inside its own namespace
sudo systemd-run --scope -p MemoryMax=100M \
unshare --fork --pid --net --mount-proc \
python3 -c "import os; print(f'My PID: {os.getpid()}'); a = bytearray(200 * 1024 * 1024)"