I started this project because I wanted to build mathhacks, a website where you can solve computer science x maths coding challenges. I ended up making a web-based code runner for Python and C# to experiment with safe execution and provide a core tool for the platform.
How It Works
The project consists of a Fastify + TypeScript backend and a simple HTML/JS frontend:
- Frontend
- Users select a language (Python or C#) from a dropdown
- The editor automatically populates a language-specific function template
- Users write their function and click “Run”
- Backend
- Receives the code and language via a POST request to
/run - Wraps the user’s code in a test runner that runs predefined test cases
- Executes the code inside a Docker container to ensure safety
- Returns a human-readable pass/fail output to the frontend
- Test Runners
- Python: dynamically creates a script that calls the function with test cases and prints results
- C#: generates a console app inside a temporary folder, runs it via Docker, and captures the output
This setup allows me to safely run arbitrary code in multiple languages directly from the browser.
Why Docker
Running user code directly on a server is dangerous. Docker allows each code execution to happen in an isolated sandbox, preventing any system access or damage. It also makes it easy to add more languages later by spinning up different Docker images with the necessary environment.
What I Learnt
Building this taught me a lot about:
- Safe code execution and sandboxing with Docker
- Fastify and TypeScript backend development
- Dynamically generating test runners for different languages
- Creating a simple but interactive frontend with templates for each language
- Coordinating backend & frontend to return structured, human-readable output
How I Plan to Use This for Mathhacks
Mathhacks is a website where you can solve computer science x maths coding challenges. This code runner will be a core part of the platform, allowing users to:
- Solve coding challenges in multiple languages
- Get instant feedback on their solutions with automated test cases
- Experiment safely without installing anything locally
If you’re curious and want to try it once early access opens, there’s a waitlist here: Mathhacks Waitlist
The goal is to make learning programming interactive, fun, and safe.
Next Steps
- Add more languages (e.g., JavaScript, Java)
- Allow custom test cases per challenge
- Improve frontend UX with syntax highlighting and better editor features
- Integrate fully with the Mathhacks platform
Check it out on GitHub:
VulcanWM
/
code-runner
A web-based code runner for Python and C# that executes user-defined functions against predefined test cases using Docker, with a dynamic web interface for easy testing and learning.
Code Runner
A simple web-based code runner supporting Python and C# using Docker, built with Fastify for the API and modern frontend technologies.
Features
- Run Python and C# functions directly from the browser
- Automated test cases
- Human-readable pass/fail output
- Safe execution inside Docker containers
- Built with Fastify for fast, lightweight API handling
- Interactive frontend with language-specific templates
Tools & Technologies
- Node.js and Fastify for the backend API
- Docker for safe code execution and sandboxing
- TypeScript for type-safe backend code
- HTML/JS for a simple, interactive frontend
- Optional: React or other frontend frameworks for future improvements
Requirements
- Docker installed
- Node.js >= 20
- npm or yarn
Installation
git clone https://github.com/VulcanWM/code-runner.git
cd code-runner
npm install
Running the Server
npm start
# The server will run on http://[::1]:8080
Usage
- Open
http://[::1]:8080in your browser - Select the language (Python or C#) from the dropdown
- Type your function code in the editor
- Click Run to see the…
Top comments (0)