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

+38
View File
@@ -0,0 +1,38 @@
//go:build linux
package sandbox
import (
"os"
"os/exec"
"syscall"
)
const signalKill = int(syscall.SIGKILL)
func platformSupported() error {
return nil
}
// attachToCgroup starts nsjail directly inside the run cgroup, so no
// instruction of nsjail or of the program runs outside its limits, and kills
// nsjail if the runner dies.
func attachToCgroup(cmd *exec.Cmd, cgroup *runCgroup) {
cmd.SysProcAttr = &syscall.SysProcAttr{
UseCgroupFD: true,
CgroupFD: int(cgroup.dir.Fd()),
Setpgid: true,
Pdeathsig: syscall.SIGKILL,
}
}
// peakMemoryKB returns ru_maxrss of nsjail in KiB, the fallback when the
// kernel has no memory.peak. It overstates small programs because it
// includes the runner's resident set at exec.
func peakMemoryKB(state *os.ProcessState) int64 {
usage, ok := state.SysUsage().(*syscall.Rusage)
if !ok {
return 0
}
return usage.Maxrss
}