关于Claude Code开启sandbox沙箱之后curl命令无法访问局域网

系统环境

  • 宿主机:win11

  • WSL2:ubuntu 24.04

  • WSL 网络模式:NAT模式

  • Claude Code:2.1.81 (安装到WSL中)

  • Claude Code 沙箱配置 (~/.claude/settings.json代码片段如下)

    json 复制代码
    {
      "sandbox": {
        "enabled": true,
        "autoAllowBashIfSandboxed": true,
        "allowUnsandboxedCommands": false,
        "excludedCommands": ["docker"],
        "filesystem": {
          "allowWrite": ["//tmp/build"],
          "denyRead": ["~/.config/opencode", "~/.codex", "~/.local/share/opencode", "~/.ssh"]
        },
        "network": {
          "allowedDomains": ["github.com"],
          "allowUnixSockets": [
            "/var/run/docker.sock"
          ]
        }
      }
    }

问题现象

在 claude cli 中,执行bash命令,命令为通过 curl 访问宿主机win11局域网中的设备。

发现执行 curl 命令时总是出现关于 Uses proxy env variable no_proxy == 'localhost,127.0.0.1,::1,*.local,.local,169.254.0.0/16,10.0. 0.0/8,172.16.0.0/12,192.168.0.0/16' 的提示。导致自动化测试时失败。

问题分析

claude code 开启沙箱之后,会自动设置 NO_PROXYno_proxy,设置值为 localhost,127.0.0.1,::1,*.local,.local,169.254.0.0/16,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16

另外还会设置 http_proxy=http://localhost:3128https_proxy=http://localhost:3128

我尝试了在 ~/.claude/settings.jsonenv 中设置 no_proxyNO_PROXY 为空,实际没有效果

curl 纳入 excludedCommands ,即 "excludedCommands": ["docker", "curl"] ,理论上 curl 命令就不应该在沙箱中运行了,但是实际发现仍然在沙箱中运行。查了一下 Claude Code 仓库的 issue ,发现属于官方文档中的一个bug。

该照提示进行修改,将 "excludedCommands": ["docker", "curl"] 修改为 "excludedCommands": ["docker:*", "curl:*"] 可以解决问题。

相关推荐
小陈同学呦2 小时前
我想搭建一个AI编程平台:让每个人都能用提示词“召唤”出想要的项目
ai编程
ZzT3 小时前
CLAUDE.md 到底该怎么写?从「给 AI 的交接文档」说起
ai编程·claude
小陈同学呦3 小时前
从“前后端分离”到“超级个体”:AI编码时代的一点感想
人工智能·ai编程
github.com/starRTC4 小时前
vscode系列:在vscode里面使用skills
ai编程
zhuyan1085 小时前
【AI编程】aider安装记录
linux·运维·ai编程
写点啥呢5 小时前
最适合AOSP开发的AI编辑器——cursor
agent·ai编程·cursor
程序员陆业聪5 小时前
Anthropic 的 Harness 启示:当 AI Agent 开始「长跑」,架构才是真正的天花板
ai编程
轻帆向远5 小时前
智能编码辅助工具在大型软件工程中的应用概述
软件工程·ai编程
yuki_uix6 小时前
一次 CR 引发的思考:我的 rules.ts 构想,究竟属于哪种开发哲学?
前端·ai编程