Subscribe to the Non-Human & AI Identity Journal

Shell-formatted Command Execution

Shell-formatted command execution occurs when software builds a command line as text and passes it to a shell or shell-like interpreter. If any part of that command comes from a client, configuration value, or environment variable, injection risk rises sharply because quoting and escaping often fail across all code paths.

Expanded Definition

Shell-formatted command execution is not just “running a command.” It is the practice of assembling a text command and handing it to a shell, where parsing rules for spaces, quotes, metacharacters, redirection, globbing, and expansion decide what actually executes. In NHI and agentic AI environments, that distinction matters because an autonomous workflow may invoke tools with parameters derived from prompts, configuration, or environment variables, turning a routine operational command into an injection boundary.

Definitions vary across vendors on whether a shell wrapper, a system call that invokes a shell, or any command interpreter should be treated under the same control category, but the security concern is consistent: once untrusted text enters the shell grammar, the executable outcome can diverge from the developer’s intent. Guidance from OWASP and MITRE CWE consistently treats command injection as a high-impact abuse path, especially where escaping is incomplete or command construction is split across code paths.

The most common misapplication is assuming that partial quoting or string sanitisation makes shell execution safe, which occurs when one code path still passes attacker-controlled text into a shell interpreter.

Examples and Use Cases

Implementing shell-formatted command execution rigorously often introduces operational friction, because safer APIs and direct process invocation can reduce flexibility for administrators who are used to composing commands dynamically.

  • A deployment script uses a shell command to rotate certificates, but a hostname taken from configuration contains shell metacharacters and alters the execution path.
  • An AI agent generates a diagnostic command from a user request, then passes it to a shell for execution without strict allowlisting, creating an injection surface.
  • A CI/CD job launches backup tooling through a shell wrapper, and an environment variable intended as a file path is interpreted as multiple tokens or options.
  • A service account invokes maintenance commands from an orchestration layer, but command fragments are concatenated from logs or ticket fields that were never intended to be executable.
  • Governance teams reviewing identity pathways use the Ultimate Guide to NHIs alongside NIST Cybersecurity Framework 2.0 to map where scriptable execution should be constrained, logged, and separated from privileged credentials.

Why It Matters in NHI Security

Shell-formatted command execution becomes especially dangerous when service accounts, automation tokens, or AI agents hold privileges broader than the task requires. NHIMG research shows that 97% of NHIs carry excessive privileges and 96% of organisations store secrets outside of secrets managers in vulnerable locations including code, config files, and CI/CD tools, which means a single shell injection event can quickly become credential theft or lateral movement rather than a contained application bug. The same Ultimate Guide to NHIs also reports that 80% of identity breaches involved compromised non-human identities such as service accounts and API keys.

For security teams, the issue is not merely command safety but governance of execution authority. If a workflow can spawn a shell, the identity behind that workflow needs clear limits, strong secret handling, and explicit review of what commands it may form. Aligning controls with NIST Cybersecurity Framework 2.0 helps translate this into repeatable access control, monitoring, and response practices.

Organisations typically encounter the full impact only after a maintenance job, CI pipeline, or agent-driven task has already run an attacker-influenced command, at which point shell-formatted command execution becomes operationally unavoidable to address.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 and OWASP Agentic AI Top 10 address the attack and risk surface, while NIST CSF 2.0, NIST Zero Trust (SP 800-207) and NIST SP 800-63 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP Non-Human Identity Top 10 NHI-02 Shell invocation expands secret and command injection risk under unsafe NHI handling.
OWASP Agentic AI Top 10 A-03 Agent tool use can turn prompt-derived text into unsafe shell commands.
NIST CSF 2.0 PR.AC-4 Least-privilege access limits damage when shell execution is abused.
NIST Zero Trust (SP 800-207) SC-4 Zero Trust principles require validating each execution request and trust boundary.
NIST SP 800-63 Digital identity assurance informs the strength of service identities issuing commands.

Remove shell mediation where possible and treat any command construction from untrusted text as a control failure.