BetaServer tools are currently in beta. The API and behavior may change.
openrouter:bash server tool gives a model the ability to run shell
commands. It mirrors Anthropic’s native bash tool and is available on the
Anthropic Messages API only (/api/v1/messages). When the model needs to
run a command, it calls the tool; with server-side execution enabled,
OpenRouter runs the command inside an isolated, sandboxed Linux container and
returns the combined output and exit code.
Messages API only
openrouter:bash is only available on the Anthropic Messages API. Requesting
it on the Chat Completions or Responses API returns a 400 error. On those
APIs, use a client-side function tool instead.How It Works
- You include
{ "type": "openrouter:bash" }in yourtoolsarray on a Messages API request. - Based on the user’s prompt, the model decides whether it needs to run a command and emits the call with one or more shell commands.
- With
engine: "openrouter", OpenRouter executes the commands sequentially in a sandboxed container. - The combined
stdout,stderr, andexitCodeare returned to the model. - The model incorporates the result into its response. It may run multiple command batches in a single request if needed.
engine: "openrouter" on the tool (see
Execution engine). With the default engine (auto), the
tool call is returned to your application to run client-side instead.
Quick Start
Send the tool on a Messages API request. Setengine: "openrouter" to run
commands server-side in the OpenRouter sandbox.
Configuration
The bash tool accepts optionalparameters to choose its execution
environment:
| Parameter | Type | Default | Description |
|---|---|---|---|
environment | object | container_auto | Execution environment. Use { "type": "container_auto" } for an OpenRouter-managed container, or { "type": "container_reference", "container_id": "..." } to reuse an existing container |
engine | string | auto | Where commands run: openrouter runs them server-side in the OpenRouter sandbox; auto/native (the default) return the tool call to your application to run client-side. See Execution engine |
Call Arguments
The model generates the call arguments. They mirror Anthropic’s native bash tool action:| Field | Type | Description |
|---|---|---|
command | string | A single shell command to run |
commands | string[] | Shell commands to run sequentially |
restart | boolean | Reset the shell session (see Restart) |
timeout_ms | integer | Maximum execution time for the batch |
max_output_length | integer | Maximum characters returned per stream (stdout and stderr are each capped to this) |
Anthropic Messages API native bash tool
On the Messages API you can also use Anthropic’s native bash tool shape ({ "type": "bash_20250124", "name": "bash" }) instead of openrouter:bash.
bash_20250124 tool runs client-side by default: OpenRouter
returns the tool_use to your application to execute locally, exactly as a
direct call to the provider would. To run commands server-side in OpenRouter’s
sandbox instead, send the OpenRouter tool shape with engine: "openrouter":
Restart
Anthropic’s bash tool supports arestart action that resets the shell
session. When the model emits { "restart": true }, OpenRouter provisions a
fresh sandbox container, so commands run after a restart start from a clean
state. The reset applies for the remainder of the current agentic turn. To keep
a container alive across separate API requests in a conversation, send a stable
session_id on each request — the sandbox is keyed by it.
Execution engine
Theengine parameter controls where commands run:
openrouter— run commands server-side in the OpenRouter sandbox.auto(default) /native— native passthrough: the tool call is returned to your application to run client-side, and OpenRouter does not execute the commands. The nativebash_20250124tool always uses this behavior, since it has noenginefield.
openrouter, while
the default leaves command execution to your own application.
Response Format
When the model calls the bash tool, it receives a response like:exitCode indicates the command itself failed; the error output is
returned on stderr so the model can read and react to it.
Security
Running shell commands is powerful and is sandboxed by design:- Commands execute in an isolated container — not on OpenRouter
infrastructure or your machine. With
container_autothe container is ephemeral; withcontainer_referenceit persists across requests. - Containers are scoped per account, so they are never shared across tenants.
- Network access is intended to be disabled by default at the container level.
- Execution time is bounded by
timeout_ms(clamped to a server-side maximum). stdoutandstderrare each truncated tomax_output_length(a per-stream cap, itself clamped to a server-side maximum).
Next Steps
- Server Tools Overview — Learn about server tools
- Web Fetch — Fetch content from URLs
- Tool Calling — Learn about user-defined tool calling