{"id":37116731,"url":"https://github.com/criyle/go-judge","last_synced_at":"2026-04-02T16:18:19.856Z","repository":{"id":40237510,"uuid":"204219780","full_name":"criyle/go-judge","owner":"criyle","description":"Sandbox service built on Linux container technologies with simple REST and gRPC API","archived":false,"fork":false,"pushed_at":"2026-03-23T20:14:32.000Z","size":1061,"stargazers_count":590,"open_issues_count":0,"forks_count":84,"subscribers_count":9,"default_branch":"master","last_synced_at":"2026-03-24T18:13:00.913Z","etag":null,"topics":["cgroup","cgroup-v2","cgroup2","container","docker","envexec","executor-service","go","golang","jobobject","oj","online-judge","sandbox","vfork"],"latest_commit_sha":null,"homepage":"https://docs.goj.ac","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/criyle.png","metadata":{"files":{"readme":"README.cn.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-08-24T22:32:38.000Z","updated_at":"2026-03-23T20:14:35.000Z","dependencies_parsed_at":"2025-12-12T04:01:56.737Z","dependency_job_id":null,"html_url":"https://github.com/criyle/go-judge","commit_stats":null,"previous_names":[],"tags_count":158,"template":false,"template_full_name":null,"purl":"pkg:github/criyle/go-judge","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criyle%2Fgo-judge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criyle%2Fgo-judge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criyle%2Fgo-judge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criyle%2Fgo-judge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/criyle","download_url":"https://codeload.github.com/criyle/go-judge/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/criyle%2Fgo-judge/sbom","scorecard":{"id":309114,"data":{"date":"2025-08-11","repo":{"name":"github.com/criyle/go-judge","commit":"2bc4a4fcee9e59660e92be97b9e89e4b129c2a55"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.5,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Code-Review","score":2,"reason":"Found 7/30 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":10,"reason":"21 commit(s) and 10 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: topLevel 'contents' permission set to 'write': .github/workflows/build.yml:7","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:41: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:49: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:72: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/criyle/go-judge/build.yml/master?enable=pin","Warn: containerImage not pinned by hash: Dockerfile.goreleaser:1: pin your Docker image by updating debian:latest to debian:latest@sha256:6d87375016340817ac2391e670971725a9981cfc24e221c47734681ed0f6c0f5","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   3 third-party GitHubAction dependencies pinned","Info:   0 out of   1 containerImage dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/build.yml:9"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v1.9.4 not signed: https://api.github.com/repos/criyle/go-judge/releases/221961294","Warn: release artifact v1.9.3 not signed: https://api.github.com/repos/criyle/go-judge/releases/210259030","Warn: release artifact v1.9.2 not signed: https://api.github.com/repos/criyle/go-judge/releases/205437114","Warn: release artifact v1.9.1 not signed: https://api.github.com/repos/criyle/go-judge/releases/205404280","Warn: release artifact v1.9.0 not signed: https://api.github.com/repos/criyle/go-judge/releases/201883391","Warn: release artifact v1.9.4 does not have provenance: https://api.github.com/repos/criyle/go-judge/releases/221961294","Warn: release artifact v1.9.3 does not have provenance: https://api.github.com/repos/criyle/go-judge/releases/210259030","Warn: release artifact v1.9.2 does not have provenance: https://api.github.com/repos/criyle/go-judge/releases/205437114","Warn: release artifact v1.9.1 does not have provenance: https://api.github.com/repos/criyle/go-judge/releases/205404280","Warn: release artifact v1.9.0 does not have provenance: https://api.github.com/repos/criyle/go-judge/releases/201883391"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 9 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-17T22:49:09.263Z","repository_id":40237510,"created_at":"2025-08-17T22:49:09.264Z","updated_at":"2025-08-17T22:49:09.264Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31051893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T16:55:14.406Z","status":"ssl_error","status_checked_at":"2026-03-27T16:55:07.885Z","response_time":164,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cgroup","cgroup-v2","cgroup2","container","docker","envexec","executor-service","go","golang","jobobject","oj","online-judge","sandbox","vfork"],"created_at":"2026-01-14T13:40:45.374Z","updated_at":"2026-04-02T16:18:19.812Z","avatar_url":"https://github.com/criyle.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-judge\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/criyle/go-judge.svg)](https://pkg.go.dev/github.com/criyle/go-judge) [![Go Report Card](https://goreportcard.com/badge/github.com/criyle/go-judge)](https://goreportcard.com/report/github.com/criyle/go-judge) [![Release](https://img.shields.io/github/v/tag/criyle/go-judge)](https://github.com/criyle/go-judge/releases/latest) ![Build](https://github.com/criyle/go-judge/workflows/Build/badge.svg)\n\n[English](README.md) | [文档](https://docs.goj.ac/cn)\n\n快速，简单，安全\n\n## 快速上手\n\n### 安装和运行\n\n下载对应平台预编译二进制文件 `go-judge` [Release](https://github.com/criyle/go-judge/releases) 并在终端开启\n\n或者使用 docker\n\n```bash\ndocker run -it --rm --privileged --shm-size=256m -p 5050:5050 --name=go-judge criyle/go-judge\n```\n\n### REST API 接口\n\n沙箱服务提供 REST API 接口来在受限制的环境中运行程序（默认监听于 `localhost:5050`）。\n\n- **POST /run 在受限制的环境中运行程序**\n- GET /file 得到所有在文件存储中的文件 ID 到原始命名映射\n  - POST /file 上传一个文件到文件存储，返回一个文件 ID 用于提供给 /run 接口\n  - GET /file/:fileId 下载文件 ID 指定的文件\n  - DELETE /file/:fileId 删除文件 ID 指定的文件\n- /ws /run 接口的 WebSocket 版\n- /stream 运行交互式命令。支持流式 api\n- /version 获取构建的 Git 版本 (例如 v1.9.0) 以及运行时信息 (go 版本, 操作系统, 平台)\n  - /config 获取部分配置信息 (例如 fileStorePath, runnerConfig) 以及支持的功能特性\n\n### REST API 接口定义\n\n[接口数据类型定义](https://docs.goj.ac/cn/api#rest-api-接口定义)\n\n### 示例\n\n请使用 postman 或其他 REST API 调试工具向 http://localhost:5050/run 发送请求\n\n[请求实例](https://docs.goj.ac/cn/example)\n\n## 进阶设置\n\n### 运行要求\n\n- Linux 内核版本 \u003e= 3.10\n- 系统 Cgroup 文件系统挂载于 `/sys/fs/cgroup`（Systemd 默认）\n\n### 系统架构\n\n```text\n+----------------------------------------------------------------------------+\n| 传输层 (HTTP / WebSocket / FFI / ...)                                      |\n+----------------------------------------------------------------------------+\n| 工作协程 (运行环境池 和 运行环境生产者 )                                     |\n+-----------------------------------------------------------+----------------+\n| 运行环境                                                   | 文件存储       |\n+--------------------+----------------+---------------------+----------+-----+\n| Linux (go-sandbox) | Windows (winc) | macOS (app sandbox) | 共享内存 | 磁盘 |\n+--------------------+----------------+---------------------+----------+-----+\n```\n\n### 配置\n\n服务相关:\n\n- 默认监听地址是 `localhost:5050`，使用 `-http-addr` 指定\n- 默认 gRPC 接口处于关闭状态，使用 `-enable-grpc` 开启\n  - 默认 gRPC 监听地址是 `localhost:5051` ，使用 `-grpc-addr` 指定\n- 默认日志等级是 info ，使用 `-silent` 关闭 或 使用 `-release` 开启 release 级别日志(在 docker 中会自动开启)\n- 默认没有开启鉴权，使用 `-auth-token` 指定令牌鉴权\n- 默认没有开启 go 语言调试接口（`localhost:5052/debug`），使用 `-enable-debug` 开启，同时将日志层级设为 Debug\n- 默认没有开启 prometheus 监控接口，使用 `-enable-metrics` 开启 `localhost:5052/metrics`\n- 在启用 go 语言调试接口或者 prometheus 监控接口的情况下，默认监控接口为 `localhost:5052`，使用 `-monitor-addr` 指定\n\n沙箱相关:\n\n- 默认同时运行任务数为和 CPU 数量相同，使用 `-parallelism` 指定\n- 使用 `-mount-conf` 指定沙箱文件系统挂载细节，详细请参见 [文件系统挂载](https://docs.goj.ac/cn/mount) (仅 Linux)\n- 使用 `-file-timeout` 指定文件存储文件最大时间。超出时间的文件将会删除。（例如指定 `30m` 时，缓存文件将在创建后 30 分钟删除）\n- 默认文件存储在共享内存文件系统中（`/dev/shm/`），可以使用 `-dir` 指定另外的本地目录为文件存储\n- 默认最大输出限制为 `256MiB`，使用 `-output-limit` 指定 POSIX rlimit 的输出限制\n- 默认最大 `copyOut` 文件大小为 `64MiB` ，使用 `-copy-out-limit` 指定\n\n可以[在此查看更多配置文档](https://docs.goj.ac/cn/configuration)。\n\n### 指标监控\n\n[Prometheus 指标监控接口](https://docs.goj.ac/cn/api#prometheus-监控接口)\n\n### 在沙箱中运行终端\n\n从 [Release](https://github.com/criyle/go-judge/releases) 下载 `go-judge-shell` 。运行将连接本地 `go-judge` 沙箱服务并开启一个容器内的终端用于调试。\n\n### /run 接口返回状态\n\n- Accepted: 程序在资源限制内正常退出\n- Memory Limit Exceeded: 超出内存限制\n- Time Limit Exceeded: （通常 `exitStatus` 为 `9`（超时时被 `SIGKILL` 结束））\n  - 超出 `timeLimit` 时间限制\n  - 或者超过 `clockLimit` 等待时间限制\n- Output Limit Exceeded:\n  - 超出 `pipeCollector` 限制\n  - 或者超出 `-output-limit` 最大输出限制\n- File Error:\n  - `copyIn` 指定文件不存在\n  - 或者 `copyIn` 指定文件大小超出沙箱文件系统限制\n  - 或者 `copyOut` 指定文件不存在\n- Non Zero Exit Status: 程序用非 0 返回值退出\n- Signalled: 程序收到结束信号而退出（例如 `SIGSEGV`）\n- Dangerous Syscall: 程序被 `seccomp` 过滤器结束（默认不启用）\n- Internal Error:\n  - 指定程序路径不存在\n  - 或者容器创建失败（比如使用非特权 docker）\n  - 或者其他错误\n\n### 容器的文件系统\n\n在 Linux 平台，默认只读挂载点包括主机的 `/lib`, `/lib64`, `/usr`, `/bin`, `/etc/ld.so.cache`, `/etc/alternatives`, `/etc/fpc.cfg`, `/dev/null`, `/dev/urandom`, `/dev/random`, `/dev/zero`, `/dev/full` 和临时文件系统 `/w`, `/tmp` 以及 `/proc`。\n\n使用 `mount.yaml` [定制容器文件系统](https://docs.goj.ac/cn/mount#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8C%82%E8%BD%BD)。\n\n不使用 `mount.yaml` 时，`/w` 的 `/tmp` 挂载 `tmpfs` 大小通过 `-tmp-fs-param` 指定，默认值为 `size=128m,nr_inodes=4k`\n\n如果在容器的根目录存在 `/.env` 文件，那么这个文件会在容器创建时被载入。文件的每一行会作为环境变量的初始值加入到运行程序当中。\n\n如果之后指定的挂载点目标在之前的挂载点之下，那么需要保证之前的挂载点存在目标文件或者文件夹。\n\n### 注意\n\n\u003e [!WARNING]  \n\u003e Windows 和 macOS 平台为实验性支持，请不要在生产环境使用\n\n#### 使用 cgroup\n\n在 cgroup v1 系统上 `go-judge` 需要 `root` 权限创建 `cgroup`。请使用 `sudo` 以 `root` 用户运行或者确保运行用户拥有以下目录的读写权限 `/sys/fs/cgroup/cpuacct/gojudge`, `/sys/fs/cgroup/memory/gojudge`, `/sys/fs/cgroup/pids/gojudge`。\n\n在 cgroup v2 系统上，`go-judge` 会和 `system dbus` 沟通，创建一个临时 `scope`。如果 `systemd` 不存在，并且拥有 `root` 权限那么将尝试进行嵌套初始化。\n\n如果没有 `cgroup` 的权限，那么 `cgroup` 相关的资源配置将不会生效。\n\n#### cgroup v2\n\n`go-judge` 目前已经支持 cgroup v2 鉴于越来越多的 Linux 发行版默认启用 cgroup v2 而不是 v1 （比如 Ubuntu 21.10+，Fedora 31+）。然而，对于内核版本小于 5.19 的版本，因为 cgroup v2 在内存控制器里面缺少 `memory.max_usage_in_bytes`，内存使用量计数会转而采用 `maxrss` 指标。这项指标会显示的比使用 cgroup v1 时候要稍多，在运行使用内存较少的程序时比较明显。对于内核版本大于或等于 5.19 的版本，`memory.peak` 会被采用。\n\n同时，如果本程序在容器中运行，容器中的进程会被移到 /api cgroup v2 层级中来开启 cgroup v2 嵌套支持。\n\n在 `systemd` 为 `init` 的发行版中运行时，`go-judge` 会使用 `dbus` 通知 `systemd` 来创建一个临时 `scope` 作为 `cgroup` 的根。\n\n在高于 5.7 的内核中运行时，`go-judge` 会尝试更快的 `clone3(CLONE_INTO_CGROUP)` 和 `vfork` 方法.\n\n#### 内存使用\n\n控制进程通常会使用 `20M` 内存。每个容器进程通常会占用 `20M` 内存 + 临时文件系统 (tmpfs) 大小 `2 * 128M`。对于每个请求，它将占用 用户程序限制的最大内存 + 额外限制 (`16k`) + 总 copy out 最大限制。请注意，缓存文件存储在宿主机的共享内存中 (`/dev/shm`)，因此请确保分配了足够的空间。\n\n比方说当并发数（concurrency）为 4 时，容器本身可能占用高达 `60 + (20+32) * 4M = 268M` + 4 \\* 总 copy out 限制 + 总请求的最大内存限制。\n\n由于 Go 语言运行时（runtime）的限制，内存并不会自动返回给操作系统，这可能会导致 OOM Killer 杀死进程。因此引入了一个后台工作线程，用于检查堆内存使用情况并在必要时调用垃圾收集（GC）。\n\n- `-force-gc-target` 默认 `20m`，触发 GC 的最小堆内存使用量\n- `-force-gc-interval` 默认 `5s`，检查内存使用情况的间隔时间\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcriyle%2Fgo-judge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcriyle%2Fgo-judge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcriyle%2Fgo-judge/lists"}