`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

未关闭
#5,615 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
bash, javascript, json, node.js
领域
cli, security

调研方向

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 内容生成。

描述

area:configuration area:permissions area:plugins
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.

  1. SDK sessions with enableConfigDiscovery: true load skills from ~/.copilot but ignore disabledSkills and sandbox in ~/.copilot/settings.json. The docs say, in the bundled SDK's types.d.ts, for explicit skill roots, "skill and managed disables still apply", and offer skills.disabledSkills and permissions.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 answers Skill "canary-skill" not found, while an SDK session lists the personal skill as "enabled": true and loads it. With the sandbox enabled and deniedPaths: ["/work/secret-sb"], prompt mode blocks view /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 ~/.copilot that add capabilities (skills, MCP servers) but not the parts that remove them.
  2. A blocking preToolUse hook that times out or prints malformed JSON lets the tool call run, with no warning in -p output. The docs say: "Timeouts are always fail-open, including for preToolUse and 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 20 with timeoutSec: 2) or exits 0 with {"permissionDecision": "deny" (no closing brace); the user's --allow-tool=shell grant then approves it. No timeout warning appeared in -p stdout or stderr or in what the model received. The same happens for MCP tool calls and task (subagent) calls, in subagents, and in ACP and SDK sessions.
  3. sandbox and disabledSkills written to ~/.copilot/settings.json during a running session are not applied (subagents.disabledSubagents is). The docs say: "Most settings apply right away, but a few only take full effect after Copilot CLI restarts—for example, experimental and 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" for settings.json). In a running ACP session, after the sandbox was enabled with deniedPaths: ["/work/secret-sb"], the next prompt's view /work/secret-sb/x.txt returned the file and the model was still told it is not sandboxed; a skill disabled the same way was still loaded. subagents.disabledSubagents written 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.

  1. SDK host (Node, run in /work; add your model configuration to createSession, a GitHub token or a provider under inference.providers):
    import { 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();
    
    With ~/.copilot/settings.json = {"disabledSkills": ["canary-skill"]}: prompt mode "Use the canary-skill skill" answers Skill "canary-skill" not found; the SDK host prints session.skills_loaded with canary-skill, "enabled": true, and the tool result is Skill "canary-skill" loaded successfully.. With settings.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 in sendAndWait returns the file content.
  2. Create ~/.copilot/hooks/guard.json:
    {"version": 1, "hooks": {"preToolUse": [{"type": "command", "bash": "sleep 20; echo blocked >&2; exit 2", "matcher": "bash", "timeoutSec": 2}]}}
    
    Prompt mode "Run this exact shell command with the bash tool: touch /work/canary/x.txt": the file is created, stderr is empty. With "bash": "echo blocked >&2; exit 2" (no sleep): "Denied by preToolUse hook: hook exited with code 2", no file. With "bash": "echo '{\"permissionDecision\": \"deny\"'" (no timeoutSec): the file is created.
  3. Start with no ~/.copilot/settings.json. Start copilot --acp --no-auto-update --disable-builtin-mcps in /work and send over stdio (one JSON object per line):
    {"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"}]}}
    
    Write S to ~/.copilot/settings.json, wait a few seconds, then send a second session/prompt (id 4): "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
  1. Expected: a session that discovers configuration from ~/.copilot also applies the settings there that disable skills or enable the sandbox. Suggested: read disabledSkills and sandbox along with the discovered skills and servers, or say in the SDK docs that enableConfigDiscovery does not apply them and point to skills.disabledSkills / permissions.sandbox.
  2. 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 -p mode.
  3. Expected: the sandbox and disabledSkills apply from the next prompt, as disabledSubagents does. 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/copilot-cli 的其他 Issue

查看 github/copilot-cli 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。