Security Model
Runtime is designed with security as a primary concern. Every code execution runs in a completely isolated Docker container with strict resource limits and automatic cleanup to prevent abuse and system compromise.Isolation Layers
The system implements multiple layers of isolation:Container Isolation
Each execution runs in a separate Docker container, providing process and filesystem isolation
Temporary Filesystem
Code is written to unique temporary directories that are deleted after execution
Container Isolation
Fresh Container Per Execution
Every code execution creates a brand new Docker container. Location:DockerExecutorUtil.java:51-58
Containers are ephemeral - they exist only for the duration of code execution and are immediately destroyed afterward.
Container Lifecycle
Location:DockerExecutorUtil.java:62-87
Resource Limits
Memory Limit: 128MB
Each container is limited to 128MB of RAM.Why 128MB?
Why 128MB?
128MB is sufficient for most code snippets while preventing memory-intensive attacks:
- Prevents infinite array allocations
- Limits recursive function call depth
- Stops memory leak exploits
- Protects host system memory
CPU Limit: 0.5 Cores
Each container is limited to half a CPU core.CPU Limit Calculation
CPU Limit Calculation
Docker measures CPU in nanoseconds:
- 1 CPU core = 1,000,000,000 nanoseconds
- 0.5 cores = 500,000,000 nanoseconds
- 0.1 cores = 100,000,000 nanoseconds
- Infinite loops from consuming all CPU
- CPU-intensive cryptomining attempts
- Fork bomb attacks
Resource Limit Enforcement
Filesystem Isolation
Temporary Directories
Each execution gets a unique temporary directory on the host. Location:DockerExecutorUtil.java:41-43
Example Directory
Volume Binding
The temporary directory is mounted read-write into the container.Only the specific temporary directory is accessible inside the container. The rest of the host filesystem is isolated.
Automatic Cleanup
Temporary directories are deleted after execution completes. Location:DockerExecutorUtil.java:88
DockerExecutorUtil.java:143-149
No Persistence: Code and execution artifacts are never stored permanently. Each execution is stateless.
Process Isolation
Working Directory
All code execution happens in the/code directory inside the container.
- Code cannot access system directories
- Compiled binaries are contained
- Output files are isolated
User Permissions
Containers run with default Docker user permissions (typically root inside the container, but isolated from host).Network Isolation
No Network Access
By default, containers are created without network capabilities.The absence of network configuration means containers cannot:
- Make outbound HTTP requests
- Download additional packages
- Communicate with external services
- Scan internal networks
Language-Specific Security
Trusted Base Images
All Docker images are official, trusted images from Docker Hub. Location:DockerExecutorUtil.java:119-127
eclipse-temurin:17
Official OpenJDK build from Eclipse Foundation
python:3.11
Official Python Software Foundation image
gcc:latest
Official GNU Compiler Collection image
node:18
Official Node.js Foundation image
Command Injection Prevention
Commands are built programmatically, not from user input concatenation. Location:DockerExecutorUtil.java:129-141
File names are validated and constructed programmatically. User code goes into the file contents, not the file name or command.
Error Handling & Security
Graceful Failure
All exceptions are caught and returned as safe error messages. Location:DockerExecutorUtil.java:95-97
Container Cleanup on Failure
Even if execution fails, containers are still removed.The current implementation removes containers in the success path. For production, consider adding a
finally block to guarantee cleanup.Security Best Practices
Image Scanning
Image Scanning
Regularly scan Docker images for vulnerabilities:
Resource Monitoring
Resource Monitoring
Monitor container resource usage to detect abuse:
Rate Limiting
Rate Limiting
Implement API rate limiting to prevent abuse:
- Limit requests per IP address
- Limit concurrent executions
- Track execution metrics
Input Validation
Input Validation
Validate all user inputs:
- Maximum code size (e.g., 10KB)
- Allowed language values
- Character encoding validation
Security Checklist
Potential Improvements
Execution Timeout
Add maximum execution time limit (e.g., 30 seconds)
Read-Only Filesystem
Mount code directory as read-only where possible
User Namespaces
Run containers with non-root user mapping
Seccomp Profiles
Apply restrictive seccomp security profiles
Next Steps
Architecture Overview
Return to the architecture overview
Deployment Guide
Learn how to deploy Runtime securely