building a web-based code runner for python & c#

Published: (December 10, 2025 at 05:52 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Cover image for building a web-based code runner for python & c#

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 selected language via a POST request to /run.
  • Wraps the user’s code in a test runner that executes 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 submitted function with the test cases and prints the results.
  • C# – Generates a console app in a temporary folder, runs it via Docker, and captures the output.

Why Docker

Running user code directly on a server is dangerous. Docker provides an isolated sandbox for each execution, preventing any system access or damage. It also makes it straightforward to add more languages later by spinning up different Docker images with the required environment.

What I learned

  • Safe code execution and sandboxing with Docker.
  • Building a Fastify + TypeScript backend.
  • Dynamically generating test runners for multiple languages.
  • Creating a simple, interactive frontend with language‑specific templates.
  • Coordinating backend and 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 × math coding challenges. This code runner will be a core part of the platform, allowing users to:

  • Solve challenges in multiple languages.
  • Get instant feedback via automated test cases.
  • Experiment safely without installing anything locally.

If you’re curious and want early access, join the waitlist: 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 richer editor features.
  • Fully integrate the runner with the MathHacks platform.

Features

  • Run Python and C# functions directly from the browser.
  • Automated test cases with human‑readable pass/fail output.
  • Safe execution inside Docker containers.
  • Built with Fastify for a lightweight API.
  • Interactive frontend with language‑specific templates.

Tools & Technologies

  • Node.js & Fastify – backend API.
  • Docker – sandboxed code execution.
  • TypeScript – type‑safe backend code.
  • HTML/JS – simple interactive frontend.
  • (Optional) React or other frameworks for future UI enhancements.

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

  1. Open http://[::1]:8080 in your browser.
  2. Select the language (Python or C#) from the dropdown.
  3. Write your function code in the editor.
  4. Click Run to see the pass/fail results for the predefined test cases.
Back to Blog

Related posts

Read more »

Code Block Click Copy

I'm a back‑end‑leaning full‑stack developer, and after a long day fixing JavaScript code I decided to add “copy to clipboard” buttons to the code blocks on my s...