This API lets clients send a Python script that defines main(). The script is executed inside a locked down nsjail environment with:
- Limited CPU and memory
- A restricted filesystem
- No network access
After execution, the service returns:
- result: the JSON serializable return value of main()
- stdout: anything printed by the script
- Docker
- Poetry (for local development)
Run the container:
docker-compose up --buildThe app will be available at http://localhost:8080
Local (docker-compose port 8080):
curl -X POST http://localhost:8080/execute \
-H 'Content-Type: application/json' \
-d '{"script": "def main():\n return 42"}'Production:
curl -X POST https://safe-python-executor-538469180276.us-central1.run.app/execute \
-H 'Content-Type: application/json' \
-d '{"script": "def main():\n return 42"}'Reference TEST_CASES.md file to test with different request bodies.
The production API is available at:
https://safe-python-executor-538469180276.us-central1.run.app/execute
GET /- Returns a hello messageGET /health- Health check endpointPOST /execute- Execute a Python script