`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

Đang mở
#5,615 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
bash, javascript, json, node.js
Lĩnh vực
cli, security

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
11.5k
Fork
2k
Merge trung bình
6 giờ 34 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của github/copilot-cli

Tất cả issue của github/copilot-cli

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.