Built-in tool: execute shell commands via bash -rc (restricted shell).
Returns stdout/stderr merged with the exit code appended. Output is
capped while the command runs: the first 8,000 and the last 20,000
bytes are kept (errors usually come last) and the middle is replaced by
a marker giving the number of bytes left out, so the result fits in
max_result_chars/0 and memory stays bounded however much a command
prints. Commands that exceed the timeout are killed, together with every
process they started, and return an error.
Context options
Set these in the agent's :context map:
:bash_env- the command's environment. By default the BEAM's environment is inherited minus every variable whose name containsKEY,TOKEN,SECRET,PASSWORDorCREDENTIAL(case-insensitive), so the model cannotprintenv ANTHROPIC_API_KEY. A map such as%{"GITHUB_TOKEN" => token, "DATABASE_URL" => nil}is applied on top of that: a string sets a variable (even a secret-looking one),nilremoves it.:inheritpasses the whole environment unchanged (the behaviour before 0.12.5).:bash_restricted- runbash -r(defaulttrue). See Security.:bash_max_timeout- ceiling in milliseconds for thetimeoutthe model asks for (default 10 minutes). The agent's:tool_timeoutstill applies on top of it.:bash_on_output- optional 1-arity callback(binary() -> any())invoked in a dedicated supervised worker for each raw output chunk as it arrives from the shell port (before head/tail truncation), allowing hosts to inspect or stream raw bytes without blocking shell timeout or cancellation cleanup. The worker queue is bounded (at most 128 chunks and 256 KiB queued in memory; excess chunks are dropped under backpressure with a once-per-command warning log), and command exit waits at most a short flush grace period (250ms, clamped to the remaining command timeout, also logging once if queued chunks remain) so a slow callback never turns a finished command into a timeout. Raising callbacks are rescued and logged once per command; throws or exits terminate only the callback worker while command execution continues.:bash_executor- anexecutor/0that runs the command instead of the local shell, for a container, VM or remote runner. The options above, except the timeout, do not apply to it. Custom executors run inside a supervised worker that is brutally killed on timeout or cancellation (avoid setting:trap_exitunless your executor handles termination).:working_directory- where the command runs (set by the agent).
Security
This tool runs arbitrary commands as the operating-system user of the BEAM. It is not a sandbox; treat the model's shell access like a contractor's laptop on your network.
- Restricted mode stops the top-level shell from using
cd, changingPATH,SHELL,ENVorBASH_ENV, running a command whose name contains/, and redirecting output. It does not apply to programs the shell runs, sobash -c 'cd / && ...',python3 -c,env,find -execand any other interpreter onPATHbypass it. It guards against accidents, not against a model or a prompt injection that tries to escape. :allowed_pathslimits the read, write and edit tools only; this tool ignores it.- The secret filter is a name heuristic: a credential stored under
another name (a
DATABASE_URLwith an embedded password, say) is still inherited. Pass an explicit:bash_envfor anything sensitive. - Timeouts kill the command's process group. A command that starts a
new session (
setsid, a double-forking daemon) leaves that group and survives.
For isolation, supply a :bash_executor that runs commands in a
container or VM.
Usage
config = %{tools: [Alloy.Tool.Core.Bash], ...}The agent can then call:
%{command: "ls -la", timeout: 5000}
Summary
Types
A custom command executor. Receives the shell command string and the working
directory path, and must return {output, exit_code}.
Types
@type executor() :: (command :: String.t(), dir :: String.t() -> {String.t(), non_neg_integer()})
A custom command executor. Receives the shell command string and the working
directory path, and must return {output, exit_code}.
Supply a custom executor via the :bash_executor key in the agent's
:context map to sandbox or proxy shell execution.