快速开始
环境要求
| 项 | 说明 |
|---|---|
| OS | Linux(推荐 x86_64);需可用 user namespace |
| cgroup | v1 / v2 / hybrid 自动探测;对应控制器目录需可写 |
| Go | 1.27+(编译本项目) |
| 语言工具链 | gcc / g++ / go(运行镜像内置) |
make check-cgroup # 检查本机 cgroup 是否可用
无 cgroup 写权限时,安全测试会失败(不会静默跳过)。容器内建议 --privileged + --cgroupns=host。
开箱体验
一条命令拉起带页面的 demo(需 Linux + Docker;必须 --privileged --cgroupns=host):
DEMO=registry.cn-beijing.aliyuncs.com/jiangbytecr/light-sandbox-demo:latest
docker pull "$DEMO"
docker run --rm --privileged --cgroupns=host \
-p 8880:8880 -p 8888:8888 -p 8889:8889 \
"$DEMO"
浏览器打开 http://127.0.0.1:8880,选择 C / C++ / Go 后点「运行」即可。也可直接调 HTTP 8888 / gRPC 8889(与页面同源反代共用同一沙箱进程)。demo 镜像关闭鉴权,仅用于演示;生产请用纯沙箱镜像并开启 Auth。
| 镜像 | 用途 | 端口 |
|---|---|---|
light-sandbox-demo |
页面 + 沙箱 HTTP / gRPC | 8880 / 8888 / 8889 |
light-sandbox |
仅沙箱 API / gRPC | 8888 / 8889 |
快速开始
make build
make run
# 等价:./bin/light-sandbox -f etc/sandbox.yaml
| 服务 | 默认地址 |
|---|---|
| HTTP | http://127.0.0.1:8888 |
| gRPC | 127.0.0.1:8889 |
| Prometheus(HTTP) | http://127.0.0.1:9091/metrics |
| Prometheus(gRPC) | http://127.0.0.1:9092/metrics |
配置文件:etc/sandbox.yaml。更多命令见 make help。
# 健康检查
curl -s localhost:8888/api/v1/health
# 同步执行(C:files + steps)
curl -s localhost:8888/api/v1/run -H 'Content-Type: application/json' -d '{
"language": "c",
"files": [{"path": "main.c", "content": "#include <stdio.h>\nint main(){printf(\"%d\\n\",1+1);}\n"}],
"steps": [
{"name": "compile", "command": ["gcc", "-O2", "main.c", "-o", "main"]},
{"name": "run", "command": ["./main"]}
],
"artifacts": ["main"],
"limits": {"cpu_ms": 1000, "clock_ms": 2000, "memory_kb": 65536, "output_kb": 1024, "proc": 16}
}'