$ show radian-software/python-in-a-box
This repository implements a simple online Python REPL (Read-Eval-Print Loop) as a web application. The frontend consists of a single HTML file that uses Xterm.js to render a terminal interface and connects to a WebSocket endpoint for real-time communication. The backend is a Node.js server built with Express and express-ws that, upon WebSocket connection, spawns a Python 3 process via node-pty and facilitates bidirectional communication between the browser and the process. The application is designed as a proof of concept and includes a session timeout of one hour to limit resource usage. The architecture is straightforward: the frontend handles user input and display, while the backend manages the execution environment. The codebase is notable for its minimalism, with the frontend requiring approximately 13 lines of JavaScript and the backend approximately 17 lines (as noted in the README). This simplicity makes the core patterns highly reusable for similar terminal-in-the-browser applications. However, the Dockerfile included in the repository contains references to future Ubuntu and Node.js versions, which may indicate aspirational or placeholder content and could pose challenges for immediate deployment.
The LLM identified 2 files worth highlighting for reuse:
A self-contained HTML file that implements a terminal emulator using Xterm.js and WebSocket. It connects to a WebSocket endpoint, handles resize events, and displays terminal output. The component is reusable with any backend that follows the simple WebSocket protocol of sending and receiving strings.
A minimal Express.js server that serves a static HTML page and provides a WebSocket endpoint to interact with a pseudo-terminal. Upon connection, it spawns a child process (by default, Python 3) and pipes data between the WebSocket and the process's stdin/stdout. The pattern is reusable for any command-line process by changing the spawn arguments.