`sandbox` and `disabledSkills` are not applied in SDK sessions or when changed mid-session, and a blocking `preToolUse` hook fails open on timeout or bad output
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 68/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- bash, javascript, json, node.js
研究方向
Start with the supplied SDK createSession reproduction and inspect how enableConfigDiscovery loads ~/.copilot/settings.json, skills.disabledSkills, and permissions.sandbox. Then reproduce the preToolUse timeout and malformed-JSON cases using ~/.copilot/hooks/guard.json and the ACP prompt flow. Done means discovered and mid-session settings consistently disable skills and enforce sandbox restrictions, and blocking hooks deny calls on timeout or invalid output with the promised warning.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
Some restrictions a user sets for themselves are silently not in force: sandbox and disabledSkills in ~/.copilot/settings.json are ignored by SDK sessions and are not picked up when written during a running session, and a blocking preToolUse guard lets the call run when it times out or prints malformed JSON. In each case nothing tells the user that the restriction is off. Some of this is documented; I'm reporting it because the user-facing result is a restriction the user believes is on.
- SDK sessions with
enableConfigDiscovery: trueload skills from~/.copilotbut ignoredisabledSkillsandsandboxin~/.copilot/settings.json. The docs say, in the bundled SDK'stypes.d.ts, for explicit skill roots, "skill and managed disables still apply", and offerskills.disabledSkillsandpermissions.sandbox("Sandbox configuration applied before MCP servers or session tools start"); they do not say whether discovered user settings are applied. With{"disabledSkills": ["canary-skill"]}, prompt mode answersSkill "canary-skill" not found, while an SDK session lists the personal skill as"enabled": trueand loads it. With the sandbox enabled anddeniedPaths: ["/work/secret-sb"], prompt mode blocksview /work/secret-sb/x.txt; the SDK session tells the model "You are not operating in a sandboxed environment" and returns the file. The session applies the parts of~/.copilotthat add capabilities (skills, MCP servers) but not the parts that remove them. - A blocking
preToolUsehook that times out or prints malformed JSON lets the tool call run, with no warning in-poutput. The docs say: "Timeouts are always fail-open, including forpreToolUseand admin-deployed policy hooks: a warning is surfaced and the tool call proceeds through the normal permission flow rather than being denied", and "If the leftover output is empty, or fails to parse as JSON, the hook is treated as having produced no output and falls through to default behavior" (hooks configuration reference). A guard that exits 2 denies the call, and one that crashes (exit 1) also denies it ("hook errored"), but the same guard lets the call run when it times out (sleep 20withtimeoutSec: 2) or exits 0 with{"permissionDecision": "deny"(no closing brace); the user's--allow-tool=shellgrant then approves it. No timeout warning appeared in-pstdout or stderr or in what the model received. The same happens for MCP tool calls andtask(subagent) calls, in subagents, and in ACP and SDK sessions. sandboxanddisabledSkillswritten to~/.copilot/settings.jsonduring a running session are not applied (subagents.disabledSubagentsis). The docs say: "Most settings apply right away, but a few only take full effect after Copilot CLI restarts—for example,experimentaland the proxy settings. When you change one of these, Copilot tells you a restart is needed" (docs: change settings), and "Sandbox policy changes restart extensions under the new restrictions" (copilot help sandbox, which also says "Edit them there" forsettings.json). In a running ACP session, after the sandbox was enabled withdeniedPaths: ["/work/secret-sb"], the next prompt'sview /work/secret-sb/x.txtreturned the file and the model was still told it is not sandboxed; a skill disabled the same way was still loaded.subagents.disabledSubagentswritten the same way was applied on the next prompt ("The "explore" subagent is turned off"). No restart notice appeared, and a new conversation in the same process did not apply them either.
See also the issue about deny rules, the working-directory boundary and plan mode covering less than the docs say.
Affected version
1.0.114, 1.0.117
Steps to reproduce the behavior
Setup for all steps: a Debian 12 container with Node 22, bubblewrap and socat installed (the sandbox needs them on Linux); a git repository /work with /work/secret-sb/x.txt containing SECRET and the directory /work/canary; a personal skill ~/.copilot/skills/canary-skill/SKILL.md with the front matter name: canary-skill, description: canary skill and the body "Reply with the word CANARY.". Sandbox settings S: {"sandbox": {"enabled": true, "userPolicy": {"network": {"allowOutbound": false, "allowLocalNetwork": false}, "filesystem": {"deniedPaths": ["/work/secret-sb"]}}}}. Prompt-mode runs are echo '<prompt>' | copilot --no-auto-update --no-ask-user --disable-builtin-mcps --allow-tool=shell --allow-tool=write from /work.
- SDK host (Node, run in
/work; add your model configuration tocreateSession, a GitHub token or a provider underinference.providers):
Withimport { CopilotClient, RuntimeConnection } from "<copilot-sdk dir>/index.js"; const client = new CopilotClient({ mode: "coding-agent", runtime: RuntimeConnection.forSpawnedStdio({ path: "<path to the copilot binary>", args: [], workingDirectory: "/work" }) }); const session = await client.createSession({ workingDirectory: "/work", enableConfigDiscovery: true, permissions: { onRequest: async (r) => ({ kind: ["read", "write", "shell"].includes(r.kind) ? "approve-once" : "reject" }) } }); session.on((e) => { if (e.type === "session.skills_loaded") console.error(JSON.stringify(e.data)); }); await session.sendAndWait("Use the canary-skill skill", 120000); await client.stop();~/.copilot/settings.json={"disabledSkills": ["canary-skill"]}: prompt mode "Use the canary-skill skill" answersSkill "canary-skill" not found; the SDK host printssession.skills_loadedwithcanary-skill,"enabled": true, and the tool result isSkill "canary-skill" loaded successfully.. Withsettings.json= S: prompt mode "Use the view tool to show /work/secret-sb/x.txt" answers "<sandbox is active and blocked this command. ...>"; the SDK host with that prompt insendAndWaitreturns the file content. - Create
~/.copilot/hooks/guard.json:
Prompt mode "Run this exact shell command with the bash tool: touch /work/canary/x.txt": the file is created, stderr is empty. With{"version": 1, "hooks": {"preToolUse": [{"type": "command", "bash": "sleep 20; echo blocked >&2; exit 2", "matcher": "bash", "timeoutSec": 2}]}}"bash": "echo blocked >&2; exit 2"(no sleep): "Denied by preToolUse hook: hook exited with code 2", no file. With"bash": "echo '{\"permissionDecision\": \"deny\"'"(notimeoutSec): the file is created. - Start with no
~/.copilot/settings.json. Startcopilot --acp --no-auto-update --disable-builtin-mcpsin/workand send over stdio (one JSON object per line):
Write S to{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1,"clientCapabilities":{"fs":{"readTextFile":false,"writeTextFile":false},"terminal":false}}} {"jsonrpc":"2.0","id":2,"method":"session/new","params":{"cwd":"/work","mcpServers":[]}} {"jsonrpc":"2.0","id":3,"method":"session/prompt","params":{"sessionId":"<sessionId from the reply to id 2>","prompt":[{"type":"text","text":"say ok"}]}}~/.copilot/settings.json, wait a few seconds, then send a secondsession/prompt(id4): "Use the view tool to show /work/secret-sb/x.txt". The content is returned. A new process started with the same file blocks the read. For skills, write{"disabledSkills": ["canary-skill"]}instead and ask to use the skill: it is loaded. With{"subagents": {"disabledSubagents": ["explore"]}}the next prompt is told "The "explore" subagent is turned off. Enable it in /subagents before dispatching it."
Expected behavior
- Expected: a session that discovers configuration from
~/.copilotalso applies the settings there that disable skills or enable the sandbox. Suggested: readdisabledSkillsandsandboxalong with the discovered skills and servers, or say in the SDK docs thatenableConfigDiscoverydoes not apply them and point toskills.disabledSkills/permissions.sandbox. - Expected: a guard that cannot answer in time, or answers with unreadable output, denies the call, at least when configured as blocking. Suggested: an opt-in such as
failClosed: true, and print the documented timeout warning ("a warning is surfaced") in-pmode. - Expected: the sandbox and
disabledSkillsapply from the next prompt, asdisabledSubagentsdoes. Suggested: re-read them when the settings file changes, or report that a restart is needed, as the docs describe for restart-only settings.
Additional context
No response
- 主要語言
- Python
- 星號
- 11.5k
- 分支
- 2k
- 平均合併
- 6 小時 34 分鐘
- 30 天內合併 PR
- 3
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/copilot-cli 的其他 Issue
-
area:plugins
難度 2/5 1-3 小時 新手友好度 75/100
github/copilot-cli#5567 ·
-
難度 1/5 1-3 小時 新手友好度 78/100
github/copilot-cli#5489 ·
-
Built-in functions.view returns no content for large files despite documenting automatic truncation未關閉area:tools
難度 2/5 1-3 小時 新手友好度 72/100
github/copilot-cli#5476 ·
-
triage
難度 1/5 1 小時以內 新手友好度 74/100
github/copilot-cli#5377 ·
-
area:platform-windows area:tools
難度 1/5 1 小時以內 新手友好度 74/100
github/copilot-cli#5340 ·
查看 github/copilot-cli 的全部 Issue
相似的 Issue
-
fidelity
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
backlog
難度 2/5 1-3 小時 新手友好度 72/100
sagemathinc/sagebrush#3434 ·
維護者通常 1 天內回覆
-
marketing
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
documentation good first issue help wanted
難度 2/5 1-3 小時 新手友好度 78/100
wuisabel-gif/MemWhale#576 ·
維護者通常 1 天內回覆
-
Status: Triage Suggestion
難度 2/5 1-3 小時 新手友好度 68/100
GTNewHorizons/GT-New-Horizons-Modpack#27957 ·
維護者通常 1 天內回覆