A lightweight, secure, and efficient code execution engine designed to run user-submitted code inside isolated Docker containers. Perfect for online judges, code battles, and learning platforms.
┌────────────────────────┐
│ Frontend UI │
│ (Code Battle App) │
└──────────┬─────────────┘
│
▼
┌────────────────────────┐
│ Backend API Server │
│ (Handles Submission) │
└──────────┬─────────────┘
│ Push JSON job
▼
┌────────────────┐
│ Redis Queue │ ◄────── Push job to `submit`
└────────────────┘
│
▼
┌──────────────────────────────────────────┐
│ Code Execution Service (Worker) │
│ ▸ Reads from Redis `submit` queue │
│ ▸ Extracts code, input, language, etc. │
│ ▸ Creates files inside /submissions │
│ ▸ Calls Docker container to execute code │
│ ▸ Compares output with test cases │
│ ▸ Pushes result to `result` queue │
└──────────────────────────────────────────┘
│
▼
┌────────────────┐
│ Redis Queue │
│ `result` │
└────────────────┘
│
▼
┌────────────────────────┐
│ Leaderboard / │
│ Result Display │
└────────────────────────┘
---
code-execution-service/
├── node_modules/
├── outputs/ # Execution outputs
├── submissions/ # Code submission files
├── index.js # Main entry point (worker)
├── package.json # Node.js dependencies
├── Container-logic/
│ └── App/
│ ├── engine # Execution logic (inside Docker)
│ └── dockerfile # Docker image setup
git clone https://github.com/yourusername/code-execution-service.git
cd code-execution-serviceMake sure Docker is installed and running, then pull the prebuilt image:
docker pull ayushgupta712005/judge-runner:latestcode .From inside the code-execution-service directory, run the container:
docker run -d --name judge-python \
-v ${PWD}/submissions:/app/submissions \
-v ${PWD}/outputs:/app/outputs \
ayushgupta712005/judge-runner:latest✅ This:
- Mounts
submissionsandoutputsto the container - Runs the image in background mode
You can either start Redis locally or use Docker:
docker run -d --name redis -p 6379:6379 redisYou can push this JSON payload using redis-cli or a GUI like RedisInsight:
{
"language": "java",
"input": "import java.util.*;\npublic class Main\n{ \n\tpublic static void main(String[] args) {\n\t\tScanner s=new Scanner(System.in);\n\t\tString str=s.nextLine();\n\t\tSystem.out.println(isValid(str));\n\t}\n\t public static boolean isValid(String s) {\n int i = -1;\n char[] stack = new char[s.length()];\n for (char ch : s.toCharArray()) {\n if (ch == '(' || ch == '{' || ch == '[')\n stack[++i] = ch;\n else {\n if (i >= 0\n && ((stack[i] == '(' && ch == ')')\n || (stack[i] == '{' && ch == '}')\n || (stack[i] == '[' && ch == ']')))\n i--;\n else\n return false;\n }\n }\n return i == -1;\n }\n}",
"TestCase": [
{ "input": "()", "output": "true", "isHidden": false },
{ "input": "()[]{}", "output": "true", "isHidden": false },
{ "input": "(]", "output": "false", "isHidden": true }
],
"id": "2134516",
"timeLimit": 500
}From the root directory (code-execution-service), run:
node index.jsThis script:
- Reads from the Redis
submitqueue - Executes code using the Docker container
- Compares output with test cases
- Pushes result to a
resultqueue
{
"id": "2134516",
"status": "Passed",
"passedTestCases": 2,
"totalTestCases": 3,
"timeTaken": "420ms"
}👉 ayushgupta712005/judge-runner
Open to feature improvements (e.g., multi-language support, better test case diffing, etc.) via PRs or suggestions!