dsh-sandbox-escalation-prompt
仓库:https://github.com/zhanxin-xu/dsh-sandbox-escalation-prompt
往 DSH 的系统提示词里注入一条沙箱提权纪律(sandbox_permissions 的使用规则),
让 bash / fs / pwsh 等工具在提权请求上不再出现「当前模式本来就允许却仍然申请」
或「只给 justification 却不提权」这类偏差。
注入的文本(默认可通过 text 覆盖)
Only set sandbox_permissions when the current sandbox mode is insufficient and a strictly higher permission level is required.
If the current sandbox mode already permits the operation, omit sandbox_permissions entirely.
Never request the same permission level as the current sandbox mode.
Only include justification together with a real permission escalation.
它是什么 / 不是什么
- 是一条静态的 system-prompt section,对所有 agent(含子代理、所有预设)生效;
- 注册的是 section(提示词正文),不是 context(每轮动态运行时快照):
dsh 自带
sandbox:policy / approval:policy 两个动态 context 会随会话模式变化
(例如 approval=never 时会说「不要请求提权」),本插件不与之冲突,也不复制它们;
静态注册还有个好处:文本不变则提示词前缀稳定,KV cache 不受影响;
- 不使用
complete: true,因此不会顶掉别的人格、工具指引或运行时快照;
- 不 import 任何包,只依赖
ctx.systemPrompt 服务,放在 ~/.dsh/plugins/ 下的裸目录即可加载。
配置(挂载行的 config)
| 字段 | 默认 | 说明 |
|---|
enabled | true | false(或 'false'/'no'/0)时不注入任何 section,用于临时关闭 |
text | 上面四行原文 | 注入文本;纯空白视为不注入 |
order | 9990 | section 排序位,越小越靠前 |
sectionName | user:sandbox-escalation-policy | section 名,必须全局唯一(重名会抛 duplicate 错误) |
order 的常见选择:
| order | 位置 |
|---|
700 | 紧随 PLAN_POLICY(500) / TEAM_POLICY(600) 的策略带 |
1050 | 紧随 TOOL_BASH(1000) / TOOL_PWSH(1010) 的 shell 工具带 |
9990(默认) | 末尾环境事实之前(STRUCTURED_OUTPUT(9900) 之后),作为收尾性纪律,遵循度最好 |
安装到 web profile(本机已按此配置)
# 1. 链接到 profile 的 node_modules
ln -s ../../../plugins/dsh-sandbox-escalation-prompt \
~/.dsh/profiles/web/node_modules/dsh-sandbox-escalation-prompt
# 2. profile package.json 的 dependencies 里登记(让 pnpm install 不再丢掉链接)
# "dsh-sandbox-escalation-prompt": "link:../../plugins/dsh-sandbox-escalation-prompt"
# 3. ~/.dsh/profiles/web/cordis.patch.yml 里挂载
- insert:
- id: sandbox-escalation-prompt
name: dsh-sandbox-escalation-prompt
config:
enabled: true
web profile 的 patchReload 是 live:改完 cordis.patch.yml 无需重启 dsh web,
Host 会热应用补丁;首次在 node_modules 里放链接建议先做,改动补丁文件即可生效。
其它 profile(headless/acp 等)= startup,需要重启进程。
验证
cd ~/.dsh/plugins/dsh-sandbox-escalation-prompt
node scripts/smoke.mjs # 假 ctx:注册/覆盖/开关分支
node scripts/integration.mjs # 真 cordis + 真 dsh-system-prompt:装配后提示词确实含四行
热加载/重启后还可以这样确认运行中的 Host 真的注入了:读当前会话日志里最近一条
system/message 事件(就是渲染后的完整系统提示词):
zstd -dc ~/.dsh/sessions/--Users-user-.dsh--/session-*/session.v3.jsonl.zstd \
| grep -c "Never request the same permission level as the current sandbox mode"
关闭与卸载
- 临时关闭:把挂载行
config.enabled 改成 false(热加载立即生效);
- 彻底移除:删掉
cordis.patch.yml 里的挂载行,再删 node_modules 链接与
package.json 里的依赖登记,最后删除本目录。
目录结构
dsh-sandbox-escalation-prompt/
├── package.json # 声明 dsh.bundle.patch(供 dsh plugin add 安装时自挂载)
├── cordis.patch.yml # 自挂载补丁;已手工挂载时用 !!js 守卫自动退让,避免重复挂载
├── lib/index.js # 插件本体:注册 system-prompt section
├── scripts/smoke.mjs # 离线单元 smoke 测试
├── scripts/integration.mjs # 真 cordis + 真 systemPrompt 集成测试
└── README.md