Playground(本地)
English summary. Playground is a local Python stdlib HTTP service that compiles/runs Q+ code with per-run temp dirs, ulimit, timeout/output/concurrency limits and host-path scrubbing; async/thread examples are VM-only. It is not a security sandbox and is not a deployed public service in the release tree (deployment is a separate planning input).
Q+ Playground 是本地开发用的轻量 Web 运行环境:site/playground.py 提供编辑页面与 POST /api/run 接口,用发布树工具链(build/bqvm + build/qboot.qbc)在临时目录编译并执行 Q+ 源码,返回 stdout/stderr/退出码与耗时。
启动(Getting Started)
首次使用见 快速上手;本地服务/限制不变。
启动
python3 site/playground.py --host 127.0.0.1 --port 8787 --qplus-root .
GET /:Playground 编辑页(textarea + Run + 输出);GET /api/health:服务与工具链/限制信息(不泄露主机路径);POST /api/run:{"source": "..."}→{ok, stdout, stderr, exit, ms, ...}。
部署包与安全边界(v1.7.0)
- 部署文档:
docs/PLAYGROUND_DEPLOY.md(本地/内部演示; 不是沙箱、不是公网安全边界;Docker/systemd/nginx 模板未生产验证,不得直接公网暴露)。 - 模板:
deploy/playground/Dockerfile、Dockerfile.multistage、qplus-playground.service、nginx-qplus-playground.conf;本机 smokePLAYGROUND_SMOKE_PASS(hex/u64 用例 + /api/health- /api/run)。部署包仅本地/内部演示用途;不联网、不推送镜像。
真实运行限额(site/playground.py 源码 + HTTP 实测)
| 项 | 值 | 实测/说明 |
|---|---|---|
| 源码 | 200,000 B | 超限 413 source too large: ... (limit 200000 bytes) |
| 请求体 | 256,000 B | 超限 413 request body too large: ... |
| VM 运行超时 | 3,000 ms(墙钟 +3 s 强杀) | 死循环 ok=false, stage=run, exit=1, error="execution timed out after 3000 ms" |
| 编译超时 | 15 s | stage=compile/exit=124/compilation timed out |
| 并发 | 2 | MAX_CONCURRENT=2 |
| 输出上限 | 64,000 字符 | 尾部 ... [output truncated](实测 64,023 字符含标记) |
| 资源 | 编译 1 GiB/10 s CPU;运行 256 MiB/4 s CPU/1024 KB 文件 | 每次独立临时目录 + 清理 |
| 禁用 | extern、裸 sys_*、use std.file/http/http_client/socket/env/process; | 400 source rejected: ...(alpha 守卫,非安全边界) |
| 文件系统 | 仅 per-run 临时目录(std.fs/std.io 文件函数可用) | 实测 true tmpfs;运行后清理,无持久化 |
| 网络 | 无真实网络 | raw sys 禁用;真 loopback 未提供(std.net -8) |
详见
docs/PLAYGROUND.md:完整限额、错误 JSON、stdlib 子集、 文件系统/网络边界与不得宣称项。编译/运行失败常返回 HTTP 200(ok=false+stage/exit/error), 仅请求级校验 400/413;非沙箱/不要公网暴露。
限制(本地工具,非公开服务)
- 每次请求新建临时目录;对编译/运行施加 wall-clock 与资源限制(ulimit/timeout/源码长度守卫);
- 输出中的主机路径被清洗;不是针对不可信公网用户的安全边界——如需暴露请放入容器/低权限用户;
- VM 能力集以当前发布树为准(AOT/网络/线程等按语言支持范围,与文档一致);
- Playground 不联网、不下载依赖;示例仅供参考。
相关文档
参见 PLAYGROUND_DEPLOY.md:本地/非公开/非安全边界,不得公网暴露;Docker 模板未生产验证。