A production-ready Code Execution API built with Node.js, Express, and Docker. It supports executing code in C++, Java, Python, and JavaScript.
- Language Support: C++, Java, Python, JavaScript
- Security:
- 5-second execution timeout
- 50 KB maximum payload size
- Prevents command injection via
child_process.execFile - Automatic temporary file cleanup
- Install Node.js
- Clone this repository and navigate to
code-runner - Run
npm install - Run
npm run dev
Note: For C++, Java, and Python execution to work locally, you need g++, javac, java, and python3 installed on your machine and accessible in your PATH.
- Build the Docker image:
docker build -t code-runner . - Run the Docker container:
docker run -p 3000:3000 code-runner
This repository is fully compatible with Railway.
- Push this code to a GitHub repository.
- Go to Railway.
- Click "New Project" -> "Deploy from GitHub repo".
- Select your repository.
- Railway will automatically detect the
Dockerfileand build/deploy your service. - Once deployed, Railway will expose a public URL for your API.
Endpoint: POST /execute
Request Body:
{
"language": "python",
"code": "print('Hello, World!')"
}Supported Languages: cpp, c++, java, python, python3, javascript, js, node
Success Response:
{
"success": true,
"output": "Hello, World!\n",
"error": ""
}Error Response:
{
"success": false,
"output": "",
"error": "SyntaxError: invalid syntax"
}Endpoint: GET /health
Response:
{
"status": "ok"
}