© 2025 **Pratipal Kumar Singh
This project is a lightweight Python compiler/runner that executes user-provided code in a safe, sandboxed environment and returns structured output.
It also supports saving results as PNG or JPG images, along with optional Gemini-powered AI features such as:
- Code explanation
- Error debugging
- Smart test-case suggestions
- Code formatting
This system is ideal for internship platforms, coding assessments, training portals, and project-based learning.
- Execute Python code safely
- Capture
stdout,stderr, runtime, and exit codes - Save output as PNG/JPG using Pillow
- Download results as
.txt - Sandbox restrictions: limited resources, isolated execution
- AI Integration (optional)
- Error explanation
- Code enhancement
- Test-case generation
- REST API + CLI support
- Industrial use-case ready
PYTHON-COMPILER-ENGINE/
├─ README.md
├─ LICENSE
├─ requirements.txt
└─ index.html
- Python 3.10+
- pip
- (Optional) Gemini AI API Key
python -m venv .venv # Windows: .venv\Scripts\activate
pip install -r requirements.txtCreate a .env file:
GEMINI_API_KEY=your_key_here
GEMINI_ENDPOINT=https://api.gemini.example/v1
APP_SECRET_KEY=random_string
Never commit .env to GitHub.
python run_code.py --file main.py --save-image output.pngPOST /run
{
"language": "python",
"source": "print('Hello AI Compiler!')",
"save_image": true,
"image_format": "png"
}- Outputs rendered using Pillow
- Monospaced fonts for clarity
- Optionally render in HTML and capture screenshot using headless browser
import requests, os
resp = requests.post(
f"{os.getenv('GEMINI_ENDPOINT')}/v1/assist",
headers={"Authorization": f"Bearer {os.getenv('GEMINI_API_KEY')}"},
json={"prompt": "Explain this Python error: ..."}
)To safely execute untrusted code:
- Use Docker/Firecracker sandbox
- Strict timeouts
- Disable network
- Memory and CPU limits
- Isolate filesystem
- Fork repo
- Create feature branch
- Submit PR
- Ensure tests pass
Released under the MIT License.
© 2025 Pratipal Kumar Singh — All rights reserved where applicable.
For queries or collaborations:
Pratipal Kumar Singh
kumarpratipal123@gmail.com