Kudu: The open-source web-based code execution platform with a client-server architecture that provides secure, containerized code execution.
Kudu is a robust, containerized code execution platform that enables secure running of code snippets in isolated environments. It features a React-based frontend with Monaco editor integration and a Node.js/Express backend that orchestrates Docker containers for code execution.
- Tech Stack: React 18, Material-UI, Monaco Editor
- Key Components:
CodeEditor.jsx
: Main editor interface with real-time code executionErrorHandler.js
: Global error boundary and error displayLoadingSpinner.js
: Execution state indicatorThemeSwitcher.jsx
: Dark/light mode toggle
- Tech Stack: Node.js, Express, Dockerode
- Core Modules:
routes/code.js
: Code execution endpoint handlersmiddleware/validator.js
: Input validation and security checksservices/monitoring.js
: Prometheus metrics and loggingutils/metrics.js
: Container resource monitoring
// Resource limits per container
const containerConfig = {
Memory: 100 * 1024 * 1024, // 100MB
NanoCPUs: 1e9, // 1 CPU core
NetworkMode: "none" // Network isolation
};
// Blocked patterns from validator.js
const blockedPatterns = [
/process\.env/i,
/require\s*\(/i,
/import\s+(?:os|sys|subprocess)/i,
/open\s*\(/i,
/eval\s*\(/i,
/exec\s*\(/i
];
// Prometheus metrics
const metrics = {
executionDuration: new promClient.Histogram({
name: "code_execution_duration_seconds",
help: "Duration of code execution in seconds",
labelNames: ["language"]
}),
memoryUsage: new promClient.Gauge({
name: "container_memory_usage_bytes",
help: "Memory usage of containers",
labelNames: ["container_id"]
})
};
- Docker Engine 20.10+
- Node.js 16+
- npm 7+
# Clone repository
git clone https://github.com/wandilemawelela/kudu.git
cd kudu
# Install dependencies
cd frontend && npm install
cd ../backend && npm install
# Start development servers
# Terminal 1:
cd frontend && npm start
# Terminal 2:
cd backend && npm start
# Build and run with docker-compose
docker-compose up --build
PORT=3001
FRONTEND_URL=http://localhost:3000
NODE_ENV=development
REACT_APP_BACKEND_URL=http://localhost:3001
services:
backend:
build:
context: ./backend
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "3001:3001"
frontend:
build:
context: ./frontend
ports:
- "3000:3000"
POST /code/run
Content-Type: application/json
{
"language": "python|javascript",
"code": "string"
}
{
"success": true,
"output": "string",
"executionTime": 0.123
}
- Container Isolation
- Memory limits: 100MB per container
- CPU limits: 1 core
- Network access: Disabled
- Auto-removal: Containers destroyed after execution
- Code Validation
- Blocked patterns prevention
- Maximum code length enforcement
- Language-specific restrictions
- Rate Limiting
- Request limits per IP
- Execution timeouts
- Resource quotas
- Execution duration
- Memory usage
- CPU utilization
- Error rates
- Container lifecycle events
const logger = winston.createLogger({
level: "info",
format: winston.format.json(),
transports: [
new winston.transports.File({ filename: "error.log", level: "error" }),
new winston.transports.File({ filename: "combined.log" })
]
});
cd backend
npm test
Key test suites:
- Container Management
- Container pooling
- Resource cleanup
- Cache optimization
- Frontend Optimization
- Code editor performance
- Request debouncing
- Error handling
MIT License - see LICENSE
for details
- CPU: 2 cores
- RAM: 4GB
- Storage: 20GB
- Docker Engine 20.10+
- Node.js 16+
- CPU: 4+ cores
- RAM: 8GB+
- Storage: 40GB+
- SSD storage
- Docker Engine 20.10+
- Node.js 16+