container_exec
Run commands inside a running Docker container with configurable user, working directory, environment, TTY, and detach options. Returns exit code and output for straightforward automation.
Instructions
Run a command inside a running container (for a compose service, prefer compose_exec).
Security: when any element of cmd is agent-controlled, use an exec-form argv list that does not
invoke a shell (e.g. ["python", "-V"], ["ls", path]). A string cmd, or a shell form like
["sh", "-c", template], interprets shell metacharacters in the untrusted parts.
Args:
cmd: Command to execute (prefer exec-form argv, no shell, when any element is agent-controlled)
tty: Allocate a pseudo-TTY
privileged: Run with extended privileges
user: User to run the command as
detach: Detach from the exec
environment: Environment variables, as {"KEY": "value"} or a list of "KEY=value" strings
workdir: Working directory inside the container
demux: Return stdout and stderr separately
Returns: dict: {"exit_code", "output"}; output is combined stdout+stderr, or a [stdout, stderr] pair with demux=True
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cmd | Yes | ||
| tty | No | ||
| user | No | ||
| demux | No | ||
| stdin | No | ||
| detach | No | ||
| stderr | No | ||
| stdout | No | ||
| workdir | No | ||
| id_or_name | Yes | ||
| privileged | No | ||
| environment | No |