2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

macOS・Linux・WSL2 でサンドボックス動作差を吸収する実装(2026-10-10 時点)

2
Posted at

同じ settings.json を配っても、Claude Code のサンドボックス配下では OS ごとに挙動とエラー文言が変わります。本稿は、プラットフォームを検出し、ファイルシステム/ネットワークの拒否を正規化して報告する一本の診断スクリプトを、ゼロから再現可能な形で示します。技術的主張はすべて公式ドキュメントの逐語照合済み範囲に限定します(検証日 2026-10-10)。

対応プラットフォームと実施機構(citation-first)

Claude Code のサンドボックスが動く範囲は限定されています。

The sandbox runs on macOS, Linux, and WSL2. On native Windows, Claude Code runs commands unsandboxed.

macOS・Linux・WSL2 で動作し、ネイティブ Windows ではコマンドは非サンドボックスで走ります。OS レベルの実施機構は分かれており、macOS は uses Seatbelt for sandbox enforcement、Linux と WSL2 は bubblewrap を使います。Linux/WSL2 では bubblewrap がファイルシステム分離を担い、socat がネットワークをサンドボックスプロキシ経由にルーティングします。基盤はオープンソースの @anthropic-ai/sandbox-runtime です。

差異を正規化する着眼点

ホームディレクトリへの書き込みテストのエラーは OS で異なります。

touch ~/sandbox-probe Fails with Operation not permitted on macOS, or Read-only file system on Linux and WSL2

同じ touch 失敗でも文言が違うため、エラー文字列から実施機構を逆引きできます。ネットワーク面も、Linux/WSL2 はネットワーク名前空間で分離し、macOS は Seatbelt がプロキシ以外の接続をブロックします。localhost 接続は macOS では network.allowLocalBinding を true にすると全ポートへ届きますが、a sandboxed command's localhost is private to that command のため Linux/WSL2 では同設定は効きません。認証情報マスキングも Linux/WSL2 はセンチネルコピーを読めるのに対し、macOS では sandboxed commands can't read the file at all という deny 相当になります。

References

[1] https://code.claude.com/docs/en/sandboxing

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?