Skip to content

ShindouAris/CodeSandBox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CODESANDBOX

Important

UNIX system ONLY


βš™οΈ System Requirements

To run this project, make sure the following dependencies are installed and available in your system PATH:

Requirement Description
Python 3.12+ Required for backend logic and Python-based modules
G++ Used for compiling and running C++ submissions
GCC Used for compiling C submissions
JAVAC Java compiler (for compiling .java files)
JAVA Java runtime environment (for executing compiled Java code)

Important

πŸ“¦ Install all required packages using your system package manager

For Debian/Ubuntu (APT):

sudo apt update && sudo apt install python3.12 g++ gcc openjdk-17-jdk -y

For Arch Linux / Manjaro (PACMAN):

sudo pacman -Syu python g++ gcc jdk-openjdk

πŸ“‚ FOLDER STRUCTURE

CodeSandBox/
β”œβ”€β”€ Module/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ abstract.py
β”‚   β”œβ”€β”€ cpp.py
β”‚   β”œβ”€β”€ java.py
β”‚   β”œβ”€β”€ python.py
β”‚   └── register.py
β”œβ”€β”€ Route/
β”‚   β”œβ”€β”€ info.py
β”‚   └── submit.py
β”œβ”€β”€ models/
β”‚   └── model.py
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ enums.py
β”‚   β”‚   β”œβ”€β”€ problems.py
β”‚   β”‚   β”œβ”€β”€ random.py
β”‚   β”‚   β”œβ”€β”€ storage.py
β”‚   β”‚   └── sumissions.py
β”‚   β”œβ”€β”€ logger/
β”‚   β”‚   └── logger.py
β”‚   β”œβ”€β”€ safepy/
β”‚   β”‚   └── safeimport.py
β”‚   β”œβ”€β”€ runGuard.py
β”‚   └── tokencompare.py
β”‚
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ .gitignore
β”œβ”€β”€ checker.py
β”œβ”€β”€ main.py
β”œβ”€β”€ readme.md
└── requirements.txt

🐳 Docker Setup

This project includes a fully configured Dockerfile and an optional Docker Compose setup for easy deployment and scaling.


βš™οΈ Dockerfile Overview

Base image: ubuntu:24.04 Default user: lhuser Working directory: /app Exposed port: 8000 Startup command: python3 main.py

The Dockerfile installs and configures everything needed for code execution and judging:

  • gcc, g++ β†’ for compiling C/C++
  • openjdk-21-jdk, openjdk-21-jre-headless β†’ for Java
  • python3-full, python3-pip, python3-venv β†’ for Python
  • curl, git, ca-certificates β†’ basic utilities

Environment Variables:

Variable Description
JAVA_HOME Path to Java installation
PATH Includes both Java and Python virtual env paths

🧱 Docker Compose

A docker-compose.yml file can be used to easily run or scale the judge service.

version: "3.9"

services:
  judge:
    build: .
    container_name: problem_judge
    restart: unless-stopped
    ports:
      - "8000:8000"
    environment:
      - JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
      - PATH=/usr/lib/jvm/java-21-openjdk-amd64/bin:/app/.venv/bin:$PATH
    volumes:
      - .:/app
    command: ["python3", "main.py"]

πŸš€ How to Use

# Build Docker image
docker build -t problem-judge .

# Run container
docker run -d -p 8000:8000 problem-judge

Or with Docker Compose πŸ‘‡

# Build and start
docker compose up -d

# View logs
docker compose logs -f

# Stop everything
docker compose down

⚑ Scaling Example

Wanna simulate multiple judge nodes? Just scale it up:

docker compose up --scale judge=5 -d

🧩 Problem API Endpoints

1️⃣ POST /problem/submit_problem_local

Submit a solution for automatic judging (local problem only).

🧾 Form Data

Field Type Required Description
id string βœ… The submission ID
problem_id string βœ… The problem ID
module string βœ… Programming language used (e.g. python3, c++17, java17, etc.)
file file βœ… The source file to be submitted

1️⃣.5️⃣ POST /problem/submit_problem

Submit a solution with your testcases included in the formdata.

🧾 Form Data

