For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/agent/guide/rshell.md. A documentation index is available at /llms.txt.

Agent Restricted Shell (rshell)

Overview

The Agent Restricted Shell (rshell) is the command execution layer behind the remote-actions toolset in the Datadog MCP server. When an AI system or developer CLI calls datadog_remote_action_restricted_shell_run_command, rshell is what runs on the host.

rshell is an open source, POSIX-compatible shell interpreter written in Go and embedded in the Private Action Runner (PAR) process. It is not a real host shell. There is no bash, sh, or zsh process spawned. Every command is a purpose-built Go implementation with explicit safety constraints. You can view the source on GitHub.

How it works

When a command is invoked:

  1. The Datadog backend receives the request from the MCP client.
  2. The request is forwarded to the PAR running on the target host.
  3. rshell, embedded in the PAR process, executes the command as a Go builtin.
  4. Output is returned to the backend and surfaced to the MCP client.

The PAR is a customer-installed process. It handles the secure channel between the Datadog backend and the host. rshell runs inside it and never opens a separate shell process on the host.

Why it is safe

rshell enforces the following constraints by design:

  • No write access. rshell has no commands that write to the file system. The only output redirect allowed is >/dev/null. Files cannot be created, modified, or deleted.
  • No external binary execution. rshell cannot call binaries on the host. Every command is a Go builtin inside the PAR process. External commands are blocked unless an explicit ExecHandler is configured.
  • No network egress. Network diagnostic commands (ping, ss, ip) are read-only. ping blocks flood mode, broadcast, and multicast addresses. Background execution (cmd &) is not supported.
  • Path allowlisting. All file access is restricted to directories configured in AllowedPaths. You can further restrict this in your Agent configuration.
  • Backend-controlled command allowlist. The permitted command set is controlled per Agent version from the Datadog backend, using a rshell: namespace prefix (for example, rshell:cat). Individual commands have a killswitch that can be disabled immediately if a security issue is discovered.
  • Empty environment by default. No parent environment variables are inherited. rshell starts with an empty environment unless variables are explicitly passed by the caller.

Supported commands

The following commands and shell features are available as of Agent 7.79.

File inspection

CommandDescription
catPrint file contents; supports line numbering and non-printing character display
lsList directory contents; supports pagination using --offset and --limit
headPrint the first N lines or bytes of a file (default: 10 lines)
tailPrint the last N lines or bytes of a file (default: 10 lines); supports +N offset mode; -f (follow) is blocked
findSearch for files by name, type, size, permissions, and modification time; -delete and -regex are blocked
stringsPrint printable character sequences in files (default minimum length: 4)

Text processing

CommandDescription
grepSearch for patterns; uses RE2 regex engine (linear-time, no backtracking)
sedFilter and transform text; uses RE2 regex engine; -i (in-place edit) and -f (script file) are blocked
cutExtract fields or byte ranges from lines
trTranslate, squeeze, or delete characters
sortSort lines; supports numeric, human-readable, and reverse sorting; -o (output to file) is blocked
uniqFilter or report duplicate lines
wcCount lines, words, bytes, characters, or max line length
printfFormat and print data to stdout

Process and system inspection

CommandDescription
psReport process status; -e/-A shows all processes; -f adds UID/PPID/start time
unamePrint system information (Linux only)

Network diagnostics (read-only)

CommandDescription
pingSend ICMP echo requests and report round-trip statistics; flood, broadcast, and multicast are blocked
ssDisplay network socket statistics; -p (process disclosure) and -K (kill) are blocked
ip addr / ip linkShow network interface addresses and link-layer information
ip routeShow IPv4 routing table or resolve a route for a given address (Linux only)

Shell utilities

CommandDescription
echoWrite arguments to stdout
test / [ ]Evaluate conditional expressions (file tests, string and integer comparison, logical operators)
helpDisplay supported features and available commands
true / falseReturn exit code 0 or 1
exitExit the shell with a given status code

Supported shell features

Control flow

  • for VAR in WORDS; do CMDS; done
  • if / elif / else
  • break and continue for loop control
  • && and || short-circuit lists
  • ! negation
  • { CMDS; } brace groups
  • ( CMDS ) subshells (variable changes do not propagate to the parent)

Pipes and redirections

  • | pipe stdout between commands
  • < input redirection (read-only, within AllowedPaths)
  • >/dev/null, 2>/dev/null, &>/dev/null discard output
  • 2>&1, >&2 file descriptor duplication between stdout and stderr
  • <<DELIM and <<-DELIM heredocs

Write redirections to any target other than /dev/null are blocked.

Variables and expansion

  • Variable assignment: VAR=value
  • Variable expansion: $VAR, ${VAR}
  • $? last exit code
  • Inline assignment: VAR=value command (scoped to that command)
  • Command substitution: $(cmd) and `cmd`; output capped at 1 MiB
  • Single and double quotes
  • Globbing: *, ?, [abc], [a-z], [!a]
  • Line continuation: \ at end of line
  • Comments: # text

Arithmetic expansion $(( )), array assignment, append assignment (+=), and parameter expansion operations such as ${var:-default} are not supported.

Restrict file access

By default, file read commands are gated by a path allowlist managed from the Datadog backend. You can further restrict which paths and commands rshell can access in your Agent configuration.

# datadog.yaml
private_action_runner:
  restricted_shell:
    allowed_paths:
      - /etc/datadog-agent/
      - /var/log/datadog/
    allowed_commands:
      - rshell:cat
      - rshell:grep

Further reading