Home

Shell Tool

The shell tool allows agents to execute commands in a bash shell. Each command is evaluated by the shell guard before execution.

shell

Executes a shell command and returns its output.

ParameterTypeRequiredDescription
commandstringThe shell command to execute
timeout_msinteger (min: 1)Timeout in milliseconds. Defaults to 10000 (10 seconds)
descriptionstringHuman-readable description of what the command does (for logging only)

The per-call timeout is clamped to a provider-specific maximum (e.g., 10 minutes). Output includes the exit code, duration, and stdout/stderr content. If the command exceeds the timeout, it is killed and the partial output is returned with a [TIMED OUT] indicator.

Guard Pipeline

The shell guard evaluates commands using a multi-step pipeline:

  1. Command extraction — the raw command string is parsed to extract individual segments (splitting on &&, ||, ;, etc.) and command substitutions. Wrapper commands (bash -c, sh -c, etc.) are recursively unwrapped up to 5 levels of nesting. Commands longer than 8,192 bytes are rejected.

  2. Safe pattern check — each segment is tested against the combined set of safe patterns from all guard packs. If a segment matches a safe pattern, it is considered safe and skips destructive checking.

  3. Destructive pattern check — segments that did not match any safe pattern are tested against destructive patterns. A match produces a Deny or Warn verdict depending on the pattern's confidence level and the session's trust level.

  4. Default verdict — segments that match neither safe nor destructive patterns receive the default verdict based on trust level:

    • Low trust: Deny (default-deny)

    • Medium / High trust: Allow (default-allow)

The strictest verdict across all segments becomes the final verdict for the command.

Command Extraction

The extraction pipeline handles:

  • Shell wrappersbash -c "...", sh -c "...", zsh -c "...", and Windows equivalents (cmd /c, powershell -command) are unwrapped recursively, including path-qualified variants like /usr/bin/bash

  • Environment wrappersenv prefixes (with flags like -u, -C, -S, -i, VAR=val) are stripped to expose the inner command

  • Compound commands — splitting on &&, ||, ;, &, and newlines

  • Command substitutions$(...) and backtick expressions are extracted from unquoted and double-quoted contexts (but not single-quoted strings)

  • Sudo/doas — stripped and the inner command re-evaluated; at low trust, sudo/doas alone is denied

  • Pipe segments — passed individually to destructive pattern validators

Trust Level Behavior

Trust LevelDefault (no match)Destructive (high confidence)Destructive (medium confidence)
LowDenyDenyDeny
MediumAllowDenyDeny
HighAllowDenyWarn

Guard Packs

Shell guard patterns are organized into packs — groups of related safe and destructive patterns. Each pack targets a specific domain (filesystem operations, git, cloud services, etc.).

Pack IDNameDescriptionSafe PatternsDestructive Patterns
core.filesystemFilesystemGuards against recursive/forced file deletion and dangerous moves/overwrites4210
core.gitGitGuards against destructive git operations that lose history or modify remote state811
core.obfuscationObfuscationGuards against meta-execution patterns whose purpose is guard bypass05
core.stencilaStencilaGuards the agent's own runtime, credentials, and publishing operations98
bioinformatics.sequence_toolsSequence ToolsGuards against destructive bioinformatics sequence analysis operations174
chemistry.molecular_dynamicsMolecular DynamicsGuards against destructive molecular dynamics and chemistry tool operations33
cloud.awsAWSGuards against destructive AWS operations04
cloud.azureAzureGuards against destructive Azure operations03
cloud.gcpGoogle CloudGuards against destructive GCP operations03
cloud.iacInfrastructure as CodeGuards against destructive IaC operations02
containers.dockerDockerGuards against destructive Docker operations03
containers.kubectlKubernetesGuards against destructive Kubernetes operations03
database.mysqlMySQLGuards against destructive MySQL operations04
database.postgresqlPostgreSQLGuards against destructive PostgreSQL operations04
database.sqliteSQLiteGuards against destructive SQLite operations02
datasets.versioningData VersioningGuards against destructive operations on scientific data versioning tools85
datasets.transferData Transfer ToolsGuards against destructive operations in scientific data transfer tools55
environments.managersEnvironment ManagersGuards against destructive operations on environment and package managers1510
environments.rR LanguageGuards against destructive R package management operations22
geospatial.climate_dataClimate Data ToolsGuards against destructive operations on NetCDF/HDF climate data files23
geospatial.gdalGDAL/OGRGuards against destructive GDAL/OGR geospatial data operations24
hpc.apptainerHPC ContainersGuards against destructive Singularity/Apptainer container operations02
hpc.schedulersHPC SchedulersGuards against destructive HPC job scheduler operations126
latex.build_toolsLaTeX Build ToolsGuards against destructive LaTeX build tool operations22
ml.experiment_trackingML Experiment TrackingGuards against destructive ML experiment and model tracking operations45
notebooks.jupyterJupyter NotebooksGuards against destructive Jupyter notebook operations13
packages.registriesPackage RegistriesGuards against destructive package manager operations affecting registries05
scientific.computingScientific ComputingGuards against destructive operations in scientific computing environments25
system.diskDiskGuards against destructive disk operations03
system.networkNetworkGuards against destructive network operations03
system.servicesServicesGuards against destructive system service operations03
workflows.enginesWorkflow EnginesGuards against destructive operations in scientific workflow engines44
© 2026 Stencila