Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Execution API

A production-ready Code Execution API built with Node.js, Express, and Docker. It supports executing code in C++, Java, Python, and JavaScript.

Features

  • 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

Local Setup

  1. Install Node.js
  2. Clone this repository and navigate to code-runner
  3. Run npm install
  4. 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.

Docker Setup (Recommended)

  1. Build the Docker image:
    docker build -t code-runner .
  2. Run the Docker container:
    docker run -p 3000:3000 code-runner

Railway Deployment Instructions

This repository is fully compatible with Railway.

  1. Push this code to a GitHub repository.
  2. Go to Railway.
  3. Click "New Project" -> "Deploy from GitHub repo".
  4. Select your repository.
  5. Railway will automatically detect the Dockerfile and build/deploy your service.
  6. Once deployed, Railway will expose a public URL for your API.

API Documentation

1. Execute Code

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"
}

2. Health Check

Endpoint: GET /health

Response:

{
  "status": "ok"
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages