A browser-based Python runtime platform that gives each user an isolated Kubernetes container, persistent filesystem state, and interactive stdin support.
Features β’ Screenshots β’ Tech Stack β’ Project Structure β’ Installation and Setup β’ Environment Variables β’ API Endpoints β’ How It Works β’ Known Limitations
PyRuntime Forge lets users register, log in, and run Python code inside their own Kubernetes pod.
The current execution model is:
command_to_exec = ["python", "-c", command]So the platform is:
- filesystem-stateful
- container-stateful
- not Python-RAM-stateful across separate executions
This means:
- files created in a user's pod remain available between runs
- interactive programs using
input()now work through the browser UI - Python variables such as
x = 10do not survive a new click onExecute
- Per-user isolated Python runtime in Kubernetes
- User registration and login backed by MongoDB Atlas
- Python code execution directly from the browser
- Interactive stdin support for
input()-based programs - Streaming stdout and stderr output using Socket.IO
- Persistent filesystem inside the user's pod
- File-based data science workflows across multiple executions
- Pre-built user pod image with NumPy, Pandas, scikit-learn, and Matplotlib
- Test-case suite for validating project behavior
- Documentation comparing PyRuntime Forge with Jupyter
Users can switch between sign up and login from the same page.
After login, users can execute Python code and send stdin when the running program calls input().
| Layer | Technology |
|---|---|
| Backend | Python 3.9+, Flask, Flask-SocketIO, Eventlet |
| Frontend | HTML, CSS, JavaScript, Socket.IO client |
| Database | MongoDB Atlas |
| Orchestration | Kubernetes on Docker Desktop |
| Runtime Isolation | Per-user Kubernetes Deployment + Pod |
| User Pod Image | jupyter/datascience-notebook:latest |
| Custom Pod Base | python:3.9-slim with NumPy, Pandas, scikit-learn, Matplotlib (see Dockerfile) |
| Execution Model | python -c "<submitted code>" inside the user container |
| Configuration | .env with python-dotenv |
| Test Assets | Ready-to-run Python scripts in test-cases/ |
| Documentation | Markdown docs in docs/ |
PyRuntimeForge/
βββ docs/
β βββ jupyter-vs-pyruntime-forge.md # Comparison: PyRuntime Forge vs Jupyter
βββ screenshots/
β βββ Login_page.png
β βββ Main.png
β βββ Signup_Page.png
βββ templates/
β βββ index.html # Single-page frontend (auth + code console)
βββ test-cases/
β βββ README.md # How to run the test cases
β βββ data_science_demo_step1.py # Saves a CSV dataset to the pod
β βββ data_science_demo_step2.py # Loads and summarises the saved dataset
β βββ filesystem_statefulness_step1.py
β βββ filesystem_statefulness_step2.py
β βββ interactive_guess_game.py # Tests interactive stdin support
β βββ ram_statefulness_step1.py
β βββ ram_statefulness_step2.py
βββ .env # MongoDB URI (not committed)
βββ .gitignore
βββ Dockerfile # Flask server image (used by Render)
βββ pod.Dockerfile # Custom user-pod image (Python 3.9-slim + data science libs)
βββ LICENSE
βββ README.md
βββ requirements.txt # Server-side Python dependencies
βββ server.py # Flask + Socket.IO backend
The Dockerfile defines a lightweight custom image for user pods:
FROM python:3.9-slim
RUN pip install --no-cache-dir numpy pandas scikit-learn matplotlibIt is an alternative to jupyter/datascience-notebook:latest if you want a smaller image without the full Jupyter stack. To use it, build and push it to a registry, then replace the image value in the deployment manifest inside server.py.
Make sure you have:
- Python 3.9 or newer
- Docker Desktop installed
- Kubernetes enabled in Docker Desktop
- A MongoDB Atlas cluster
- Your current public IP allowed in Atlas network access
git clone <your-repository-url>
cd PyRuntimeForgepython3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtThis installs Flask, Flask-SocketIO, Eventlet, PyMongo, the Kubernetes client, and python-dotenv.
kubectl config current-context
kubectl get nodesExpected context:
docker-desktop
See the next section for the exact format.
python server.pyDefault URL:
http://127.0.0.1:5000
On some macOS systems, AirPlay / Control Center already uses port 5000.
If that happens, run:
python -c "import server; server.socketio.run(server.app, debug=True, port=5001)"Then open:
http://127.0.0.1:5001
Create a .env file in the project root:
MONGODB_URI="mongodb+srv://<username>:<password>@<cluster>/<database>?retryWrites=true&w=majority&appName=Cluster0"Current database usage in the code:
- database:
cloud - collection:
users
Example:
MONGODB_URI="mongodb+srv://user:password@cluster0.example.mongodb.net/cloud?retryWrites=true&w=majority&appName=Cluster0"Loads the frontend UI.
Registers a user, stores that user in MongoDB Atlas, and creates a per-user Kubernetes deployment.
Example request:
{
"username": "alice",
"email": "alice@example.com"
}Example response:
{
"message": "User alice registered successfully."
}Looks up the user by email and returns the sanitized container identifier.
Example request:
{
"email": "alice@example.com"
}Example response:
{
"container_id": "alice"
}execute_commandStarts Python execution inside the user's pod.send_stdinSends one input line to the running process.
command_startedSignals that execution has started.command_outputStreams stdout and stderr back to the browser.command_completeSignals that execution has finished.
flowchart TD
A["User opens PyRuntime Forge"] --> B["Register or Login"]
B --> C["Flask server validates user"]
C --> D["MongoDB Atlas stores / fetches user"]
C --> E["Kubernetes creates or finds user pod"]
E --> F["User submits Python code from browser"]
F --> G["Backend opens exec session in the user's pod"]
G --> H["python -c runs the submitted code"]
H --> I["stdout / stderr streamed back through Socket.IO"]
I --> J["UI renders output in the console"]
H --> K{"Program uses input()?"}
K -- Yes --> L["User types in stdin box"]
L --> M["Frontend emits send_stdin"]
M --> H
K -- No --> I
sequenceDiagram
participant U as User
participant UI as Browser UI
participant S as Flask + Socket.IO Server
participant DB as MongoDB Atlas
participant K as Kubernetes API
participant P as User Pod
U->>UI: Open app
UI->>S: GET /
S-->>UI: Render page
U->>UI: Register
UI->>S: POST /register
S->>DB: Insert user
S->>K: Create deployment
K-->>S: Deployment created
S-->>UI: Registration success
U->>UI: Login
UI->>S: POST /login
S->>DB: Find user
DB-->>S: Return container_id
S-->>UI: Login success
U->>UI: Submit Python code
UI->>S: execute_command
S->>K: Find pod by label
K-->>S: Pod name
S->>P: exec python -c "submitted code"
P-->>S: stdout/stderr
S-->>UI: command_output
alt input() is called
U->>UI: Type reply in stdin box
UI->>S: send_stdin
S->>P: write to stdin
P-->>S: more output
S-->>UI: command_output
end
P-->>S: process exits
S-->>UI: command_complete
PyRuntime Forge remembers:
- files saved in the container
- datasets downloaded inside the pod
- generated CSV files, plots, and outputs written to disk
PyRuntime Forge does not remember:
- Python variables between separate
Executeclicks - in-memory pandas dataframes between separate runs
- imported modules in RAM between separate runs
Example:
Execution 1:
x = 12345
print("Stored x =", x)Execution 2:
print(x)Result:
NameError: name 'x' is not defined
This is expected because every execution starts a fresh Python process.
- No password authentication. Registration requires only a username and email. This is intentional for a demo/sandbox environment; do not use this in production without adding proper password hashing and session management.
- No RAM statefulness. Each
Executeclick runspython -c, which starts a fresh interpreter. Python variables and imported modules are not preserved between clicks. Use file I/O to pass data between executions. - Pod startup delay. When a user registers for the first time, Kubernetes must pull the container image. The first execution may fail or stall until the pod reaches the
Runningstate. Check pod status withkubectl get pods. - Single namespace. All user pods are deployed to the
defaultnamespace. Usernames must be unique and are sanitized to valid Kubernetes resource names (lowercase alphanumeric and hyphens only). - No resource limits. The deployment manifest does not set CPU or memory limits on user pods. In a production deployment, resource quotas should be configured.
kubectl cluster-info
kubectl get nodeskubectl get deployments
kubectl get pods
kubectl get pods -o widekubectl describe pod <pod-name>kubectl exec -it <pod-name> -- /bin/bashIf bash is unavailable:
kubectl exec -it <pod-name> -- /bin/shkubectl delete deployment <username>-deploymentAdditional documentation:
Runnable test cases:
- test-cases/README.md
- test-cases/filesystem_statefulness_step1.py
- test-cases/filesystem_statefulness_step2.py
- test-cases/ram_statefulness_step1.py
- test-cases/ram_statefulness_step2.py
- test-cases/interactive_guess_game.py
- test-cases/data_science_demo_step1.py
- test-cases/data_science_demo_step2.py
This project is licensed under the MIT License β see the LICENSE file for details.
Prashant Agrawal
β If you find this project useful, please give it a star! β