Field Type Required Description
id string βœ… The submission ID
data_test string βœ… The test data for the jugde (see #testcase)
module string βœ… Programming language used (e.g. python3, c++17, java17, etc.)
file file βœ… The source file to be submitted
time_limit_sec int βœ… The time limit for the problem
memory_limit_mb int βœ… The memory limit for the problem

Testcase payload (/submit_problem only)

Basic

{
  "testcases": [
    {
      "input": "hello world",
      "output": "hello world"
    },
    {
      "input": "fastapi is cool",
      "output": "fastapi is cool"
    }
  ]
}

More advanced

{
  "testcases": [
    {
      "input": "Line1\nLine2\nLine3",
      "output": "Line1\nLine2\nLine3"
    },
    {
      "input": "    leading and trailing spaces    ",
      "output": "    leading and trailing spaces    "
    },
    {
      "input": "Tabs\tand\tmultiple\tspaces",
      "output": "Tabs\tand\tmultiple\tspaces"
    },
    {
      "input": "πŸ”₯πŸ’€πŸ₯€πŸš€πŸŒŒ", 
      "output": "πŸ”₯πŸ’€πŸ₯€πŸš€πŸŒŒ"
    },
    {
      "input": "Escaped\\nnewline\\tand tab",
      "output": "Escaped\\nnewline\\tand tab"
    },
    {
      "input": "",
      "output": ""
    }
  ]
}

πŸ“€ Response Examples

βœ… Accepted (AC)

{
  "id": "75ffb5d0-0e9b-47a6-930b-af7922adbd73",
  "problem_name": "donghoso",
  "module_used": "python3",
  "status": "Accepted",
  "message": "All testcases passed",
  "running_time": 0.1576685905456543,
  "usage_memory": 34.8828125
}

❌ Wrong Answer (WA)

{
  "id": "75ffb5d0-0e9b-47a6-930b-af7922adbd73",
  "problem_name": "donghoso",
  "module_used": "python3",
  "status": "WrongAnswer",
  "message": "Expected: 7111111111111111111111111111111111111111111111111, GOT: 71111111111111111111111111111111111111111111111111\n, STDIN: 101 | WrongAnswer on test case 6",
  "running_time": 0.1573479175567627,
  "usage_memory": 34.84375
}

πŸ’€ Runtime Error (RE)

{
  "id": "75ffb5d0-0e9b-47a6-930b-af7922adbd73",
  "problem_name": "donghoso",
  "module_used": "python3",
  "status": "RUNTIME_ERROR",
  "message": "RUNTIME_ERROR on test case 1",
  "running_time": 0,
  "usage_memory": 0
}

🧠 Memory Limit Exceeded (MLE)

{
  "id": "75ffb5d0-0e9b-47a6-930b-af7922adbd73",
  "problem_name": "print_helloworld",
  "module_used": "python3",
  "status": "MEMORY_LIMIT_EXCEEDED",
  "message": "MEMORY_LIMIT_EXCEEDED on test case 1",
  "running_time": 0,
  "usage_memory": 0
}

⏰ Time Limit Exceeded (TLE)

{
  "id": "75ffb5d0-0e9b-47a6-930b-af7922adbd73",
  "problem_name": "print_helloworld",
  "module_used": "python3",
  "status": "TIME_LIMIT_EXCEEDED",
  "message": "TIME_LIMIT_EXCEEDED on test case 1",
  "running_time": 0,
  "usage_memory": 0
}

🧩 Compile Error

{
  "id": "75ffb5d0-0e9b-47a6-930b-af7922adbd73",
  "problem_name": "print_helloworld",
  "module_used": "c++17",
  "status": "COMPILE_ERROR",
  "message": "Compilation command exit with non-zero status",
  "running_time": 0,
  "usage_memory": 0
}

❌ Denied submission

{
    "id": "75ffb5d0-0e9b-47a6-930b-af7922adbd73",
    "problem_name": "donghoso",
    "module_used": "python3",
    "status": "DENIED_SUBMISSION",
    "message": "Traceback (most recent call last):\n  File \"/mnt/d/Code/CodeSandBox/run/1e4d03ad-19fa-4884-90ad-6509053c5f69/main.py\", line 3, in <module>\n  File \"/mnt/d/Code/CodeSandBox/run/1e4d03ad-19fa-4884-90ad-6509053c5f69/safeimport.py\", line 12, in safe_import\nImportError: Import of 'pathlib' not allowed\n| DENIED_SUBMISSION on test case 1",
    "running_time": 0,
    "usage_memory": 0
}

2️⃣ GET /problem/status

Get the current node status (to check if it’s busy or free).

πŸ“€ Response

{
  "status": "IDLE",       // or "BUSY"
  "available_slot": 16,   // number of submissions that can run concurrently
  "max_concurrency": 16   // maximum concurrency supported
}

3️⃣ GET /api/info/problems

Return a list of available problems on this node.

πŸ“€ Response

[
  "print_helloworld",
  "print_input"
]

4️⃣ GET /api/info/languages

Return a list of supported programming languages.

πŸ“€ Response

[
  "python3",
  "c++98",
  "c++11",
  "c++17",
  "c++",
  "java8",
  "java11",
  "java17",
  "java21",
  "java"
]

About

An Judgment Node, written in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published