Just run the generated code inside Docker.
docker build -t python-sandbox .
docker run --rm \
-v "$PWD/script.py:/sandbox/script.py:ro" \
python-sandbox \
python /sandbox/script.py
This works perfectly.
One user. One container. One execution.
Multiple users.
Now you must manage: