mirror of
https://github.com/th30d4y/OpenLearnX.git
synced 2026-05-26 11:25:49 +00:00
10d9baab76
Added support for 20 programming languages: INTERPRETED LANGUAGES (9): • Python 3.11 • JavaScript (Node 20) • Bash/Shell 5 • Ruby 3.2 • PHP 8.2 • R (Statistical Computing) • Julia (Scientific Computing) • Perl 5.36 • Lua 5.4 COMPILED LANGUAGES (11): • C (GCC 13) • C++ (GCC 17) • Java 17 • Go 1.22 • Rust 1.77 • Kotlin 2.0 • Swift 5.9 • TypeScript 5 • C# (.NET 7) • Scala 2.13 • Groovy 4.0 IMPROVEMENTS: ✓ Expanded language_configs with 20+ languages ✓ Added comprehensive security patterns for each language ✓ Language aliases (py→Python, js→JavaScript, etc) ✓ Memory limits optimized per language (64MB-512MB) ✓ CPU throttling configured (0.25-0.8 cores) ✓ Timeout protection (8s-20s per language) ✓ Created SUPPORTED_LANGUAGES.md documentation SECURITY FEATURES: ✓ Docker container isolation for each execution ✓ Memory and CPU limits per language ✓ Pattern-based code blocking for dangerous operations ✓ Network access disabled ✓ File I/O restricted to /workspace ✓ 20,000 character code size limit API SUPPORT: ✓ Accept language full name or alias ✓ Input data streaming support ✓ Detailed execution metrics (time, memory, exit code) ✓ Comprehensive error reporting
8.5 KiB
8.5 KiB
Supported Programming Languages
OpenLearnX Compiler Service - Language Support
The code execution platform now supports 20+ programming languages with comprehensive security sandboxing.
✅ Supported Languages
Interpreted Languages (Runtime)
| Language | Alias | Timeout | Memory | Command | Version |
|---|---|---|---|---|---|
| Python | py |
8s | 128MB | python /workspace/code.py |
3.11-alpine |
| JavaScript | js |
8s | 128MB | node /workspace/code.js |
20-alpine |
| Bash/Shell | bash, sh |
10s | 64MB | bash /workspace/code.sh |
5-alpine |
| Ruby | rb |
10s | 128MB | ruby /workspace/code.rb |
3.2-alpine |
| PHP | php |
8s | 128MB | php /workspace/code.php |
8.2-alpine |
| Lua | lua |
8s | 64MB | lua /workspace/code.lua |
5.4 |
| Perl | pl |
10s | 128MB | perl /workspace/code.pl |
5.36-alpine |
| R | r |
15s | 256MB | Rscript /workspace/code.R |
latest |
| Julia | julia |
15s | 256MB | julia /workspace/code.jl |
1.9-alpine |
Compiled Languages (Compiled)
| Language | Alias | Timeout | Memory | Compiler | Runtime |
|---|---|---|---|---|---|
| C | c |
10s | 192MB | gcc -O2 |
./program |
| C++ | cpp, c++ |
10s | 256MB | g++ -std=c++17 |
./program |
| Java | java |
12s | 256MB | javac |
java -cp |
| Go | go |
14s | 256MB | go build |
./program |
| Rust | rust |
20s | 512MB | rustc -O |
./program |
| Kotlin | kt |
15s | 256MB | kotlinc |
java -jar |
| Swift | swift |
15s | 256MB | swiftc -O |
./program |
| TypeScript | ts |
10s | 256MB | tsc |
node |
| C# | cs, csharp |
15s | 512MB | dotnet build |
dotnet |
| Scala | scala |
15s | 256MB | scalac |
scala |
| Groovy | groovy |
12s | 256MB | groovy |
groovy |
🔧 API Usage Examples
Execute Python
curl -X POST http://localhost:5000/api/compiler/execute \
-H "Content-Type: application/json" \
-d '{
"language": "python",
"code": "print(\"Hello World\")"
}'
Execute JavaScript
curl -X POST http://localhost:5000/api/compiler/execute \
-H "Content-Type: application/json" \
-d '{
"language": "javascript",
"code": "console.log(\"Hello World\")"
}'
Execute Java
curl -X POST http://localhost:5000/api/compiler/execute \
-H "Content-Type: application/json" \
-d '{
"language": "java",
"code": "public class Main { public static void main(String[] args) { System.out.println(\"Hello World\"); } }"
}'
Execute with Input Data
curl -X POST http://localhost:5000/api/compiler/execute \
-H "Content-Type: application/json" \
-d '{
"language": "python",
"code": "x = input(); print(int(x) * 2)",
"input": "5"
}'
Execute Bash Script
curl -X POST http://localhost:5000/api/compiler/execute \
-H "Content-Type: application/json" \
-d '{
"language": "bash",
"code": "#!/bin/bash\necho \"Hello from Bash\"\necho \"Current date: $(date)\""
}'
Execute with Aliases
# Using short alias
curl -X POST http://localhost:5000/api/compiler/execute \
-H "Content-Type: application/json" \
-d '{
"language": "py",
"code": "print(\"Python via py alias\")"
}'
# Using c++ alias
curl -X POST http://localhost:5000/api/compiler/execute \
-H "Content-Type: application/json" \
-d '{
"language": "c++",
"code": "#include <iostream>\nint main() { std::cout << \"Hello C++\"; return 0; }"
}'
🔒 Security Features
Sandbox Isolation
- ✅ Docker containerization for each execution
- ✅ Memory limits (64MB - 512MB per language)
- ✅ CPU limits (0.25 - 0.8 cores)
- ✅ Timeout protection (8s - 20s)
- ✅ Read-only filesystem
Blocked Operations
Each language has specific restricted operations:
Python:
os,socket,subprocessmoduleseval(),exec(),__import__()- File I/O operations
JavaScript:
child_processmoduleprocess.env,process.binding- File system access
Bash:
- Command substitution patterns
/devaccess- Dangerous commands (
rm -rf,dd)
Java:
Runtime.getRuntime()ProcessBuilder- Network operations (
java.net)
C/C++:
system(),popen(),fork()- Socket operations
- File operations
Go:
exec.Command()- Network access
- File operations
Rust:
std::process::Command- Network operations
- Unsafe blocks (when code is not in library context)
📊 Language Statistics
Total Languages Supported: 20
Interpreted Languages: 9
Compiled Languages: 11
Performance Tiers:
Fast (8-10s): Python, JavaScript, PHP, Lua, Bash (5 languages)
Standard (10-15s): Ruby, C, C++, Java, Kotlin, Swift, TypeScript, Groovy (8 languages)
Intensive (15-20s): Go, Rust, R, Julia, C#, Scala (6 languages)
🚀 Getting Started with Each Language
1. Python
# Your code here
print("Hello World")
name = input()
print(f"Hello {name}")
2. JavaScript
// Your code here
console.log("Hello World");
const name = "Alice";
console.log(`Hello ${name}`);
3. Bash
#!/bin/bash
echo "Hello World"
echo "Current directory: $(pwd)"
4. Java
public class Main {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
5. C++
#include <iostream>
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}
6. Rust
fn main() {
println!("Hello World");
}
7. Go
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
8. R
# Your code here
print("Hello World")
x <- c(1, 2, 3)
print(mean(x))
9. Ruby
puts "Hello World"
name = gets.chomp
puts "Hello #{name}"
📝 API Response Format
{
"success": true,
"execution_id": "550e8400-e29b-41d4-a716-446655440000",
"language": "python",
"output": "Hello World\n",
"error": "",
"exit_code": 0,
"execution_time": 0.245,
"memory_used": 12.5,
"timestamp": "2026-05-12T20:30:00.000Z"
}
🔧 Configuration Details
Docker Images Used
- Python:
python:3.11-alpine - Node.js:
node:20-alpine - GCC/G++:
gcc:13 - Java:
openjdk:17-alpine - Go:
golang:1.22-alpine - Rust:
rust:1.77-alpine - R:
rocker/r-base:latest - Julia:
julia:1.9-alpine - Ruby:
ruby:3.2-alpine - PHP:
php:8.2-alpine - Swift:
swift:5.9-alpine - C#/.NET:
mcr.microsoft.com/dotnet/sdk:7.0-alpine
⚠️ Limitations
- Network Access: Disabled for all languages (no external API calls)
- File I/O: Limited to
/workspacedirectory (read-only for most operations) - Process Creation: Disabled for security reasons
- Execution Time: Maximum 20 seconds per execution
- Code Size: Maximum 20,000 characters
- Memory: Limited per language (64MB - 512MB)
- CPU: Limited per language (0.25 - 0.8 cores)
🔄 Adding New Languages
To add a new language:
- Add configuration in
language_configsdict:
"newlang": {
"image": "newlang:version",
"file_name": "code.ext",
"compile_command": "compile command or None",
"run_command": "run command",
"timeout": 10,
"memory_limit": "256m",
"cpu_limit": 0.5,
}
- Add security patterns in
blocked_patternsdict:
"newlang": [
r"forbidden_pattern_1",
r"forbidden_pattern_2",
]
- Add language aliases (optional) in
execute_code()method
📞 Support & Troubleshooting
Issue: Language not supported
- Solution: Check supported languages list above
Issue: Execution timeout
- Solution: Optimize code performance or increase timeout
Issue: Security violation
- Solution: Remove blocked operations (network, file I/O, process execution)
Issue: Memory limit exceeded
- Solution: Reduce data processing or optimize algorithms
📚 References
- Docker Images: https://hub.docker.com
- Language Documentation:
- Python: https://docs.python.org
- JavaScript: https://developer.mozilla.org
- Java: https://docs.oracle.com/javase
- C++: https://en.cppreference.com
- Rust: https://doc.rust-lang.org
- Go: https://golang.org/doc
- Ruby: https://ruby-doc.org
- R: https://www.r-project.org
Last Updated: May 12, 2026 Version: 2.0 (Multi-Language Support)