feat(runner): add the own code runner contract, client and nsjail service

This commit is contained in:
shira committed 2026-10-11 08:23:42 +03:00
1 parent 5e1db37746
commit cdf6bcbb91
109 files changed
+24084 -28

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
# Isolation probe: the root file system and the source are read-only, the
# scratch directory is writable, and runner files are not visible.
import os
writable = []
for path in ("/box/injected", "/usr/injected", "/injected", "/lib/injected"):
try:
with open(path, "w") as stream:
stream.write("x")
writable.append(path)
except OSError:
pass
with open("/tmp/scratch", "w") as stream:
stream.write("ok")
visible = [path for path in ("/etc/passwd", "/run/secrets", "/opt/lincodex-runner", "/proc/1") if os.path.exists(path)]
print("isolated" if not writable and not visible else "writable=" + ",".join(writable) + " visible=" + ",".join(visible))
+8
View File
@@ -0,0 +1,8 @@
# Fork bomb that ignores refused forks: the cgroup process limit must stop it.
import os
while True:
try:
os.fork()
except OSError:
pass
+6
View File
@@ -0,0 +1,6 @@
# Endless standard output: the output limit must stop it.
import sys
block = "x" * 65536
while True:
sys.stdout.write(block)
+3
View File
@@ -0,0 +1,3 @@
# Busy loop: the CPU time limit must stop it.
while True:
pass
+4
View File
@@ -0,0 +1,4 @@
# Unbounded allocation of touched memory: the cgroup memory limit must stop it.
chunks = []
while True:
chunks.append(b"x" * (1 << 20))
+18
View File
@@ -0,0 +1,18 @@
# Isolation probe: every attempt to reach a network must fail.
import socket
attempts = [
(socket.AF_INET, ("1.1.1.1", 53)),
(socket.AF_INET, ("127.0.0.1", 8080)),
(socket.AF_INET6, ("::1", 8080)),
]
reached = []
for family, address in attempts:
try:
with socket.socket(family, socket.SOCK_STREAM) as connection:
connection.settimeout(1)
connection.connect(address)
reached.append(address[0])
except OSError:
pass
print("blocked" if not reached else "reached " + " ".join(reached))
+19
View File
@@ -0,0 +1,19 @@
# Isolation probe: the program is an unprivileged user that cannot become
# root or take ownership for root.
import os
checks = [os.getuid() != 0, os.geteuid() != 0, os.getgid() != 0, os.getegid() != 0]
for attempt in (lambda: os.setuid(0), lambda: os.setgid(0)):
try:
attempt()
checks.append(False)
except OSError:
checks.append(True)
with open("/tmp/owned", "w"):
pass
try:
os.chown("/tmp/owned", 0, 0)
checks.append(False)
except OSError:
checks.append(True)
print("unprivileged" if all(checks) else "privileged")
+4
View File
@@ -0,0 +1,4 @@
# Idle wait: it uses no CPU, so only the wall-clock limit can stop it.
import time
time.sleep(3600)
+4
View File
@@ -0,0 +1,4 @@
# Correct solution: prints the sum of the integers on standard input.
import sys
print(sum(int(token) for token in sys.stdin.read().split()))
+3
View File
@@ -0,0 +1,3 @@
# Syntax error: the syntax check must reject it before any test runs.
def broken(:
return 1