The newest Claude update comes with a python sandbox built right into the API for exactly this reason.
https://docs.anthropic.com/en/docs/agents-and-tools/tool-use...