Shell
provide.foundation.process.aio.shell
¶
TODO: Add module docstring.
Classes¶
Functions¶
async_shell
async
¶
async_shell(
cmd: str,
cwd: str | Path | None = None,
env: Mapping[str, str] | None = None,
capture_output: bool = True,
check: bool = True,
timeout: float | None = None,
allow_shell_features: bool = DEFAULT_SHELL_ALLOW_FEATURES,
**kwargs: Any
) -> CompletedProcess
Run a shell command asynchronously with safety validation.
WARNING: This function uses shell=True. By default, shell metacharacters are DENIED to prevent command injection. Use allow_shell_features=True only with trusted input.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmd
|
str
|
Shell command string |
required |
cwd
|
str | Path | None
|
Working directory |
None
|
env
|
Mapping[str, str] | None
|
Environment variables |
None
|
capture_output
|
bool
|
Whether to capture output |
True
|
check
|
bool
|
Whether to raise on non-zero exit |
True
|
timeout
|
float | None
|
Command timeout in seconds |
None
|
allow_shell_features
|
bool
|
Allow shell metacharacters (default: False) |
DEFAULT_SHELL_ALLOW_FEATURES
|
**kwargs
|
Any
|
Additional subprocess arguments |
{}
|
Returns:
| Type | Description |
|---|---|
CompletedProcess
|
CompletedProcess with results |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If cmd is not a string |
ShellFeatureError
|
If shell features used without explicit permission |
Security Note
For maximum security, use async_run() with a list of arguments instead. Only set allow_shell_features=True if you fully trust the command source.
Safe: await async_shell("ls -la", allow_shell_features=False) # OK Unsafe: await async_shell(user_input) # Will raise ShellFeatureError if metacharacters present Risky: await async_shell(user_input, allow_shell_features=True) # DO NOT DO THIS