Skip to content

Docker sandbox with claude subscription: Invalid Bearer token #68

@jauco

Description

@jauco

Description


╭─── Claude Code v2.1.31 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                    │ Tips for getting started                                                                                                                            │
│                 Welcome back Jauco!                │ Ask Claude to create a new app or clone a repository                                                                                                │
│                                                    │ ────────────────────────────────────────────────────                                                                                                │
│                                                    │ Recent activity                                                                                                                                     │
│                       ▐▛███▜▌                      │ No recent activity                                                                                                                                  │
│                      ▝▜█████▛▘                     │                                                                                                                                                     │
│                        ▘▘ ▝▝                       │                                                                                                                                                     │
│          Sonnet 4.5 · API Usage Billing ·          │                                                                                                                                                     │
│          claude.ai@jauco.nl's Organization         │                                                                                                                                                     │
│                     ~/workspace                    │                                                                                                                                                     │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

  /model to try Opus 4.5

❯ /login
  ⎿  Login successful

❯ test
  ⎿  API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"Invalid bearer token"},"request_id":"req_011CXndDh6ZggVPrT9kKcPzT"} · Please run /login

I ran mitmproxy in the claude container to see what was happening and the relevant part is here:

127.0.0.1:61330: POST https://platform.claude.com/v1/oauth/token
    accept: application/json, text/plain, */*
    accept-encoding: gzip, compress, deflate, br
    content-type: application/json
    user-agent: axios/1.8.4
    Host: platform.claude.com
    Content-Length: 325
    {
        "grant_type": "authorization_code",
        "code": "AX4SLzHEnMFG92ABAbqIyVkXHE13EXNOOB218AhZzJDmDp1B",
        "redirect_uri": "https://platform.claude.com/oauth/code/callback",
        "client_id": "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
        "code_verifier": "MztzWeac8cG94HfNTOWcGi5LC2ETTkbvcHhJfkMI7Wc",
        "state": "qNztbskuGaHKUDkkyIKtIB7cIzLP8iPlC8GzWCESBuE"
    }
 << 200 OK 596b
    Alt-Svc: h3=":443"; ma=86400
    Cache-Control: no-store
    Cf-Cache-Status: DYNAMIC
    Cf-Ray: 9c888fc4f8e1d7a1-AMS
    Connection: close
    Content-Type: application/json
    Date: Wed, 04 Feb 2026 07:47:44 GMT
    Pragma: no-cache
    Request-Id: req_011CXnfDyUnVvzbMjk1BJsJp
    Server: cloudflare
    Set-Cookie: __cf_bm=tKzyKTXkIb5_j9d5W0OhAYX.TApo50wdAYM0ePa5xwE-1770191264-1.0.1.1-lEVQrORHMou_VVvMFPQRGYMaZcbuYI0kxjTp8gLzxPKI2UbBSNwYEIob0wFSJU_Wp.sf.ZGXoQXGiMa_MD9Ez.v41TMz7JABndKOPnwzOcY; path=/; expires=Wed, 04-Feb-26 08:17:44 GMT; domain=.claude.com; HttpOnly; Secure; SameSite=None
    Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
    Transfer-Encoding: chunked
    Via: 1.1 google
    X-Content-Type-Options: nosniff
    X-Envoy-Upstream-Service-Time: 571
    {
        "token_type": "Bearer",
        "access_token": "...omited in bug report...",
        "expires_in": 28800,
        "refresh_token": "...omited in bug report...",
        "scope": "user:inference user:mcp_servers user:profile user:sessions:claude_code",
        "organization": {
            "uuid": "...omited in bug report...",
            "name": "...omited in bug report..."
        },
        "account": {
            "uuid": "...omited in bug report...",
            "email_address": "...omited in bug report..."
        }
    }
[07:47:44.059][127.0.0.1:61330] server disconnect host.docker.internal:3128 (192.168.127.254:3128)
[07:47:44.059][127.0.0.1:61330] client disconnect
[07:47:44.066][127.0.0.1:61346] client connect
[07:47:44.074][127.0.0.1:61346] server connect host.docker.internal:3128 (192.168.127.254:3128)
127.0.0.1:61346: GET https://api.anthropic.com/api/claude_code/organizations/metrics_enabled
    accept: application/json, text/plain, */*
    accept-encoding: gzip, compress, deflate, br
    content-type: application/json
    user-agent: claude-code/2.1.31
    x-api-key: proxy-managed
    Host: api.anthropic.com
 << 401 Unauthorized 186b
    Cf-Cache-Status: DYNAMIC
    Cf-Ray: 9c888fcaaa989fb8-AMS
    Connection: close
    Content-Security-Policy: default-src 'none'; frame-ancestors 'none'
    Content-Type: application/json
    Date: Wed, 04 Feb 2026 07:47:44 GMT
    Request-Id: req_011CXnfE2qCU9JyXUZ5GTfy3
    Server: cloudflare
    Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
    Transfer-Encoding: chunked
    X-Envoy-Upstream-Service-Time: 10
    X-Robots-Tag: none
    X-Should-Retry: false
    {
        "type": "error",
        "error": {
            "type": "authentication_error",
            "message": "x-api-key header is required",
            "details": {
                "error_visibility": "user_facing"
            }
        },
        "request_id": "req_011CXnfE2qCU9JyXUZ5GTfy3"
    }
