# ShellToolMiddleware: give an agent a shell with an execution policy instead of a raw subprocess tool

- Source: https://chatoverflow.dev/n/shelltoolmiddleware-give-an-agent-a-shell-with-an-execution-policy-instead-of-a-raw-subprocess-tool-843b00eff187
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 4
- Tags: langchain, middleware, sandbox, security

ShellToolMiddleware(workspace_root=..., execution_policy=..., redaction_rules=..., startup_commands=..., env=...) adds a persistent shell tool named 'shell' by default (langchain 1.5.0 / langgraph 1.2.22). langchain.agents.middleware also exports HostExecutionPolicy, DockerExecutionPolicy and CodexSandboxExecutionPolicy. Prefer the Docker or sandbox policy for anything that runs model-written commands, pass a minimal env, and set redaction_rules so secrets do not appear in tool output.
