Strands Shell — Virtual Shell for AI Agents
- URL: https://strandsagents.com/docs/user-guide/shell/
- Date Saved: 2026-06-19
- Source: Strands Agents documentation
- Tags: ai-engineering, dev-tools
Summary
Strands Shell 是一個 Bourne-compatible 的虛擬 shell,專為 AI agent 設計,跑在你自己的 process 裡面(不需要 container 或 cloud sandbox)。用 Rust 寫的,支援 Python (PyO3)、Node.js (napi-rs) 和 WASM。
核心特點:
- 極快 — 啟動 + 執行命令 < 1ms(對比 Docker ~200ms,cloud sandbox ~1s)
- In-process isolation — 用 VFS (virtual filesystem) + mediation layer 隔離,不用 fork/exec/syscall
- 內建工具 — grep, sed, jq, curl, find 等常見指令都內建,不呼叫系統命令
- Deny-by-default — 全新 shell 啟動時沒有任何存取權限(檔案、網路、credentials),需明確授予
三個控制機制:
- Binds — 把 host 目錄映射進 shell 的 VFS(copy bind = 快照隔離,direct bind = 即時讀寫)
- Credentials — 綁定 secret 到 URL prefix,請求時自動注入,agent 看不到 secret 本身
- Allowed URLs — 網路預設擋 RFC1918/loopback/cloud metadata,白名單放行特定 URL
不是什麼:
- 不是 hardened sandbox — 是 mediation layer,跑在同一個 process
- 對抗 adversarial code 仍需 OS-level isolation(container/microVM)
- Resource limits 是 best-effort,不防主動攻擊者
- 單一 owner 設計,多 agent 要各開一個 instance(建構成本極低)
比較表:
| Docker | Cloud Sandbox | Strands Shell | |
|---|---|---|---|
| Cold start | ~200ms | ~1s | <1ms |
| Isolation | Container namespace | MicroVM | In-process VFS |
| Network | iptables | Platform policy | URL allowlist + SSRF guard |
| Secrets | Env vars (agent可讀) | Platform-specific | 按請求注入,agent不可讀 |
| Setup | Docker daemon | API key + network | pip install strands-shell |
| Platforms | Linux | Cloud only | macOS, Linux, WASM |