Skip to content

Commit 10d9baa

Browse files
author
Stalin
committed
Add Multi-Language Code Execution Support (20+ Languages)
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
1 parent ea05201 commit 10d9baa

3 files changed

Lines changed: 1055 additions & 1109 deletions

File tree

SUPPORTED_LANGUAGES.md

Lines changed: 364 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,364 @@
1+
# Supported Programming Languages
2+
3+
## OpenLearnX Compiler Service - Language Support
4+
5+
The code execution platform now supports **20+ programming languages** with comprehensive security sandboxing.
6+
7+
---
8+
9+
## **Supported Languages**
10+
11+
### **Interpreted Languages (Runtime)**
12+
| Language | Alias | Timeout | Memory | Command | Version |
13+
|----------|-------|---------|--------|---------|---------|
14+
| **Python** | `py` | 8s | 128MB | `python /workspace/code.py` | 3.11-alpine |
15+
| **JavaScript** | `js` | 8s | 128MB | `node /workspace/code.js` | 20-alpine |
16+
| **Bash/Shell** | `bash`, `sh` | 10s | 64MB | `bash /workspace/code.sh` | 5-alpine |
17+
| **Ruby** | `rb` | 10s | 128MB | `ruby /workspace/code.rb` | 3.2-alpine |
18+
| **PHP** | `php` | 8s | 128MB | `php /workspace/code.php` | 8.2-alpine |
19+
| **Lua** | `lua` | 8s | 64MB | `lua /workspace/code.lua` | 5.4 |
20+
| **Perl** | `pl` | 10s | 128MB | `perl /workspace/code.pl` | 5.36-alpine |
21+
| **R** | `r` | 15s | 256MB | `Rscript /workspace/code.R` | latest |
22+
| **Julia** | `julia` | 15s | 256MB | `julia /workspace/code.jl` | 1.9-alpine |
23+
24+
### **Compiled Languages (Compiled)**
25+
| Language | Alias | Timeout | Memory | Compiler | Runtime |
26+
|----------|-------|---------|--------|----------|---------|
27+
| **C** | `c` | 10s | 192MB | `gcc -O2` | `./program` |
28+
| **C++** | `cpp`, `c++` | 10s | 256MB | `g++ -std=c++17` | `./program` |
29+
| **Java** | `java` | 12s | 256MB | `javac` | `java -cp` |
30+
| **Go** | `go` | 14s | 256MB | `go build` | `./program` |
31+
| **Rust** | `rust` | 20s | 512MB | `rustc -O` | `./program` |
32+
| **Kotlin** | `kt` | 15s | 256MB | `kotlinc` | `java -jar` |
33+
| **Swift** | `swift` | 15s | 256MB | `swiftc -O` | `./program` |
34+
| **TypeScript** | `ts` | 10s | 256MB | `tsc` | `node` |
35+
| **C#** | `cs`, `csharp` | 15s | 512MB | `dotnet build` | `dotnet` |
36+
| **Scala** | `scala` | 15s | 256MB | `scalac` | `scala` |
37+
| **Groovy** | `groovy` | 12s | 256MB | `groovy` | `groovy` |
38+
39+
---
40+
41+
## 🔧 **API Usage Examples**
42+
43+
### **Execute Python**
44+
```bash
45+
curl -X POST http://localhost:5000/api/compiler/execute \
46+
-H "Content-Type: application/json" \
47+
-d '{
48+
"language": "python",
49+
"code": "print(\"Hello World\")"
50+
}'
51+
```
52+
53+
### **Execute JavaScript**
54+
```bash
55+
curl -X POST http://localhost:5000/api/compiler/execute \
56+
-H "Content-Type: application/json" \
57+
-d '{
58+
"language": "javascript",
59+
"code": "console.log(\"Hello World\")"
60+
}'
61+
```
62+
63+
### **Execute Java**
64+
```bash
65+
curl -X POST http://localhost:5000/api/compiler/execute \
66+
-H "Content-Type: application/json" \
67+
-d '{
68+
"language": "java",
69+
"code": "public class Main { public static void main(String[] args) { System.out.println(\"Hello World\"); } }"
70+
}'
71+
```
72+
73+
### **Execute with Input Data**
74+
```bash
75+
curl -X POST http://localhost:5000/api/compiler/execute \
76+
-H "Content-Type: application/json" \
77+
-d '{
78+
"language": "python",
79+
"code": "x = input(); print(int(x) * 2)",
80+
"input": "5"
81+
}'
82+
```
83+
84+
### **Execute Bash Script**
85+
```bash
86+
curl -X POST http://localhost:5000/api/compiler/execute \
87+
-H "Content-Type: application/json" \
88+
-d '{
89+
"language": "bash",
90+
"code": "#!/bin/bash\necho \"Hello from Bash\"\necho \"Current date: $(date)\""
91+
}'
92+
```
93+
94+
### **Execute with Aliases**
95+
```bash
96+
# Using short alias
97+
curl -X POST http://localhost:5000/api/compiler/execute \
98+
-H "Content-Type: application/json" \
99+
-d '{
100+
"language": "py",
101+
"code": "print(\"Python via py alias\")"
102+
}'
103+
104+
# Using c++ alias
105+
curl -X POST http://localhost:5000/api/compiler/execute \
106+
-H "Content-Type: application/json" \
107+
-d '{
108+
"language": "c++",
109+
"code": "#include <iostream>\nint main() { std::cout << \"Hello C++\"; return 0; }"
110+
}'
111+
```
112+
113+
---
114+
115+
## 🔒 **Security Features**
116+
117+
### **Sandbox Isolation**
118+
- ✅ Docker containerization for each execution
119+
- ✅ Memory limits (64MB - 512MB per language)
120+
- ✅ CPU limits (0.25 - 0.8 cores)
121+
- ✅ Timeout protection (8s - 20s)
122+
- ✅ Read-only filesystem
123+
124+
### **Blocked Operations**
125+
Each language has specific restricted operations:
126+
127+
**Python:**
128+
- `os`, `socket`, `subprocess` modules
129+
- `eval()`, `exec()`, `__import__()`
130+
- File I/O operations
131+
132+
**JavaScript:**
133+
- `child_process` module
134+
- `process.env`, `process.binding`
135+
- File system access
136+
137+
**Bash:**
138+
- Command substitution patterns
139+
- `/dev` access
140+
- Dangerous commands (`rm -rf`, `dd`)
141+
142+
**Java:**
143+
- `Runtime.getRuntime()`
144+
- `ProcessBuilder`
145+
- Network operations (`java.net`)
146+
147+
**C/C++:**
148+
- `system()`, `popen()`, `fork()`
149+
- Socket operations
150+
- File operations
151+
152+
**Go:**
153+
- `exec.Command()`
154+
- Network access
155+
- File operations
156+
157+
**Rust:**
158+
- `std::process::Command`
159+
- Network operations
160+
- Unsafe blocks (when code is not in library context)
161+
162+
---
163+
164+
## 📊 **Language Statistics**
165+
166+
```
167+
Total Languages Supported: 20
168+
Interpreted Languages: 9
169+
Compiled Languages: 11
170+
171+
Performance Tiers:
172+
Fast (8-10s): Python, JavaScript, PHP, Lua, Bash (5 languages)
173+
Standard (10-15s): Ruby, C, C++, Java, Kotlin, Swift, TypeScript, Groovy (8 languages)
174+
Intensive (15-20s): Go, Rust, R, Julia, C#, Scala (6 languages)
175+
```
176+
177+
---
178+
179+
## 🚀 **Getting Started with Each Language**
180+
181+
### **1. Python**
182+
```python
183+
# Your code here
184+
print("Hello World")
185+
name = input()
186+
print(f"Hello {name}")
187+
```
188+
189+
### **2. JavaScript**
190+
```javascript
191+
// Your code here
192+
console.log("Hello World");
193+
const name = "Alice";
194+
console.log(`Hello ${name}`);
195+
```
196+
197+
### **3. Bash**
198+
```bash
199+
#!/bin/bash
200+
echo "Hello World"
201+
echo "Current directory: $(pwd)"
202+
```
203+
204+
### **4. Java**
205+
```java
206+
public class Main {
207+
public static void main(String[] args) {
208+
System.out.println("Hello World");
209+
}
210+
}
211+
```
212+
213+
### **5. C++**
214+
```cpp
215+
#include <iostream>
216+
int main() {
217+
std::cout << "Hello World" << std::endl;
218+
return 0;
219+
}
220+
```
221+
222+
### **6. Rust**
223+
```rust
224+
fn main() {
225+
println!("Hello World");
226+
}
227+
```
228+
229+
### **7. Go**
230+
```go
231+
package main
232+
import "fmt"
233+
func main() {
234+
fmt.Println("Hello World")
235+
}
236+
```
237+
238+
### **8. R**
239+
```r
240+
# Your code here
241+
print("Hello World")
242+
x <- c(1, 2, 3)
243+
print(mean(x))
244+
```
245+
246+
### **9. Ruby**
247+
```ruby
248+
puts "Hello World"
249+
name = gets.chomp
250+
puts "Hello #{name}"
251+
```
252+
253+
---
254+
255+
## 📝 **API Response Format**
256+
257+
```json
258+
{
259+
"success": true,
260+
"execution_id": "550e8400-e29b-41d4-a716-446655440000",
261+
"language": "python",
262+
"output": "Hello World\n",
263+
"error": "",
264+
"exit_code": 0,
265+
"execution_time": 0.245,
266+
"memory_used": 12.5,
267+
"timestamp": "2026-05-12T20:30:00.000Z"
268+
}
269+
```
270+
271+
---
272+
273+
## 🔧 **Configuration Details**
274+
275+
### **Docker Images Used**
276+
- Python: `python:3.11-alpine`
277+
- Node.js: `node:20-alpine`
278+
- GCC/G++: `gcc:13`
279+
- Java: `openjdk:17-alpine`
280+
- Go: `golang:1.22-alpine`
281+
- Rust: `rust:1.77-alpine`
282+
- R: `rocker/r-base:latest`
283+
- Julia: `julia:1.9-alpine`
284+
- Ruby: `ruby:3.2-alpine`
285+
- PHP: `php:8.2-alpine`
286+
- Swift: `swift:5.9-alpine`
287+
- C#/.NET: `mcr.microsoft.com/dotnet/sdk:7.0-alpine`
288+
289+
---
290+
291+
## ⚠️ **Limitations**
292+
293+
1. **Network Access**: Disabled for all languages (no external API calls)
294+
2. **File I/O**: Limited to `/workspace` directory (read-only for most operations)
295+
3. **Process Creation**: Disabled for security reasons
296+
4. **Execution Time**: Maximum 20 seconds per execution
297+
5. **Code Size**: Maximum 20,000 characters
298+
6. **Memory**: Limited per language (64MB - 512MB)
299+
7. **CPU**: Limited per language (0.25 - 0.8 cores)
300+
301+
---
302+
303+
## 🔄 **Adding New Languages**
304+
305+
To add a new language:
306+
307+
1. **Add configuration** in `language_configs` dict:
308+
```python
309+
"newlang": {
310+
"image": "newlang:version",
311+
"file_name": "code.ext",
312+
"compile_command": "compile command or None",
313+
"run_command": "run command",
314+
"timeout": 10,
315+
"memory_limit": "256m",
316+
"cpu_limit": 0.5,
317+
}
318+
```
319+
320+
2. **Add security patterns** in `blocked_patterns` dict:
321+
```python
322+
"newlang": [
323+
r"forbidden_pattern_1",
324+
r"forbidden_pattern_2",
325+
]
326+
```
327+
328+
3. **Add language aliases** (optional) in `execute_code()` method
329+
330+
---
331+
332+
## 📞 **Support & Troubleshooting**
333+
334+
**Issue**: Language not supported
335+
- **Solution**: Check supported languages list above
336+
337+
**Issue**: Execution timeout
338+
- **Solution**: Optimize code performance or increase timeout
339+
340+
**Issue**: Security violation
341+
- **Solution**: Remove blocked operations (network, file I/O, process execution)
342+
343+
**Issue**: Memory limit exceeded
344+
- **Solution**: Reduce data processing or optimize algorithms
345+
346+
---
347+
348+
## 📚 **References**
349+
350+
- Docker Images: https://hub.docker.com
351+
- Language Documentation:
352+
- Python: https://docs.python.org
353+
- JavaScript: https://developer.mozilla.org
354+
- Java: https://docs.oracle.com/javase
355+
- C++: https://en.cppreference.com
356+
- Rust: https://doc.rust-lang.org
357+
- Go: https://golang.org/doc
358+
- Ruby: https://ruby-doc.org
359+
- R: https://www.r-project.org
360+
361+
---
362+
363+
**Last Updated**: May 12, 2026
364+
**Version**: 2.0 (Multi-Language Support)

0 commit comments

Comments
 (0)