This guide provides instructions for deploying the Python Interpreter Online project securely in a production environment.
The application includes several security measures to prevent abuse:
- Rate Limiting: Limits users to 10 requests per minute to prevent DoS attacks.
- Resource Limiting:
- CPU time limited to 2 seconds per execution
- Memory usage limited to 100MB per execution
- Execution timeout of 3 seconds
- Code Size Limit: Maximum code size is limited to 10KB.
- Restricted Imports: Potentially dangerous modules like
os
,subprocess
, etc. are blocked. - Restricted Operations: Operations like
eval()
,exec()
, and file I/O are blocked. - Docker Containerization: Both frontend and backend are containerized with resource limits.
The simplest way to deploy is using Docker Compose:
# Clone the repository
git clone https://github.com/getGit789/python-interpreter-online.git
cd python-interpreter-online
# Build and start the containers
docker-compose up -d
This will start both the frontend and backend services with appropriate resource limits.
cd backend
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8002 --workers 4
cd frontend
npm install
node server.js
- Reverse Proxy: Deploy behind Nginx or Apache with rate limiting.
- HTTPS: Configure SSL/TLS for secure communication.
- Firewall: Configure a firewall to restrict access to necessary ports only.
- Regular Updates: Keep all dependencies updated to patch security vulnerabilities.
- Monitoring: Set up monitoring for resource usage and suspicious activities.
For production deployment, consider setting these environment variables:
MAX_WORKERS
: Number of worker processes (default: 4)MAX_CODE_SIZE
: Maximum code size in characters (default: 10000)REQUESTS_LIMIT
: Number of requests allowed per time window (default: 10)TIME_WINDOW
: Time window for rate limiting in seconds (default: 60)
For high-traffic scenarios:
- Increase the number of backend workers
- Consider deploying multiple instances behind a load balancer
- Implement a distributed rate limiter using Redis
Common issues:
- If the backend fails to start, check if port 8002 is already in use
- If the frontend can't connect to the backend, verify the API_URL environment variable
- For memory issues, adjust the resource limits in docker-compose.yml