System Architecture
Runtime is a secure code execution API service built with Spring Boot that runs user-submitted code snippets in isolated Docker containers. The system supports multiple programming languages and enforces strict resource limits to ensure security and stability.Core Components
The architecture consists of three main layers:API Layer
RESTful endpoints built with Spring Boot that handle incoming code execution requests
Execution Engine
Language-specific executors that prepare and manage code execution in Docker containers
Docker Runtime
Isolated container environment where code is compiled and executed
Request Flow
Here’s how a code execution request flows through the system:Component Breakdown
ExecutionController
The entry point for all code execution requests. Location:ExecutionController.java:22-26
ExecutionService
Orchestrates the execution process by delegating to the appropriate language executor. Location:ExecutionService.java:13-17
CodeExecutor
Manages language-specific executors using a strategy pattern. Location:CodeExecutor.java:16-22
DockerExecutorUtil
Handles all Docker interactions including container creation, execution, and cleanup. Location:DockerExecutorUtil.java:24-35
Supported Languages
The system supports five programming languages, each with its own Docker image and execution command:Java
Java
Docker Image:
eclipse-temurin:17Execution: Compiles with javac and runs with javaFile Naming: Extracts class name from public class ClassName patternPython
Python
Docker Image:
python:3.11Execution: Runs directly with python main.pyFile Name: main.pyC
C
Docker Image:
gcc:latestExecution: Compiles with gcc and executes binaryFile Name: main.cC++
C++
Docker Image:
gcc:latestExecution: Compiles with g++ and executes binaryFile Name: main.cppJavaScript
JavaScript
Docker Image:
node:18Execution: Runs with node main.jsFile Name: main.jsResource Management
Every Docker container is created with strict resource limits to prevent abuse:These resource limits ensure fair usage and prevent individual executions from consuming excessive system resources.
Execution Lifecycle
- Temporary Directory Creation - A unique directory is created for each execution
- File Writing - Code is written to an appropriate file (e.g.,
Main.java,main.py) - Container Creation - Docker container is created with language-specific image
- Container Start - Container starts and executes the compilation/run command
- Output Capture - Both stdout and stderr are captured
- Container Cleanup - Container is removed immediately after execution
- Directory Cleanup - Temporary directory is deleted
Next Steps
Docker Execution
Learn how Docker-based code execution works in detail
Security Features
Understand the security and isolation mechanisms