Building a remote code execution service is inherently dangerous. Allowing untrusted, anonymous users to submit raw C/C++ code opens the door to catastrophic Remote Code Execution (RCE) vulnerabilities. The Cloud Compiler v2.0 solves this by operating as a distributed system designed for secure, low-latency feedback.
System Architecture & WebSockets
The platform replaces traditional HTTP polling with persistent WebSocket connections, enabling interactive coding (REPL-like behavior) over the web.
- Frontend: Replaced standard textareas with CodeMirror 5 to provide an IDE-grade environment, coupled with Xterm.js for the terminal interface.
- Backend: Powered by Python
aiohttp(AsyncIO). The server streamsstdoutcharacters immediately over the WebSocket, preventing the UI from "hanging" on long-running processes.
Each client connection generates a unique UUID-based session directory. All temporary files are created within this isolated sandbox and are automatically wiped upon disconnection, preventing data leakage between concurrent users.
Execution Engines
Each language runs in a specialized, isolated subprocess on the backend, stripped of sensitive environment variables.
- Python 3 Engine: Code is executed via
python3 -u(unbuffered) to ensure real-time output. The backend environment includespipfor standard library imports. - C / C++ Compiler: Powered by GCC. C++ compiles via
g++ source.cpp -o app -lm -pthread. Explicitly linking against the Math and Threads libraries enables advanced multi-threaded applications. The binary is immediately executed and piped to the socket.
AI Auto-Debug System
The compiler actively monitors the output stream for common error patterns (like Segmentation fault or Traceback). If triggered:
- The client buffers the last 4KB of terminal output.
- The Code + Error Log is routed to Google's Gemini 3.1 Flash Lite model.
- The AI generates a JSON patch containing an explanation and the corrected code, which the user can apply instantly to the CodeMirror editor.