python client_test_code_exe.py
If you get error, check if the server is running by https://6bd2-89-213-179-161.ngrok-free.app.
Note: Replace the url to yours if you want to test your own server.
A FastAPI server that executes Python code remotely with public access via ngrok.
- Python 3.7+
- ngrok account (free)
pip install fastapi uvicorn pyngrok requests numpyexport NGROK_AUTH_TOKEN="your_token_here"# Terminal 1
caffeinate -i python local_code_executor/local_server.py
# Terminal 2
caffeinate -i ngrok http 8000 --region=euAfter starting, you'll get:
- Local:
http://localhost:8000 - Public:
https://xxxxx.ngrok-free.app(shown in terminal) - API Docs: Add
/docsto either URL
Via curl:
curl -X POST https://your-ngrok-url.ngrok-free.app/execute_code \
-H "Content-Type: application/json" \
-d '{"code": "result = 2 + 2\nprint(result)"}'Via Python:
import requests
url = "https://your-ngrok-url.ngrok-free.app/execute_code"
response = requests.post(url, json={"code": "import numpy as np\ndata = np.array([1,2,3])\nresult = data.mean()"})
print(response.json())- Keep laptop awake:
caffeinate -iprevents sleep but allows screen to turn off - EU region works best if US region fails
- Both server and ngrok must run for public access
- Public URL changes each time you restart ngrok
Press Ctrl+C in the terminal running the server.
This server executes arbitrary Python code. Only use in trusted environments.