shell_exec
Run a bash command in the session's shell.
Runs the command in the session's persistent shell. cd and export carry over between calls. The shell starts in /workspace, and browser downloads are in ./downloads.
Inputs
| Name | Type | Default | Allowed values | Description |
|---|---|---|---|---|
sessionIdrequired | string | – | – | The session's id, from session_create. |
commandrequired | string | – | – | The bash command. |
timeoutMs | number | 120000 | – | How long the command may run, in milliseconds, at most 3,600,000 (1 hour). |
sessionId is the id that session_create returned. The server keeps no default session. If that session is stopped, this tool resumes it first, as it was (a resume starts a machine again, and billing with it).
Example call
This is what an MCP client sends. You do not write it yourself: ask the model in plain words and it calls the tool.
{ "name": "shell_exec", "arguments": { "sessionId": "6c1f3c9e-1d2a-4f67-9b0e-1b2c3d4e5f60", "command": "python3 -c 'print(6*7)'" }}What it returns
The command's output (stdout, then stderr) and its exit code.
42[exit code 0]When a call fails, the result is marked as an error. Its text starts with the API’s error code, such as unauthorized or session_not_running, followed by its message.
Annotations
The server tells every client what this tool does to the world, so a client can decide what to ask you about before it runs.
| Annotation | Value |
|---|---|
title | Run a shell command |
readOnlyHint | false |
destructiveHint | true |
openWorldHint | true |
Good to know
- Needs a session with a shell. Without one the call answers
shell_disabled. - A command stopped by its time limit ends with [exit code timeout].
- For a job that takes longer than the time limit, start it in the background with
nohup … > job.log 2>&1 &, which returns at once, and readjob.loglater withfiles_readortail job.log. A background job stops when the session stops.
The same thing with the API
| Endpoint | Reference |
|---|---|
POST /v1/sessions/{id}/shell/exec | Run a command |
These docs describe a beta API. Endpoints, fields and SDK methods may change before general availability; breaking changes will be listed in the changelog.