A comprehensive platform for secure code execution, algorithm analysis, and AI-powered code assistance. Features Docker-based isolated code execution, Supabase authentication with ES256 JWT, and a LangChain-powered AI assistant microservice.
- Overview
- Docker Container Execution
- System Architecture
- Features
- Installation
- Quick Start
- API Endpoints
- Security
- Technology Stack
- Contributing
DAALAB enables users to write, execute, and analyze algorithms in a secure, isolated environment. The platform's core innovation is its Docker-based code execution system, ensuring that user-submitted code runs in complete isolation from the host system.
- β Secure Code Execution: Python and C++ code runs in isolated Docker containers
- β Real-time Performance Tracking: Millisecond-precision runtime measurements
- β AI-Powered Analysis: LangChain agents provide intelligent code reviews
- β Multi-Language Support: Python 3.13 and C++17
- β User Authentication: ES256 JWT-based secure authentication
- β Performance Visualization: Interactive charts and analytics
- β Microservices Architecture: Independent scalability for AI and execution services
The platform's security and reliability are built on Docker containerization. Here's how code execution works:
User Code β API Server β Docker Container β Isolated Execution β Results β Container Destroyed
Container Configuration:
- Image:
python:3.13-slim(official Python slim image) - Isolation: Each execution runs in a fresh, isolated container
- Volume Mount: User code mounted at
/code/code.py - Auto-Cleanup: Containers automatically removed after execution
Implementation (container_runner.py):
container = self.client.containers.run(
"python:3.13-slim",
command=["python", "-u", "/code/code.py"],
volumes={code_path: {"bind": "/code/code.py", "mode": "rw"}},
remove=True # Automatic cleanup
)Container Configuration:
- Image:
gcc:latest(official GCC compiler) - Two-Phase Process: Compilation β Execution
- Standard: C++17 support
- Compile-Only Mode: Available for syntax checking
Implementation:
command=["sh", "-c", "g++ -std=c++17 -o /code/program /code/user.cpp && /code/program"]| Benefit | Description |
|---|---|
| Complete Isolation | Code cannot access host filesystem or network |
| No Persistence | Each execution starts with a clean state |
| Resource Control | Docker enforces CPU and memory limits |
| Automatic Cleanup | Containers destroyed immediately after use |
| Consistent Environment | Same execution environment for all users |
| Multi-Tenancy Safe | Concurrent executions are completely isolated |
The system includes a SafeCodeRunner (code_runner.py) with intelligent fallback:
- Primary: Docker container execution (most secure)
- Fallback: Local execution with restrictions if Docker unavailable
- Blacklisted modules:
os,sys,subprocess,socket, etc. - Forbidden functions:
eval,exec,open, etc. - 10-second timeout enforcement
- Dangerous pattern detection
- Blacklisted modules:
The platform uses a 2-microservice architecture for scalability:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Browser β
β (HTML/CSS/JS Frontend) β
ββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββ
β
β HTTP/HTTPS
β
ββββββββββΌββββββββββββββββββββββββββββββββββββββ
β Main API Service (Port 8000) β
β - Code execution via Docker β
β - Authentication (ES256 JWT) β
β - Database operations β
β - Performance tracking β
β - Static file serving β
ββββββββββ¬βββββββββββββββββββββ¬ββββββββββββββββββ
β β
β β HTTP
β β
ββββββββββΌβββββββββ βββββββΌβββββββββββββββββββ
β Docker Engine β β AI Service (Port 8001) β
β - Python β β - LangChain agents β
β - C++ (GCC) β β - Code analysis β
β - Containers β β - Bug detection β
βββββββββββββββββββ β - AI chat β
ββββββββββββββββββββββββββ
β
β
ββββββββββΌβββββββββ
β Supabase β
β - PostgreSQL β
β - Auth β
β - Storage β
βββββββββββββββββββ
Main API Service (api_server.py)
Port: 8000
Framework: FastAPI
Responsibilities:
- Docker container orchestration for code execution
- User authentication and authorization
- Algorithm runtime data collection
- Performance analytics
- Frontend static file serving
Key Endpoints:
POST /api/run-code- Execute Python codePOST /api/run-cpp- Execute C++ codePOST /api/auth/signup- User registrationPOST /api/auth/login- User authenticationGET /api/runtime-data- Performance metrics
AI Helper Service (helper_agent/agent_service.py)
Port: 8001
Framework: FastAPI + LangChain
LLM: Groq (Llama 3.3 70B Versatile)
Responsibilities:
- Intelligent code analysis using LangChain agents
- Bug detection and security issue identification
- Code optimization suggestions
- Interactive conversational AI about code
- Complexity analysis
Key Endpoints:
POST /analyze- Code analysisPOST /chat- Interactive AI chatGET /health- Service health checkDELETE /session/{id}- Clear conversation history
- Multi-Language Support: Python 3.13 and C++17
- Real-Time Output: Instant execution results
- Performance Metrics: Millisecond-precision runtime tracking
- Error Handling: Comprehensive error reporting
- Timeout Protection: Prevents infinite loops
Powered by LangChain agents with specialized tools:
-
Code Structure Analysis (tools.py)
- AST parsing for Python
- Function and class detection
- Import analysis
- Lines of code counting
-
Issue Detection
- Security vulnerabilities (
eval,exec) - Anti-patterns and code smells
- Mutable default arguments
- Bare except clauses
- Style violations (PEP 8)
- Security vulnerabilities (
-
Optimization Suggestions
- Performance improvements
- Best practice recommendations
- Refactoring opportunities
-
Complexity Analysis
- Cyclomatic complexity
- Cognitive complexity
- Maintainability index
- Secure Authentication: ES256 JWT tokens
- User Profiles: Personal code storage
- Performance History: Track algorithm runtimes
- Session Management: Conversation continuity
- Runtime Graphs: Interactive Plotly.js charts
- Algorithm Comparison: Side-by-side performance
- Input Size Analysis: Complexity visualization
- Statistical Summaries: Min, max, avg execution times
- Python: 3.9 or higher
- Docker: Installed and running
- Supabase Account: For authentication and database
- Groq API Key: For AI features (alternatively OpenAI)
git clone <repository-url>
cd DAALABpip install -r requirements.txtCreate a .env file in the root directory:
# Supabase Configuration
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-supabase-anon-key
SUPABASE_JWKS_URL=https://your-project.supabase.co/auth/v1/.well-known/jwks.json
SUPABASE_JWT_KID=your-jwt-kid
# AI Service
GROQ_API_KEY=your-groq-api-key
AI_SERVICE_PORT=8001
AI_SERVICE_URL=http://localhost:8001
# Main Service
PORT=8000
HOST=0.0.0.0- Open Supabase Dashboard β SQL Editor
- Execute the schema from docs/schema.sql
docker pull python:3.13-slim
docker pull gcc:latest.\docs\start_services.ps1Terminal 1 - Main API Service:
python api_server.pyTerminal 2 - AI Helper Service:
python -m helper_agent.agent_service- Open integrated terminal
- Split terminal (Ctrl+Shift+5)
- Run services in separate terminals
- Frontend: http://localhost:8000
- API Docs: http://localhost:8000/docs
- AI Service Docs: http://localhost:8001/docs
POST /api/run-code
Content-Type: application/json
Authorization: Bearer {jwt_token}
{
"code": "print('Hello, World!')",
"algorithm_name": "HelloWorld",
"input_size": 1
}POST /api/run-cpp
Content-Type: application/json
Authorization: Bearer {jwt_token}
{
"code": "#include <iostream>\nint main() { std::cout << \"Hello\"; }",
"algorithm_name": "CppHello",
"input_size": 1
}POST /api/auth/signup
Content-Type: application/json
{
"email": "user@example.com",
"password": "secure_password",
"username": "username"
}POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "secure_password"
}GET /api/runtime-data
Authorization: Bearer {jwt_token}GET /api/runtime-summary
Authorization: Bearer {jwt_token}POST /api/ai/analyze
Authorization: Bearer {jwt_token}
Content-Type: application/json
{
"code": "def example(): pass",
"language": "python",
"query": "Analyze this code"
}POST /analyze
Content-Type: application/json
{
"code": "def fibonacci(n): return n if n <= 1 else fibonacci(n-1) + fibonacci(n-2)",
"language": "python",
"query": "How can I optimize this?"
}POST /chat
Content-Type: application/json
{
"question": "What's the time complexity?",
"code": "for i in range(n): for j in range(n): print(i, j)",
"session_id": "user-123"
}- No Host Access: Containers cannot access the host filesystem beyond mounted files
- Network Isolation: No network access from containers
- Resource Limits: CPU and memory constraints enforced by Docker
- Ephemeral Execution: Containers destroyed immediately after use
- Read-Only Mounts: Where applicable, files are mounted read-only
- ES256 JWT: Elliptic Curve cryptographic signatures
- JWKS Verification: Public key fetched from Supabase
- Token Validation: Signature, audience, and expiration checks
- Secure Storage: Passwords hashed by Supabase Auth
When Docker is unavailable, the system enforces:
- Blacklist of dangerous modules (os, sys, subprocess, socket, etc.)
- Forbidden functions (eval, exec, open, etc.)
- Timeout enforcement (10 seconds max)
- Pattern detection for malicious code
- CORS configured for specific origins in production
- Input validation via Pydantic models
- SQL injection prevention via Supabase client
- Error messages sanitized to prevent information leakage
| Technology | Purpose |
|---|---|
| FastAPI | High-performance async web framework |
| Docker SDK | Container orchestration and management |
| Supabase | PostgreSQL database + authentication |
| PyJWT | ES256 JWT token verification |
| LangChain | AI agent framework for code analysis |
| Groq | Fast LLM inference (Llama 3.3 70B) |
| Uvicorn | ASGI server for FastAPI |
| httpx | Async HTTP client for microservice communication |
| Technology | Purpose |
|---|---|
| Vanilla JavaScript | No framework overhead |
| HTML5/CSS3 | Modern responsive design |
| Plotly.js | Interactive data visualization |
| Fetch API | Async backend communication |
| Component | Details |
|---|---|
| Docker | python:3.13-slim, gcc:latest images |
| Supabase | Managed PostgreSQL + Auth |
| Microservices | Independent service deployment |
- User authentication data
- Password hashing
- Email verification
- id: UUID (primary key)
- user_id: UUID (foreign key)
- algorithm_name: TEXT
- input_size: INTEGER
- execution_time_ms: NUMERIC
- code_snippet: TEXT
- output_result: TEXT
- created_at: TIMESTAMP- id: UUID (primary key)
- user_id: UUID (foreign key)
- file_type: TEXT ('python' or 'cpp')
- code_content: TEXT
- filename: TEXT
- created_at: TIMESTAMP
- updated_at: TIMESTAMP
- UNIQUE(user_id, file_type)python tests/test_ai_service.pyAnalyze Code:
curl -X POST http://localhost:8001/analyze \
-H "Content-Type: application/json" \
-d '{"code": "def hello(): print(\"world\")", "language": "python"}'Execute Python Code:
curl -X POST http://localhost:8000/api/run-code \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{"code": "print(2 + 2)"}'- Python Container Startup: ~200-500ms
- C++ Compilation + Execution: ~500-1000ms
- AI Analysis: ~1-3 seconds (depending on code complexity)
- JWT Verification: <10ms
- Concurrent Executions: Unlimited (Docker manages resources)
- AI Service: Scales independently from main service
- Database: Supabase handles connection pooling
- Stateless Design: Easy horizontal scaling
- Configure CORS with specific origins
- Set up environment variables securely
- Enable Docker resource limits
- Configure rate limiting
- Set up monitoring and logging
- Use Redis for session storage (replace in-memory)
- Deploy services independently
- Configure SSL/TLS certificates
- Set up backup strategy for database
- Main API: Railway, Render, or AWS ECS
- AI Service: Separate instance for independent scaling
- Database: Supabase (managed)
- Docker: Ensure Docker is available on hosting platform
Contributions are welcome! This microservice architecture makes it easy to:
- Add new programming languages (just add Docker images)
- Extend AI analysis tools
- Swap LLM providers (replace Groq with OpenAI, Claude, etc.)
- Add new features to either service independently
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Test thoroughly
- Commit (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- FastAPI for the excellent web framework
- Docker for containerization technology
- LangChain for AI agent framework
- Supabase for authentication and database
- Groq for fast LLM inference
For issues, questions, or contributions:
- Open an issue on GitHub
- Check existing documentation in docs/
- Review API documentation at
/docsendpoints
- AI Service Documentation
- Database Schema
- Migration Guide
- LangChain Documentation
- Docker SDK for Python
- FastAPI Documentation
Built with β€οΈ for secure, scalable code execution and AI-powered analysis