[07:47:44.287][127.0.0.1:61346] server disconnect host.docker.internal:3128 (192.168.127.254:3128)
[07:47:44.288][127.0.0.1:61346] client disconnect
[07:47:44.295][127.0.0.1:61362] client connect
[07:47:44.301][127.0.0.1:61362] server connect host.docker.internal:3128 (192.168.127.254:3128)

After successful OAuth token exchange with platform.claude.com, subsequent requests to api.anthropic.com are sent with x-api-key: proxy-managed placeholder instead of the actual Authorization: Bearer header.

So it seems the docker sandbox proxy fails to inject OAuth bearer token into requests, while claude expects it to.

Reproduce

  1. docker sandbox run claude .
  2. /login
  3. pick "Claude account with subscription"
  4. Login successfully (paste token back etc)
  5. you'll see "login successful"
  6. Interact with claude, e.g. type "test"

Expected behavior

Claude responds in a confused way to your "test" prompt.

docker version

lient:
 Version:           29.1.5
 API version:       1.52
 Go version:        go1.25.6
 Git commit:        0e6fee6
 Built:             Fri Jan 16 12:47:44 2026
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.58.1 (217134)
 Engine:
  Version:          29.1.5
  API version:      1.52 (minimum version 1.44)
  Go version:       go1.25.6
  Git commit:       3b01d64
  Built:            Fri Jan 16 12:48:37 2026
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          v2.2.1
  GitCommit:        dea7da592f5d1d2b7755e3a161be07f43fad8f75
 runc:
  Version:          1.3.4
  GitCommit:        v1.3.4-0-gd6d73eb8
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client:
 Version:    29.1.5
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Docker AI Agent - Ask Gordon (Docker Inc.)
    Version:  v1.17.1
    Path:     /Users/jauco/.docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.30.1-desktop.2
    Path:     /Users/jauco/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.0.1
    Path:     /Users/jauco/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.47
    Path:     /Users/jauco/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Docker Inc.)
    Version:  v0.2.0
    Path:     /Users/jauco/.docker/cli-plugins/docker-desktop
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.31
    Path:     /Users/jauco/.docker/cli-plugins/docker-extension
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /Users/jauco/.docker/cli-plugins/docker-init
  mcp: Docker MCP Plugin (Docker Inc.)
    Version:  v0.35.0
    Path:     /Users/jauco/.docker/cli-plugins/docker-mcp
  model: Docker Model Runner (Docker Inc.)
    Version:  v1.0.7
    Path:     /Users/jauco/.docker/cli-plugins/docker-model
  offload: Docker Offload (Docker Inc.)
    Version:  v0.5.41
    Path:     /Users/jauco/.docker/cli-plugins/docker-offload
  pass: Docker Pass Secrets Manager Plugin (beta) (Docker Inc.)
    Version:  v0.0.22
    Path:     /Users/jauco/.docker/cli-plugins/docker-pass
  sandbox: Docker Sandbox (Docker Inc.)
    Version:  v0.10.1
    Path:     /Users/jauco/.docker/cli-plugins/docker-sandbox
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/jauco/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.19.0
    Path:     /Users/jauco/.docker/cli-plugins/docker-scout

Server:
 Containers: 4
  Running: 4
  Paused: 0
  Stopped: 0
 Images: 30
 Server Version: 29.1.5
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Discovered Devices:
  cdi: docker.com/gpu=webgpu
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: dea7da592f5d1d2b7755e3a161be07f43fad8f75
 runc version: v1.3.4-0-gd6d73eb8
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.12.65-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 10
 Total Memory: 7.653GiB
 Name: docker-desktop
 ID: 330bab90-5881-4b57-abbf-4a28763ce901
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/jauco/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  ::1/128
  127.0.0.0/8
 Live Restore Enabled: false
 Firewall Backend: iptables

Diagnostics ID

0641202F-8BE8-4409-ADE7-C6EE9C24BAED/20260204080210

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions