techx-runner
A tiny, zero-dependency Node.js server that compiles and runs Java and C++ on the user's own machine, so a browser-based coding judge can execute code without a cloud sandbox. It listens on 127.0.0.1 only.
It was built for TechX, an interview-prep platform for C-DAC Mumbai students, and is published separately so its security model can be reviewed on its own.
Why
A web page cannot compile or run code. Hosted judges solve that with a farm of sandboxes, which costs money and operations time. This project takes the other route: the student's laptop already has a JDK and g++, so a small local bridge lets the web app use them. The web app gets a verdict immediately, and a separate trusted machine can re-run accepted submissions with the same judge() function (it is exported, see Use as a library).
Goals: Windows first (paths with spaces, taskkill /T, CRLF output), very low RAM, no admin rights, nothing running while unused.
Architecture
flowchart LR
B["Web app in browser<br/>(allow-listed origin)"] -- "fetch http://127.0.0.1:7324<br/>/health /run /judge" --> R["techx-runner<br/>(Node, loopback only)"]
R -- "javac / g++ once" --> C[Compiler]
R -- "run per input, one at a time" --> P["Student program<br/>(child process, time limit, output cap)"]
O["OS on-demand starter<br/>techx-runner:// handler / systemd socket / LaunchAgent"] -. "starts on first use,<br/>runner exits after 15 idle min" .-> R
/judge compiles once, runs the program on each input in order, and stops at the first runtime error or time-out. It never compares output to an expected answer; the caller owns that.
Security model
Threat: a user has the runner up and visits a malicious web page. That page can send requests to http://127.0.0.1:7324. Without defences it could make the runner compile and run arbitrary native code ("drive-by" code execution), or use DNS rebinding to look same-origin.
Mitigations, all in techx-runner.mjs:
- Loopback bind. The server listens on
127.0.0.1, not on all interfaces. The systemd socket unit is also 127.0.0.1:7324.
- Host allow-list. The
Host header must be exactly localhost:<port> or 127.0.0.1:<port>; anything else gets 403. This blocks DNS rebinding.
- Origin allow-list. If a request carries an
Origin header (browsers send it on cross-site requests) and it is not on the list, it is refused with 403 before any work is done, so a "simple" cross-site POST cannot execute code even though CORS would hide its response. Requests with no Origin (curl, the campus verifier) are accepted: the runner trusts the local user, not other websites.
- No CORS wildcard.
Access-Control-Allow-Origin echoes the single allowed origin (with Vary: Origin); it is never *. Access-Control-Allow-Private-Network: true is sent only for allowed origins.
- Serialized runs. One compile/run executes at a time, so a double-click cannot start two JVMs.
- Limits. Request body 512 KB; 1 to 50 string inputs per
/judge; 1 MB of stdout/stderr per run (shared across the inputs of a /judge, minimum 64 KB each); per-input time limit clamped to 10 s (Java gets 2x because JVM start counts); compile timeout 30 s.
- Process-tree kill. On timeout the child and everything it spawned are killed (
taskkill /pid <pid> /T /F on Windows, kill(-pid) on the process group elsewhere).
- Temp directory per request, deleted afterwards.
What it is not: a sandbox. Submitted code runs as the user who started the runner, with that user's file and network access. The model protects the user from other websites, not from code they choose to run themselves. Any local process can call the runner (there is no token), because it trusts the local machine.
Report vulnerabilities privately, see SECURITY.md.
Install and usage
Requires Node.js 18+ and a JDK and/or g++/clang++ on the machine.
npm install -g techx-runner
techx-runner # run in this terminal on 127.0.0.1:7324
techx-runner --install # start on demand from now on (current user, no admin)
techx-runner --uninstall # undo --install
techx-runner --idle-exit 15 # exit after 15 minutes without requests
techx-runner --version
Or without installing: npx techx-runner. The port can be changed with env PORT (default 7324); the on-demand units are fixed to 7324.
On-demand start per OS
--install stores absolute paths to node and the CLI, so re-run it after moving Node (nvm, reinstall). The on-demand runner exits after 15 idle minutes.
| OS |
Mechanism |
Status |
| Windows |
Registers a techx-runner:// URL handler under HKCU\Software\Classes (no admin). The web app opens that link when the runner is not up; the command runs through conhost.exe --headless so no window flashes. The browser asks once; tick "Always allow". |
Primary platform, used in development |
| Linux |
systemd user socket techx-runner.socket (127.0.0.1:7324); systemd starts the service on the first connection and hands over the socket as fd 3. Records PATH and JAVA_HOME. |
Unit generation is unit-tested; not yet run on real Linux machines |
| macOS |
LaunchAgent in.techx.runner that starts the runner at login (Node cannot adopt launchd sockets), so after an idle exit run techx-runner again. |
Plist generation is unit-tested; not yet run on real macOS machines |
HTTP API
All responses are JSON. Base URL http://127.0.0.1:7324.
GET /health
Returns runner version and detected compilers. ?refresh=1 re-probes (picks up a JDK installed after the runner started).
curl "http://127.0.0.1:7324/health?refresh=1"
# {"status":"ok","version":"0.3.0","platform":"win32","arch":"x64","compilers":{"java":{...},"cpp":{...}}}
POST /run (one input)
curl -X POST http://127.0.0.1:7324/run -H "Content-Type: application/json" \
-d '{"language":"cpp","code":"#include <iostream>\nint main(){int a,b;std::cin>>a>>b;std::cout<<a+b;}","input":"15 25\n"}'
# {"status":"accepted","stdout":"40","stderr":"","durationMs":3,"exitCode":0}
status is accepted (ran to completion), compilation_error, runtime_error or time_limit_exceeded.
POST /judge (compile once, run 1 to 50 inputs)
Body: language ("java" or "cpp"), code, inputs (array of 1 to 50 strings), optional timeLimitMs, optional memoryLimitMb (Java heap, clamped 32 to 1024, default 256).
curl -X POST http://127.0.0.1:7324/judge -H "Content-Type: application/json" \
-d '{"language":"java","code":"import java.util.*; class Main { public static void main(String[] a){ Scanner s=new Scanner(System.in); System.out.println(s.nextInt()*2); } }","inputs":["1\n","2\n","3\n"],"timeLimitMs":1000}'
# {"status":"completed","outputs":["2\n","4\n","6\n"],"stderr":"","failedIndex":null,"maxDurationMs":41,"exitCode":0}
| Field |
Meaning |
status |
completed, compilation_error, runtime_error, time_limit_exceeded |
outputs |
stdout for each input run so far (stops at the first failure) |
failedIndex |
index of the failing input, else null |
maxDurationMs |
slowest run |
stderr |
compiler output, runtime stderr, or a time-limit message |
exitCode |
process exit code (124 on time-out) |
A timed-out input is retried once before being reported, to absorb start-up spikes (for example antivirus scanning a new .exe). Java class names need not be Main: the public class names the file, the class declaring main() is run, and a package line is honoured.
Errors: 400 bad payload, 403 Host/Origin refused, 404 unknown route, 413 body too large, 500 internal error.
Use as a library
import { judge, getCompilers } from 'techx-runner';
const compilers = await getCompilers();
const r = await judge({ language: 'cpp', code, inputs: ['1\n'], timeLimitMs: 1000, compilers });
judge() also accepts env (the environment for child processes; omit to inherit) and maxOutputBytes. techx-runner/compiler-discovery.mjs exports detectCompilers.
Configuration
| Env var |
Effect |
PORT |
Listen port (default 7324) |
TECHX_ALLOWED_ORIGINS |
Comma-separated list that replaces the default allowed origins |
TECHX_JAVA |
Path to a javac to prefer |
TECHX_CXX / CXX |
Path to a C++ compiler to prefer |
JAVA_HOME |
Searched for javac |
Compiler discovery checks the override, JAVA_HOME, PATH and standard JDK directories and picks the best supported version. A C++ compiler is only accepted if it really builds and runs a probe program.
Add an allowed origin
The default list (DEFAULT_ALLOWED_ORIGINS in techx-runner.mjs) is https://shilbhushan-khanderao.github.io plus localhost and 127.0.0.1 on ports 5173 and 4173. For your own front end, set TECHX_ALLOWED_ORIGINS="https://my.site,http://localhost:3000" (it replaces the defaults) or edit the constant. Origins match exactly: scheme, host and port, no trailing slash.
Memory
Figures measured on Windows while developing the TechX platform (not a benchmark suite):
- Idle runner: about 27 to 31 MB private memory.
- A Java run: about 55 MB with
-Xms16m (the default initial heap commits about 300 MB).
- Student Java runs with
-Xms16m -Xmx<limit>m -Xss32m -XX:+UseSerialGC -Dfile.encoding=UTF-8.
javac runs with -J-Xmx256m -J-XX:+UseSerialGC -J-XX:TieredStopAtLevel=1 -encoding UTF-8, plus --release 21 when the installed JDK is newer than 21.
- C++ is built with
-O2 -Wall -std=<best of c++20/17/14>, plus -static on Windows (avoids a mismatched libstdc++-6.dll from another toolchain on PATH).
Supported compilers
compiler-support.json is the single source of truth, with three tiers: tested (listed), untested (at or above the minimum but not listed: allowed, with a warning in /health), and unsupported (below the minimum, or MSVC cl.exe / unknown flavors: refused with an install hint).
|
Minimum |
Tested |
| JDK |
11 |
11, 17, 21 |
| g++ |
9 |
9 to 16 |
| clang++ |
10 |
10 to 18 |
| Apple clang |
12 |
12 to 17 |
To add a new major: install it, run the tests, append it to tested in the JSON and update reviewedOn.
Development
npm install
npm test # vitest; starts servers on ports 7397 to 7399; needs a JDK and g++ for the execution tests
npm pack --dry-run
Do not run two copies of the suite at once (fixed ports). CI runs on Windows, macOS and Ubuntu with Node 18 and 22. A release is a v<version> tag matching package.json; the publish workflow runs the tests, then npm publish --provenance.
License
MIT (c) 2026 Shilbhushan Khanderao