-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathconfig.py
More file actions
50 lines (40 loc) · 1.53 KB
/
Copy pathconfig.py
File metadata and controls
50 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
LANGUAGE_IMAGES = {
"python": "python:3.11-slim",
"bash": "python:3.11-slim",
"python-vnc": "vnc-gui-browser:latest",
"javascript": "node:18-slim",
"java": "openjdk:11-jre-slim",
"cpp": "gcc:latest",
"go": "golang:1.21-alpine",
"rust": "rust:1.75-slim",
}
WORKING_DIR = "/workspace"
def get_command_by_language(language: str, filename: str) -> str:
commands = {
"python-vnc": f"python3 {filename}",
"python": f"python {filename}",
"javascript": f"node {filename}",
"java": f"javac {filename} && java {filename[:-5]}",
"cpp": f"g++ -o program {filename} && ./program",
"go": f"go run {filename}",
"rust": f"rustc {filename} -o program && ./program",
"bash": f"sh {filename}",
}
return commands.get(language, f"cat {filename}")
MAX_MEMORY = 256 * 1024 * 1024 # 256MB
MAX_CPU_PERCENT = 50.0
MAX_EXECUTION_TIME = 30 # seconds
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
MAX_DEPENDENCY_INSTALL_TIME = 300 # seconds
MAX_DEPENDENCY_INSTALL_SIZE = 200 * 1024 * 1024 # 200MB
MAX_PROCESSES = 10
def _env_flag(name: str, default: bool = False) -> bool:
value = os.getenv(name)
if value is None:
return default
return value.lower() in {"1", "true", "yes", "on"}
# Optional values: docker, podman, nerdctl, local. When unset, RuntimeFactory
# auto-detects container runtimes and fails closed if none are available.
SANDBOX_RUNTIME = os.getenv("SANDBOX_RUNTIME")
SANDBOX_ALLOW_LOCAL_RUNTIME = _env_flag("SANDBOX_ALLOW_LOCAL_RUNTIME")