Orchestrata Ultimate / Specs / 066-powershell-tool
066-powershell-tool: PowerShellTool - Windows PowerShell Execution
The PowerShellTool provides secure, sandboxed execution of PowerShell commands and scripts on Windows systems with comprehensive output filtering, command allowlisting, and execution timeouts.
At a glance
| Item | Value |
|---|---|
| Spec directory | specs/066-powershell-tool/ |
| Status line in the spec | Archived (2026-07-12 — Windows-only, no target host; was: Complete) |
| Requirement IDs defined | 194 |
With a @traces citation in src/ |
0 (0.0%) |
With a @traces citation in tests/ |
0 (0.0%) |
| Tracked files | 2 |
| RTM page | 066-powershell-tool |
Reading this spec
This spec describes PowerShellTool, a tool for sandboxed execution of PowerShell commands and scripts on Windows hosts, for AI agents and automation workflows. The spec is archived: a note at its top records that on 2026-07-12 (session 227, the tool-wave ruling) it was archived because it targets Windows hosts while the deployment fleet is Linux-only, so no PowerShell runtime exists or is planned. The note adds that shell execution is covered by the registered run_shell volk. The status line reads "Archived (2026-07-12 — Windows-only, no target host; was: Complete)".
For historical reference, the scope was single command execution, script file execution with parameter binding, output sanitization and filtering, a command allowlist as the security sandbox, execution timeouts, and detection of the PowerShell binary across platforms. The target systems were Windows Server 2019 or later, Windows 10 and 11, and PowerShell 5.1 or later. Four user stories give the intent: Windows service management, an Active Directory user query, an Azure resource inventory, and file system operations under security restrictions. The functional requirements (FR-001 onward) cover command execution, script execution, allowlist enforcement, execution timeout and output handling.
The 194 requirement IDs (REQ-066-NNN) cover these functions plus security, audit and test conditions. Examples are that the tool executes single commands and captures output within the timeout, sanitizes connection strings, and logs every execution with timestamp, user, command and result for the audit trail.
No code module cites this spec, consistent with the archive decision. The requirements traceability matrix lists every ID. The spec tracks 2 files. No src/ symbol cites any of the 194 requirements, so measured trace coverage is 0.0%, and in tests/, 0 requirements are cited by a test-side @traces. All 194 requirements have no citing symbol; untraced means no @traces names the ID.
Requirements
Checkbox is the state recorded in the requirements checklist; Traced by is the count of src/ symbols whose @traces names the ID.
| ID | Done | Requirement | Traced by |
|---|---|---|---|
REQ-066-001 |
- | The tool MUST execute single PowerShell commands and capture output within the specified timeout period. | none |
REQ-066-002 |
- | Command is executed using detected PowerShell binary | none |
REQ-066-003 |
- | Stdout and stderr are captured separately | none |
REQ-066-004 |
- | Exit code is returned in result | none |
REQ-066-005 |
- | Execution time is measured in milliseconds | none |
REQ-066-006 |
- | The tool MUST execute PowerShell script files (.ps1) with parameter binding. | none |
REQ-066-007 |
- | Script path is validated to exist and end in .ps1 | none |
REQ-066-008 |
- | Parameters are bound using -File parameter syntax | none |
REQ-066-009 |
- | Execution follows same security rules as single commands | none |
REQ-066-010 |
- | Errors during parameter binding return descriptive messages | none |
REQ-066-011 |
- | The tool MUST enforce a command allowlist for security sandboxing. | none |
REQ-066-012 |
- | Commands are validated before execution | none |
REQ-066-013 |
- | Default patterns include Get-, Test-, Select-, Where-, Sort-* | none |
REQ-066-014 |
- | Custom allowlists can be specified per execution | none |
REQ-066-015 |
- | Blocked commands return ERR-003 error | none |
REQ-066-016 |
- | The tool MUST implement configurable execution timeout. | none |
REQ-066-017 |
- | Default timeout is 60 seconds | none |
REQ-066-018 |
- | Timeout range is 1-600 seconds | none |
REQ-066-019 |
- | Process tree is killed on timeout | none |
REQ-066-020 |
- | Timeout error (ERR-002) is returned on expiration | none |
REQ-066-021 |
- | The tool MUST sanitize command output to remove sensitive data. | none |
REQ-066-022 |
- | Passwords, tokens, keys are replaced with [REDACTED] | none |
REQ-066-023 |
- | Connection strings are sanitized | none |
REQ-066-024 |
- | Private keys are masked | none |
REQ-066-025 |
- | Custom patterns can be configured | none |
REQ-066-026 |
- | The tool MUST detect PowerShell binary across platforms. | none |
REQ-066-027 |
- | Windows: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe | none |
REQ-066-028 |
- | Cross-platform: pwsh in PATH | none |
REQ-066-029 |
- | Linux/macOS: /usr/bin/pwsh | none |
REQ-066-030 |
- | Returns ERR-001 if not found | none |
REQ-066-031 |
- | The tool MUST parse and return structured output (JSON/text). | none |
REQ-066-032 |
- | PowerShell objects are serialized to JSON | none |
REQ-066-033 |
- | Text output is preserved as-is | none |
REQ-066-034 |
- | output_json field contains parsed objects when applicable | none |
REQ-066-035 |
- | Null when output cannot be parsed as JSON | none |
REQ-066-036 |
- | The tool MUST support working directory specification. | none |
REQ-066-037 |
- | Optional working_directory parameter | none |
REQ-066-038 |
- | Validates directory exists before execution | none |
REQ-066-039 |
- | ERR-009 returned if directory invalid | none |
REQ-066-040 |
- | The tool MUST implement execution cancellation. | none |
REQ-066-041 |
- | cancel() method accepts execution_id | none |
REQ-066-042 |
- | SIGINT signal sent first (soft cancel) | none |
REQ-066-043 |
- | Force kill after 5 second grace period | none |
REQ-066-044 |
- | ERR-012 returned if cancelled | none |
REQ-066-045 |
- | The tool MUST log all executions for audit trail. | none |
REQ-066-046 |
- | Timestamp recorded for each execution | none |
REQ-066-047 |
- | Command, user, result, and duration logged | none |
REQ-066-048 |
- | Logs include success/failure status | none |
REQ-066-049 |
- | Audit trail is queryable | none |
REQ-066-101 |
- | Command execution latency | < 100ms | < 500ms | | none |
REQ-066-102 |
- | Script startup time | < 200ms | < 1000ms | | none |
REQ-066-103 |
- | Output sanitization | < 50ms | < 200ms | | none |
REQ-066-104 |
- | Memory usage | < 100MB | < 200MB | | none |
REQ-066-105 |
- | Concurrent executions | 10 | 20 | | none |
REQ-066-106 |
- | Uptime | 99.9% availability | | none |
REQ-066-107 |
- | Error recovery | Automatic retry on transient failures | | none |
REQ-066-108 |
- | Graceful degradation | Fallback to default allowlist if custom fails | | none |
REQ-066-109 |
- | Timeout handling | Process tree termination on timeout | | none |
REQ-066-110 |
- | Input validation | All inputs validated before execution | | none |
REQ-066-111 |
- | Sandboxing | Command allowlist enforced by default | | none |
REQ-066-112 |
- | Output filtering | Sensitive data patterns redacted | | none |
REQ-066-113 |
- | Audit trail | All executions logged with full context | | none |
REQ-066-114 |
- | No code injection | Parameterized execution prevents injection | | none |
REQ-066-115 |
- | Windows | Windows 10/Server 2019 | | none |
REQ-066-116 |
- | PowerShell | 5.1 | | none |
REQ-066-117 |
- | PowerShell Core | 7.0+ | | none |
REQ-066-118 |
- | Python | 3.11+ | | none |
REQ-066-119 |
- | Logging | Structured JSON logs with context | | none |
REQ-066-120 |
- | Metrics | Execution count, duration, success rate | | none |
REQ-066-121 |
- | Tracing | OpenTelemetry compatible spans | | none |
REQ-066-122 |
- | Health checks | /health endpoint for liveness | | none |
REQ-066-050 |
- | A tool request SHALL conform to the PowerShellToolRequest JSON Schema below: command of length 1-10000, script_path matching \.ps1$, parameters as an object of string/number/boolean/array/object values, timeout an integer 1-600 defaulting to 60, an optional working_directory, an optional allowlist array of strings, and exactly one of command or script_path required. |
none |
REQ-066-051 |
- | A tool result SHALL conform to the PowerShellToolResult JSON Schema below, carrying success, output (sanitized), output_json (parsed JSON output when applicable), error, exit_code, execution_time_ms and timestamp, with success, exit_code and execution_time_ms required. |
none |
REQ-066-052 |
- | A command validation result SHALL conform to the CommandValidationResult JSON Schema below, carrying allowed (required), blocked_reason and matched_pattern. |
none |
REQ-066-053 |
- | Security configuration SHALL conform to the PowerShellSecurityConfig JSON Schema below, including command_allowlist, command_blocklist, blocked_patterns, execution_timeout_seconds (1-600, default 60), max_output_size_bytes (1024-10485760, default 1048576), sensitive_data_patterns, require_working_directory (default false), and sandbox_mode (one of none, allowlist, blocklist, strict; default allowlist). |
none |
REQ-066-054 |
- | PowerShell executable not found on system | Return error with message, log attempt | | none |
REQ-066-055 |
- | Command execution exceeded timeout | Kill process tree, return timeout error with duration | | none |
REQ-066-056 |
- | Command '{cmdlet}' is not in allowed command list | Block execution, return ERR-003 | | none |
REQ-066-057 |
- | Command '{cmdlet}' is explicitly blocked for security | Block execution, return ERR-004 | | none |
REQ-066-058 |
- | Command contains blocked pattern: {pattern} | Block execution, return ERR-005 | | none |
REQ-066-059 |
- | Script file not found: {path} | Return error with file path | | none |
REQ-066-060 |
- | Script file is not a valid .ps1 file | Validate extension, return ERR-007 | | none |
REQ-066-061 |
- | Failed to bind parameters to script | Return detailed binding error | | none |
REQ-066-062 |
- | Working directory does not exist | Validate before execution, return ERR-009 | | none |
REQ-066-063 |
- | Output size {size} exceeds maximum {max} | Truncate output, return ERR-010 | | none |
REQ-066-064 |
- | Permission denied to execute command | Check permissions, return ERR-011 | | none |
REQ-066-065 |
- | Command execution was cancelled | Return ERR-012 with cancelled status | | none |
REQ-066-066 |
- | Required PowerShell module '{module}' is not installed | Check module availability, return ERR-013 | | none |
REQ-066-067 |
- | PowerShell command syntax error | Return ERR-014 with syntax error details | | none |
REQ-066-068 |
- | Failed to decode PowerShell output | Try multiple encodings, return ERR-015 | | none |
REQ-066-069 |
- | Command exceeds maximum character limit | Validate length, return ERR-016 | | none |
REQ-066-070 |
- | Timeout value is negative, zero, or exceeds maximum | Validate range 1-600, return ERR-017 | | none |
REQ-066-071 |
- | Working directory path traversal attempt detected | Block execution, return ERR-018 | | none |
REQ-066-072 |
- | No command or script path provided | Validate input, return ERR-019 | | none |
REQ-066-073 |
- | The tool SHALL expose the PowerShellTool interface shown below — the name, description and version attributes plus execute, execute_script, validate_command, sanitize_output, get_powershell_path and cancel — implementing BaseTool. |
none |
REQ-066-074 |
- | The tool SHALL return the ToolResult structure shown below, with the fields success, output, output_json, error, exit_code, execution_time_ms and timestamp. |
none |
REQ-066-075 |
- | The tool server SHALL expose the REST endpoints shown below: POST /api/v1/tools/powershell/execute, POST /api/v1/tools/powershell/execute-script, POST /api/v1/tools/powershell/validate and GET /api/v1/tools/powershell/health. |
none |
REQ-066-076 |
- | The tool implements a command allowlist system with the following default patterns: | none |
REQ-066-077 |
- | The tool SHALL explicitly block the cmdlets listed below. | none |
REQ-066-078 |
- | The following regex patterns trigger automatic blocking: | none |
REQ-066-079 |
- | Output sanitization removes or masks the following patterns: | none |
REQ-066-080 |
- | The tool SHALL support the timeout levels below: a Default of 60 seconds for standard commands, an Extended 120 seconds for script execution, and a Custom value of 1-600 seconds when user-specified. | none |
REQ-066-081 |
- | Hard timeout kills PowerShell process tree | none |
REQ-066-082 |
- | Soft timeout sends Ctrl+C signal first | none |
REQ-066-083 |
- | Grace period of 5 seconds after soft timeout | none |
REQ-066-084 |
- | Force kill if process doesn't terminate | none |
REQ-066-085 |
- | Working Directory Restriction: Optional enforcement of working directory to prevent path traversal | none |
REQ-066-086 |
- | Output Size Limitation: Maximum 1MB output by default, configurable up to 10MB | none |
REQ-066-087 |
- | Module Isolation: Prevent loading of untrusted PowerShell modules | none |
REQ-066-088 |
- | Script Signing: Optional enforcement of signed scripts only | none |
REQ-066-089 |
- | Audit Logging: All executions logged with timestamp, user, command, and result | none |
REQ-066-123 |
- | Unit Tests | 85% | 95% | | none |
REQ-066-124 |
- | Integration Tests | 100% | 100% | | none |
REQ-066-125 |
- | Security Tests | 100% | 100% | | none |
REQ-066-126 |
- | TR-001 | Single command execution returns valid output | Integration | | none |
REQ-066-127 |
- | TR-002 | Script file execution with parameter binding | Integration | | none |
REQ-066-128 |
- | TR-003 | Command allowlist correctly permits/blocks | Unit | | none |
REQ-066-129 |
- | TR-004 | Execution timeout triggers on expiration | Unit | | none |
REQ-066-130 |
- | TR-005 | Output sanitization removes sensitive data | Unit | | none |
REQ-066-131 |
- | TR-006 | PowerShell binary detection works cross-platform | Integration | | none |
REQ-066-132 |
- | TR-007 | Working directory validation enforced | Integration | | none |
REQ-066-133 |
- | TR-008 | Execution cancellation terminates process | Integration | | none |
REQ-066-134 |
- | TR-101 | Blocked cmdlets are rejected | Security | | none |
REQ-066-135 |
- | TR-102 | Invoke-Expression commands blocked | Security | | none |
REQ-066-136 |
- | TR-103 | Path traversal attempts blocked | Security | | none |
REQ-066-137 |
- | TR-104 | Output sanitization for passwords | Security | | none |
REQ-066-138 |
- | TR-105 | Output sanitization for API keys | Security | | none |
REQ-066-139 |
- | TR-106 | Output sanitization for tokens | Security | | none |
REQ-066-140 |
- | TR-107 | Output sanitization for private keys | Security | | none |
REQ-066-141 |
- | TR-201 | Command execution latency | < 100ms | | none |
REQ-066-142 |
- | TR-202 | Script startup time | < 200ms | | none |
REQ-066-143 |
- | TR-203 | Output sanitization time | < 50ms | | none |
REQ-066-144 |
- | TR-204 | Concurrent execution support | 10+ processes | | none |
REQ-066-145 |
- | Python Version | 3.11+ | | none |
REQ-066-146 |
- | PowerShell Version | 5.1+ / 7.0+ | | none |
REQ-066-147 |
- | Operating System | Windows 10/Server 2019+ | | none |
REQ-066-148 |
- | Test Isolation | Each test runs independently | | none |
REQ-066-149 |
- | All unit tests must pass before merge | none |
REQ-066-150 |
- | All integration tests must pass before release | none |
REQ-066-151 |
- | Security tests must pass 100% before deployment | none |
REQ-066-152 |
- | Performance tests must meet thresholds | none |
REQ-066-153 |
- | Command Validation | 100% of allowlist/blocklist patterns | | none |
REQ-066-154 |
- | Output Sanitization | 100% of sensitive patterns | | none |
REQ-066-155 |
- | Timeout Handling | All timeout scenarios | | none |
REQ-066-156 |
- | Error Handling | All error conditions (E001-E015) | | none |
REQ-066-157 |
- | Path Detection | Windows/PowerShell Core detection | | none |
REQ-066-158 |
- | Execute Get-Service | Returns service list with status | | none |
REQ-066-159 |
- | Execute blocked Remove-Item | Returns E004 error | | none |
REQ-066-160 |
- | Execute script with parameters | Parameters bound correctly | | none |
REQ-066-161 |
- | Command timeout | Returns E002 error | | none |
REQ-066-162 |
- | Output exceeds size limit | Returns E010 error | | none |
REQ-066-163 |
- | Invalid script path | Returns E006 error | | none |
REQ-066-164 |
- | Sanitize password in output | Password replaced with [REDACTED] | | none |
REQ-066-165 |
- | Command with Invoke-Expression | Blocked, E005 | | none |
REQ-066-166 |
- | Command with path traversal | Blocked, V004 | | none |
REQ-066-167 |
- | Output with API key | Sanitized | | none |
REQ-066-168 |
- | Output with private key | Sanitized | | none |
REQ-066-169 |
- | Script execution timeout | Graceful termination | | none |
REQ-066-090 |
- | The PowerShell tool integrates with the orchestrata-ultimate tool ecosystem through: | none |
REQ-066-091 |
- | The tool SHALL integrate with the security framework as listed below — PAM++ enforcement of the tool:powershell permission requirement, audit logging of all executions to the central audit system, and support for dynamic allowlist updates from security policy. |
none |
REQ-066-092 |
- | The tool SHALL integrate with the API server as listed below — HTTP endpoints exposing a REST API for remote PowerShell execution, compatibility with the orchestrata authentication framework, and integration with tool server rate limiting. | none |
REQ-066-093 |
- | The tool SHALL integrate with monitoring as listed below — export of execution metrics (duration, count, success rate), OpenTelemetry spans for distributed tracing, and a /health endpoint for load balancer integration. |
none |
REQ-066-170 |
- | Single command execution | 100% success rate on allowed commands | Integration tests | | none |
REQ-066-171 |
- | Script execution | Parameters bound correctly | Integration tests | | none |
REQ-066-172 |
- | Security enforcement | 100% of blocked commands rejected | Security tests | | none |
REQ-066-173 |
- | Output sanitization | 100% sensitive data redacted | Unit tests | | none |
REQ-066-174 |
- | Command latency | < 100ms for simple commands | Load testing | | none |
REQ-066-175 |
- | Startup time | < 200ms for PowerShell init | Profiling | | none |
REQ-066-176 |
- | Throughput | 10 concurrent executions | Stress testing | | none |
REQ-066-177 |
- | Command isolation | No unauthorized command execution | Penetration testing | | none |
REQ-066-178 |
- | Data protection | Zero sensitive data in logs | Audit review | | none |
REQ-066-179 |
- | Access control | Only authorized users can execute | Auth tests | | none |
REQ-066-180 |
no | All unit tests pass (>85% coverage) | none |
REQ-066-181 |
no | All integration tests pass (100%) | none |
REQ-066-182 |
no | All security tests pass (100%) | none |
REQ-066-183 |
no | Documentation complete and reviewed | none |
REQ-066-184 |
no | Performance benchmarks met | none |
REQ-066-185 |
no | Security audit passed | none |
REQ-066-186 |
no | Compliance check passed | none |
REQ-066-187 |
no | Deployment scripts tested | none |
REQ-066-188 |
no | Monitoring dashboards configured | none |
REQ-066-189 |
no | Runbooks documented | none |
REQ-066-190 |
no | Incident response procedures defined | none |
REQ-066-191 |
no | Backup/restore procedures tested | none |
REQ-066-192 |
- | The tool SHALL declare the dependencies shown below: python >=3.11, aiofiles >=23.0.0 and pydantic >=2.0.0, with the listed dev extras. |
none |
REQ-066-094 |
- | PowerShell binary detection SHALL proceed in the order shown below — C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe (Windows), pwsh in PATH (PowerShell Core), /usr/bin/pwsh (Linux/macOS), then powershell in PATH (Windows fallback) — and SHALL raise E001 if none is found. |
none |
REQ-066-095 |
- | Command execution SHALL proceed in the order shown below: validate the command against the allowlist/blocklist, create a subprocess with timeout, capture stdout and stderr separately, convert output to UTF-8 with error handling, sanitize output for sensitive data, check output size against the limit, and return a structured ToolResult. |
none |
REQ-066-096 |
- | Script execution SHALL proceed in the order shown below: validate that the script path exists and ends in .ps1, build the parameter string from the parameters dict, execute with powershell.exe -NoProfile -ExecutionPolicy Bypass -File <script> <params>, and apply the same validation and sanitization as command execution. |
none |
REQ-066-097 |
- | Execution SHALL require tool:powershell, the allowlist SHALL be enforced, and output SHALL be sanitized. |
none |
REQ-066-193 |
- | Component logging SHALL log all major operations with appropriate log levels, include correlation IDs for request tracing, log performance metrics for critical operations, and log errors with full context for debugging. | none |
REQ-066-194 |
- | Performance metrics SHALL comprise operation duration histograms, request/error rate counters, resource utilization gauges, and business metrics relevant to the domain. | none |
REQ-066-195 |
- | Distributed tracing SHALL provide trace propagation across component boundaries, span attributes for domain-specific context, and trace sampling based on operational needs. | none |
REQ-066-196 |
- | Critical alerts SHALL cover error rate spikes, performance degradation, resource exhaustion, and business metric anomalies. | none |
REQ-066-197 |
- | The operational dashboard SHALL present real-time system health, performance trends, error analysis, and resource monitoring. | none |
Code that traces this spec
No src/ symbol cites a requirement of this spec.
Other tracked files
specs/066-powershell-tool/compliance-audit.md
Full spec text
Verbatim from specs/066-powershell-tool/spec.md; headings are pushed down two levels.
SPEC-066: PowerShellTool - Windows PowerShell Execution
ARCHIVED 2026-07-12 (session 227, tool-wave ruling — plans/tool-wave-plan.md): this spec targets Windows hosts; the deployment fleet is Linux-only (CachyOS host + Incus containers). No PowerShell runtime exists or is planned in this environment. Shell execution is covered by the registered
run_shellvolk tool and SPEC-063 REPLTool (bash sessions). Revisit only if a Windows target enters the fleet.
Metadata
- Spec ID: 066-powershell-tool
- Title: PowerShellTool - Windows PowerShell Execution with Security Sandboxing
- Author: Mohamed
- Status: Archived (2026-07-12 — Windows-only, no target host; was: Complete)
- Created: 2026-04-08
- Last Updated: 2026-04-09
- Priority: P1
- Version: 1.0.0
Overview
2.1 Purpose
The PowerShellTool provides secure, sandboxed execution of PowerShell commands and scripts on Windows systems with comprehensive output filtering, command allowlisting, and execution timeouts.
2.2 Scope
This tool enables AI agents and automation workflows to execute PowerShell commands on Windows hosts with the following capabilities:
- Single command execution
- Script file execution with parameter binding
- Output sanitization and filtering
- Security sandboxing via command allowlist
- Execution timeout enforcement
- Cross-platform PowerShell binary detection
2.3 Target Systems
- Windows Server 2019+
- Windows 10/11
- PowerShell 5.1+
- PowerShell Core 7.x
User Scenarios
US-001: Windows Service Management
As a DevOps engineer I want to execute PowerShell commands to check and manage Windows services So that I can monitor service status across multiple servers and perform recovery actions
Acceptance Criteria:
- Tool executes Get-Service commands to retrieve service states
- Tool can use Restart-Service for recovery actions
- Output is returned in structured JSON format
- Command is validated against allowlist before execution
US-002: Active Directory User Query
As an IT administrator I want to query Active Directory for user account information So that I can identify stale accounts for cleanup purposes
Acceptance Criteria:
- Tool executes AD PowerShell cmdlets with proper filtering
- Results include LastLogonDate and DisplayName
- Output is filtered for relevant accounts
- Sensitive data is sanitized from results
US-003: Azure Resource Inventory
As a cloud administrator I want to generate an inventory of Azure VMs in a subscription So that I can track VM status, size, and resource groups
Acceptance Criteria:
- Tool executes Azure PowerShell commands
- Results include Name, ResourceGroupName, PowerState, VMSize
- Output is returned in structured table format
- Authentication is handled via Azure PowerShell modules
US-004: File System Operations with Security Restrictions
As a file operations team member I want to list files in a specific directory with time-based filtering So that I can identify old files while remaining restricted from dangerous commands
Acceptance Criteria:
- Command is validated against allowlist before execution
- Only safe filesystem operations are permitted
- Output includes file metadata (name, path, last write time)
- Dangerous commands like Remove-Item are blocked
Terminology
| Term | Definition |
|---|---|
| PowerShell | Microsoft's task automation and configuration management framework |
| Cmdlet | Lightweight command in the PowerShell environment |
| Allowlist | Security mechanism that only permits explicitly approved commands |
| Blocklist | Security mechanism that explicitly prohibits certain commands |
| Sandboxing | Security practice of isolating execution to prevent harmful operations |
| PSObject | PowerShell custom object that represents structured data |
| Execution Policy | PowerShell security setting that controls script execution |
| PowerShell Core | Cross-platform version of PowerShell built on .NET Core |
Functional Requirements
FR-001: Single Command Execution
REQ-066-001: The tool MUST execute single PowerShell commands and capture output within the specified timeout period.
Success Criteria:
- REQ-066-002: Command is executed using detected PowerShell binary
- REQ-066-003: Stdout and stderr are captured separately
- REQ-066-004: Exit code is returned in result
- REQ-066-005: Execution time is measured in milliseconds
FR-002: Script File Execution
REQ-066-006: The tool MUST execute PowerShell script files (.ps1) with parameter binding.
Success Criteria:
- REQ-066-007: Script path is validated to exist and end in .ps1
- REQ-066-008: Parameters are bound using -File parameter syntax
- REQ-066-009: Execution follows same security rules as single commands
- REQ-066-010: Errors during parameter binding return descriptive messages
FR-003: Command Allowlist Enforcement
REQ-066-011: The tool MUST enforce a command allowlist for security sandboxing.
Success Criteria:
- REQ-066-012: Commands are validated before execution
- REQ-066-013: Default patterns include Get-, Test-, Select-, Where-, Sort-*
- REQ-066-014: Custom allowlists can be specified per execution
- REQ-066-015: Blocked commands return ERR-003 error
FR-004: Execution Timeout
REQ-066-016: The tool MUST implement configurable execution timeout.
Success Criteria:
- REQ-066-017: Default timeout is 60 seconds
- REQ-066-018: Timeout range is 1-600 seconds
- REQ-066-019: Process tree is killed on timeout
- REQ-066-020: Timeout error (ERR-002) is returned on expiration
FR-005: Output Sanitization
REQ-066-021: The tool MUST sanitize command output to remove sensitive data.
Success Criteria:
- REQ-066-022: Passwords, tokens, keys are replaced with [REDACTED]
- REQ-066-023: Connection strings are sanitized
- REQ-066-024: Private keys are masked
- REQ-066-025: Custom patterns can be configured
FR-006: PowerShell Binary Detection
REQ-066-026: The tool MUST detect PowerShell binary across platforms.
Success Criteria:
- REQ-066-027: Windows: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- REQ-066-028: Cross-platform: pwsh in PATH
- REQ-066-029: Linux/macOS: /usr/bin/pwsh
- REQ-066-030: Returns ERR-001 if not found
FR-007: Structured Output
REQ-066-031: The tool MUST parse and return structured output (JSON/text).
Success Criteria:
- REQ-066-032: PowerShell objects are serialized to JSON
- REQ-066-033: Text output is preserved as-is
- REQ-066-034: output_json field contains parsed objects when applicable
- REQ-066-035: Null when output cannot be parsed as JSON
FR-008: Working Directory Support
REQ-066-036: The tool MUST support working directory specification.
Success Criteria:
- REQ-066-037: Optional working_directory parameter
- REQ-066-038: Validates directory exists before execution
- REQ-066-039: ERR-009 returned if directory invalid
FR-009: Execution Cancellation
REQ-066-040: The tool MUST implement execution cancellation.
Success Criteria:
- REQ-066-041: cancel() method accepts execution_id
- REQ-066-042: SIGINT signal sent first (soft cancel)
- REQ-066-043: Force kill after 5 second grace period
- REQ-066-044: ERR-012 returned if cancelled
FR-010: Audit Logging
REQ-066-045: The tool MUST log all executions for audit trail.
Success Criteria:
- REQ-066-046: Timestamp recorded for each execution
- REQ-066-047: Command, user, result, and duration logged
- REQ-066-048: Logs include success/failure status
- REQ-066-049: Audit trail is queryable
Non-Functional Requirements
9.1 Performance Requirements
| Metric | Target | Threshold |
|---|---|---|
| REQ-066-101: Command execution latency | < 100ms | < 500ms |
| REQ-066-102: Script startup time | < 200ms | < 1000ms |
| REQ-066-103: Output sanitization | < 50ms | < 200ms |
| REQ-066-104: Memory usage | < 100MB | < 200MB |
| REQ-066-105: Concurrent executions | 10 | 20 |
9.2 Reliability Requirements
| Requirement | Specification |
|---|---|
| REQ-066-106: Uptime | 99.9% availability |
| REQ-066-107: Error recovery | Automatic retry on transient failures |
| REQ-066-108: Graceful degradation | Fallback to default allowlist if custom fails |
| REQ-066-109: Timeout handling | Process tree termination on timeout |
9.3 Security Requirements
| Requirement | Specification |
|---|---|
| REQ-066-110: Input validation | All inputs validated before execution |
| REQ-066-111: Sandboxing | Command allowlist enforced by default |
| REQ-066-112: Output filtering | Sensitive data patterns redacted |
| REQ-066-113: Audit trail | All executions logged with full context |
| REQ-066-114: No code injection | Parameterized execution prevents injection |
9.4 Compatibility Requirements
| Platform | Minimum Version |
|---|---|
| REQ-066-115: Windows | Windows 10/Server 2019 |
| REQ-066-116: PowerShell | 5.1 |
| REQ-066-117: PowerShell Core | 7.0+ |
| REQ-066-118: Python | 3.11+ |
9.5 Observability Requirements
| Capability | Specification |
|---|---|
| REQ-066-119: Logging | Structured JSON logs with context |
| REQ-066-120: Metrics | Execution count, duration, success rate |
| REQ-066-121: Tracing | OpenTelemetry compatible spans |
| REQ-066-122: Health checks | /health endpoint for liveness |
Data Models
5.1 Tool Request Schema
REQ-066-050: A tool request SHALL conform to the PowerShellToolRequest JSON Schema below: command of length 1-10000, script_path matching \.ps1$, parameters as an object of string/number/boolean/array/object values, timeout an integer 1-600 defaulting to 60, an optional working_directory, an optional allowlist array of strings, and exactly one of command or script_path required.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PowerShellToolRequest",
"type": "object",
"properties": {
"command": {
"type": "string",
"description": "PowerShell command or script to execute",
"minLength": 1,
"maxLength": 10000
},
"script_path": {
"type": "string",
"description": "Path to PowerShell script file (.ps1)",
"pattern": "\\.ps1$"
},
"parameters": {
"type": "object",
"description": "Parameters to bind to script",
"additionalProperties": {
"type": ["string", "number", "boolean", "array", "object"]
}
},
"timeout": {
"type": "integer",
"description": "Execution timeout in seconds",
"minimum": 1,
"maximum": 600,
"default": 60
},
"working_directory": {
"type": "string",
"description": "Working directory for execution"
},
"allowlist": {
"type": "array",
"description": "Custom command allowlist for this execution",
"items": {
"type": "string"
}
}
},
"oneOf": [
{ "required": ["command"] },
{ "required": ["script_path"] }
]
}
5.2 Tool Result Schema
REQ-066-051: A tool result SHALL conform to the PowerShellToolResult JSON Schema below, carrying success, output (sanitized), output_json (parsed JSON output when applicable), error, exit_code, execution_time_ms and timestamp, with success, exit_code and execution_time_ms required.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PowerShellToolResult",
"type": "object",
"properties": {
"success": {
"type": "boolean",
"description": "Whether execution completed successfully"
},
"output": {
"type": "string",
"description": "Command output (sanitized)"
},
"output_json": {
"type": ["object", "array", "null"],
"description": "Parsed JSON output if applicable"
},
"error": {
"type": "string",
"description": "Error message if execution failed"
},
"exit_code": {
"type": "integer",
"description": "Process exit code"
},
"execution_time_ms": {
"type": "integer",
"description": "Execution duration in milliseconds"
},
"timestamp": {
"type": "string",
"format": "date-time",
"description": "Execution timestamp"
}
},
"required": ["success", "exit_code", "execution_time_ms"]
}
5.3 Command Validation Schema
REQ-066-052: A command validation result SHALL conform to the CommandValidationResult JSON Schema below, carrying allowed (required), blocked_reason and matched_pattern.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "CommandValidationResult",
"type": "object",
"properties": {
"allowed": {
"type": "boolean",
"description": "Whether command is allowed by allowlist"
},
"blocked_reason": {
"type": "string",
"description": "Reason for blocking if not allowed"
},
"matched_pattern": {
"type": "string",
"description": "The allowlist pattern that matched"
}
},
"required": ["allowed"]
}
5.4 Security Configuration Schema
REQ-066-053: Security configuration SHALL conform to the PowerShellSecurityConfig JSON Schema below, including command_allowlist, command_blocklist, blocked_patterns, execution_timeout_seconds (1-600, default 60), max_output_size_bytes (1024-10485760, default 1048576), sensitive_data_patterns, require_working_directory (default false), and sandbox_mode (one of none, allowlist, blocklist, strict; default allowlist).
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PowerShellSecurityConfig",
"type": "object",
"properties": {
"command_allowlist": {
"type": "array",
"description": "Allowed cmdlet patterns",
"items": {
"type": "string"
},
"default": ["Get-*", "Test-*", "Select-*", "Where-*", "Sort-*"]
},
"command_blocklist": {
"type": "array",
"description": "Explicitly blocked cmdlet patterns",
"items": {
"type": "string"
},
"default": ["Remove-Item", "Stop-Process", "Stop-Computer", "Restart-Computer", "Format-Volume"]
},
"blocked_patterns": {
"type": "array",
"description": "Regex patterns to block in commands",
"items": {
"type": "string"
},
"default": ["-exec\\s", "Invoke-Expression", "iex\\s", "Invoke-Command.*-ScriptBlock"]
},
"execution_timeout_seconds": {
"type": "integer",
"minimum": 1,
"maximum": 600,
"default": 60
},
"max_output_size_bytes": {
"type": "integer",
"minimum": 1024,
"maximum": 10485760,
"default": 1048576
},
"sensitive_data_patterns": {
"type": "array",
"description": "Patterns to redact from output",
"items": {
"type": "string"
},
"default": ["password", "secret", "token", "key", "api_?key", "connectionstring"]
},
"require_working_directory": {
"type": "boolean",
"description": "Require working directory to be specified",
"default": false
},
"sandbox_mode": {
"type": "string",
"enum": ["none", "allowlist", "blocklist", "strict"],
"default": "allowlist"
}
}
}
Error Conditions
ERR-001: PowerShell Binary Not Found
| Condition | Handling |
|---|---|
| REQ-066-054: PowerShell executable not found on system | Return error with message, log attempt |
ERR-002: Command Timeout
| Condition | Handling |
|---|---|
| REQ-066-055: Command execution exceeded timeout | Kill process tree, return timeout error with duration |
ERR-003: Command Not in Allowlist
| Condition | Handling |
|---|---|
| REQ-066-056: Command '{cmdlet}' is not in allowed command list | Block execution, return ERR-003 |
ERR-004: Command Matches Blocklist
| Condition | Handling |
|---|---|
| REQ-066-057: Command '{cmdlet}' is explicitly blocked for security | Block execution, return ERR-004 |
ERR-005: Command Matches Blocked Pattern
| Condition | Handling |
|---|---|
| REQ-066-058: Command contains blocked pattern: {pattern} | Block execution, return ERR-005 |
ERR-006: Script File Not Found
| Condition | Handling |
|---|---|
| REQ-066-059: Script file not found: {path} | Return error with file path |
ERR-007: Script File Invalid
| Condition | Handling |
|---|---|
| REQ-066-060: Script file is not a valid .ps1 file | Validate extension, return ERR-007 |
ERR-008: Parameter Binding Failure
| Condition | Handling |
|---|---|
| REQ-066-061: Failed to bind parameters to script | Return detailed binding error |
ERR-009: Working Directory Invalid
| Condition | Handling |
|---|---|
| REQ-066-062: Working directory does not exist | Validate before execution, return ERR-009 |
ERR-010: Output Size Exceeded
| Condition | Handling |
|---|---|
| REQ-066-063: Output size {size} exceeds maximum {max} | Truncate output, return ERR-010 |
ERR-011: Execution Permission Denied
| Condition | Handling |
|---|---|
| REQ-066-064: Permission denied to execute command | Check permissions, return ERR-011 |
ERR-012: Execution Cancelled
| Condition | Handling |
|---|---|
| REQ-066-065: Command execution was cancelled | Return ERR-012 with cancelled status |
ERR-013: PowerShell Module Not Found
| Condition | Handling |
|---|---|
| REQ-066-066: Required PowerShell module '{module}' is not installed | Check module availability, return ERR-013 |
ERR-014: Invalid Command Syntax
| Condition | Handling |
|---|---|
| REQ-066-067: PowerShell command syntax error | Return ERR-014 with syntax error details |
ERR-015: Encoding Error
| Condition | Handling |
|---|---|
| REQ-066-068: Failed to decode PowerShell output | Try multiple encodings, return ERR-015 |
ERR-016: Command Exceeds Maximum Length
| Condition | Handling |
|---|---|
| REQ-066-069: Command exceeds maximum character limit | Validate length, return ERR-016 |
ERR-017: Invalid Timeout Value
| Condition | Handling |
|---|---|
| REQ-066-070: Timeout value is negative, zero, or exceeds maximum | Validate range 1-600, return ERR-017 |
ERR-018: Path Traversal Detected
| Condition | Handling |
|---|---|
| REQ-066-071: Working directory path traversal attempt detected | Block execution, return ERR-018 |
ERR-019: No Command Provided
| ERR-ID | Condition | Handling |
|---|---|---|
| ERR-019 | REQ-066-072: No command or script path provided | Validate input, return ERR-019 |
API Contracts
8.1 Tool Interface
REQ-066-073: The tool SHALL expose the PowerShellTool interface shown below — the name, description and version attributes plus execute, execute_script, validate_command, sanitize_output, get_powershell_path and cancel — implementing BaseTool.
class PowerShellTool(BaseTool):
"""Execute PowerShell commands on Windows with security sandboxing."""
name: str = "PowerShellTool"
description: str = "Execute PowerShell commands with security sandboxing"
version: str = "1.0.0"
def __init__(
self,
config: PowerShellSecurityConfig = None,
logger: logging.Logger = None
) -> None:
"""Initialize PowerShell tool with security configuration."""
async def execute(
self,
command: str,
timeout: int = 60,
working_directory: str = None,
allowlist: List[str] = None
) -> ToolResult:
"""Execute a PowerShell command."""
async def execute_script(
self,
script_path: str,
parameters: Dict[str, Any] = None,
timeout: int = 120,
working_directory: str = None
) -> ToolResult:
"""Execute a PowerShell script file with parameters."""
def validate_command(self, command: str) -> CommandValidationResult:
"""Validate command against security rules."""
def sanitize_output(self, output: str) -> str:
"""Remove sensitive data from output."""
def get_powershell_path(self) -> str:
"""Detect and return PowerShell binary path."""
async def cancel(self, execution_id: str) -> bool:
"""Cancel a running execution."""
8.2 Tool Result Interface
REQ-066-074: The tool SHALL return the ToolResult structure shown below, with the fields success, output, output_json, error, exit_code, execution_time_ms and timestamp.
@dataclass
class ToolResult:
success: bool
output: str
output_json: Optional[Union[Dict, List]]
error: Optional[str]
exit_code: int
execution_time_ms: int
timestamp: datetime
8.3 REST API Endpoints (Tool Server)
REQ-066-075: The tool server SHALL expose the REST endpoints shown below: POST /api/v1/tools/powershell/execute, POST /api/v1/tools/powershell/execute-script, POST /api/v1/tools/powershell/validate and GET /api/v1/tools/powershell/health.
POST /api/v1/tools/powershell/execute
Content-Type: application/json
Request:
{
"command": "Get-Service -Name wuauserv",
"timeout": 30,
"working_directory": "C:\\Scripts"
}
Response:
{
"success": true,
"output": "Name Status StartType\n---- ------ ---------\nwuauserv Running Automatic",
"output_json": null,
"error": null,
"exit_code": 0,
"execution_time_ms": 245,
"timestamp": "2026-04-08T10:30:00Z"
}
POST /api/v1/tools/powershell/execute-script
Content-Type: application/json
Request:
{
"script_path": "C:\\Scripts\\deploy.ps1",
"parameters": {
"Environment": "Production",
"Verbose": true
},
"timeout": 300
}
Response:
{
"success": true,
"output": "Deployment started...",
"output_json": { "status": "started", "deployment_id": "dep-12345" },
"error": null,
"exit_code": 0,
"execution_time_ms": 15230,
"timestamp": "2026-04-08T10:30:00Z"
}
POST /api/v1/tools/powershell/validate
Content-Type: application/json
Request:
{
"command": "Remove-Item -Path C:\\* -Recurse"
}
Response:
{
"allowed": false,
"blocked_reason": "Command matches blocklist pattern",
"matched_pattern": "Remove-Item"
}
GET /api/v1/tools/powershell/health
Response:
{
"status": "healthy",
"powershell_path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"version": "5.1.22621.1"
}
Examples
11.1 Single Command Execution Example
Request:
{
"command": "Get-Service -Name wuauserv",
"timeout": 30
}
Response:
{
"success": true,
"output": "Name Status StartType\n---- ------ ---------\nwuauserv Running Automatic",
"output_json": null,
"error": null,
"exit_code": 0,
"execution_time_ms": 245,
"timestamp": "2026-04-08T10:30:00Z"
}
11.2 Script Execution Example
Request:
{
"script_path": "C:\\Scripts\\deploy.ps1",
"parameters": {
"Environment": "Production",
"Verbose": true
},
"timeout": 300
}
Response:
{
"success": true,
"output": "Deployment started for Production environment...",
"output_json": {
"status": "started",
"deployment_id": "dep-12345",
"environment": "Production"
},
"error": null,
"exit_code": 0,
"execution_time_ms": 15230,
"timestamp": "2026-04-08T10:30:00Z"
}
11.3 Command Validation Example
Request:
{
"command": "Remove-Item -Path C:\\* -Recurse -Force"
}
Response:
{
"allowed": false,
"blocked_reason": "Command matches blocklist pattern",
"matched_pattern": "Remove-Item"
}
11.4 Error Response Example
Request:
{
"command": "Start-Sleep -Seconds 120",
"timeout": 10
}
Response:
{
"success": false,
"output": "",
"output_json": null,
"error": "Command execution exceeded timeout of 10s",
"exit_code": -1,
"execution_time_ms": 10050,
"timestamp": "2026-04-08T10:30:00Z"
}
11.5 Output Sanitization Example
Input:
Server=localhost;Password=«redacted»
api_key=abc123xyz
Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
Sanitized Output:
Server=localhost;Password=«redacted»
api_key=[REDACTED]
Bearer [REDACTED]
Security Requirements
12.1 Command Allowlist
REQ-066-076: The tool implements a command allowlist system with the following default patterns:
Allowed Cmdlet Patterns (Default):
Get-*- Read operations (Get-Process, Get-Service, Get-Content, etc.)Test-*- Testing operations (Test-Path, Test-Connection, etc.)Select-*- Selection and projectionWhere-*- Filtering operationsSort-*- Sorting operationsMeasure-*- Measurement operationsCompare-*- Comparison operationsConvertTo-*- Conversion operationsFormat-*- Formatting operationsOut-*- Output operations
REQ-066-077: The tool SHALL explicitly block the cmdlets listed below.
Explicitly Blocked Cmdlets:
Remove-Item- File/directory deletionRemove-ItemProperty- Property deletionStop-Process- Process terminationStop-Computer- System shutdownRestart-Computer- System restartFormat-Volume- Disk formattingClear-Disk- Disk clearingSet-ExecutionPolicy- Execution policy changes (in remote context)Invoke-Expression- Dynamic code executioniex- Alias for Invoke-Expression
12.2 Command Block Patterns
REQ-066-078: The following regex patterns trigger automatic blocking:
BLOCKED_PATTERNS = [
r"-exec\s", # Shell execution
r"Invoke-Expression", # Dynamic code execution
r"iex\s", # Short form Invoke-Expression
r"Invoke-Command.*-ScriptBlock", # Remote script block
r"Start-Process.*-Verb\s+RunAs", # Elevated execution
r"DownloadString", # Web download to memory
r"DownloadFile", # File download
r"WebClient\.Download", # WebClient download
r"\[System\.Reflection\.Assembly\]", # Dynamic assembly loading
r"Add-Type.*-TypeDefinition", # Dynamic type creation
]
12.3 Output Sanitization
REQ-066-079: Output sanitization removes or masks the following patterns:
SENSITIVE_PATTERNS = [
(r"(password|passwd|pwd)[=:]\s*\S+", "[REDACTED]"),
(r"(secret|api_key|apikey|api-key)[=:]\s*\S+", "[REDACTED]"),
(r"(token|auth_token|access_token)[=:]\s*\S+", "[REDACTED]"),
(r"(connectionstring|conn_str)[=:]\s*\S+", "[REDACTED]"),
(r"Bearer\s+\S+", "Bearer [REDACTED]"),
(r"Basic\s+\S+", "Basic [REDACTED]"),
(r"-----BEGIN\s+\w+\s+PRIVATE\s+KEY-----.*-----END\s+\w+\s+PRIVATE\s+KEY-----", "[RSA PRIVATE KEY REDACTED]"),
(r"x-api-key[:\s]+\S+", "x-api-key: «redacted»
]
12.4 Execution Timeout
REQ-066-080: The tool SHALL support the timeout levels below: a Default of 60 seconds for standard commands, an Extended 120 seconds for script execution, and a Custom value of 1-600 seconds when user-specified.
| Timeout Level | Duration | Use Case |
|---|---|---|
| Default | 60 seconds | Standard commands |
| Extended | 120 seconds | Script execution |
| Custom | 1-600 seconds | User-specified |
Timeout Enforcement:
- REQ-066-081: Hard timeout kills PowerShell process tree
- REQ-066-082: Soft timeout sends Ctrl+C signal first
- REQ-066-083: Grace period of 5 seconds after soft timeout
- REQ-066-084: Force kill if process doesn't terminate
12.5 Additional Security Measures
- REQ-066-085: Working Directory Restriction: Optional enforcement of working directory to prevent path traversal
- REQ-066-086: Output Size Limitation: Maximum 1MB output by default, configurable up to 10MB
- REQ-066-087: Module Isolation: Prevent loading of untrusted PowerShell modules
- REQ-066-088: Script Signing: Optional enforcement of signed scripts only
- REQ-066-089: Audit Logging: All executions logged with timestamp, user, command, and result
Testing Requirements
Test Coverage Requirements
| Category | Minimum Coverage | Target Coverage |
|---|---|---|
| REQ-066-123: Unit Tests | 85% | 95% |
| REQ-066-124: Integration Tests | 100% | 100% |
| REQ-066-125: Security Tests | 100% | 100% |
Functional Testing Requirements
| Requirement ID | Description | Test Type |
|---|---|---|
| REQ-066-126: TR-001 | Single command execution returns valid output | Integration |
| REQ-066-127: TR-002 | Script file execution with parameter binding | Integration |
| REQ-066-128: TR-003 | Command allowlist correctly permits/blocks | Unit |
| REQ-066-129: TR-004 | Execution timeout triggers on expiration | Unit |
| REQ-066-130: TR-005 | Output sanitization removes sensitive data | Unit |
| REQ-066-131: TR-006 | PowerShell binary detection works cross-platform | Integration |
| REQ-066-132: TR-007 | Working directory validation enforced | Integration |
| REQ-066-133: TR-008 | Execution cancellation terminates process | Integration |
Security Testing Requirements
| Requirement ID | Description | Test Type |
|---|---|---|
| REQ-066-134: TR-101 | Blocked cmdlets are rejected | Security |
| REQ-066-135: TR-102 | Invoke-Expression commands blocked | Security |
| REQ-066-136: TR-103 | Path traversal attempts blocked | Security |
| REQ-066-137: TR-104 | Output sanitization for passwords | Security |
| REQ-066-138: TR-105 | Output sanitization for API keys | Security |
| REQ-066-139: TR-106 | Output sanitization for tokens | Security |
| REQ-066-140: TR-107 | Output sanitization for private keys | Security |
Performance Testing Requirements
| Requirement ID | Description | Threshold |
|---|---|---|
| REQ-066-141: TR-201 | Command execution latency | < 100ms |
| REQ-066-142: TR-202 | Script startup time | < 200ms |
| REQ-066-143: TR-203 | Output sanitization time | < 50ms |
| REQ-066-144: TR-204 | Concurrent execution support | 10+ processes |
Test Environment Requirements
| Requirement | Specification |
|---|---|
| REQ-066-145: Python Version | 3.11+ |
| REQ-066-146: PowerShell Version | 5.1+ / 7.0+ |
| REQ-066-147: Operating System | Windows 10/Server 2019+ |
| REQ-066-148: Test Isolation | Each test runs independently |
Test Execution Requirements
- REQ-066-149: All unit tests must pass before merge
- REQ-066-150: All integration tests must pass before release
- REQ-066-151: Security tests must pass 100% before deployment
- REQ-066-152: Performance tests must meet thresholds
Testing Requirements
15.1 Unit Tests
| Test Category | Coverage Target |
|---|---|
| REQ-066-153: Command Validation | 100% of allowlist/blocklist patterns |
| REQ-066-154: Output Sanitization | 100% of sensitive patterns |
| REQ-066-155: Timeout Handling | All timeout scenarios |
| REQ-066-156: Error Handling | All error conditions (E001-E015) |
| REQ-066-157: Path Detection | Windows/PowerShell Core detection |
15.2 Integration Tests
| Test Scenario | Expected Result |
|---|---|
| REQ-066-158: Execute Get-Service | Returns service list with status |
| REQ-066-159: Execute blocked Remove-Item | Returns E004 error |
| REQ-066-160: Execute script with parameters | Parameters bound correctly |
| REQ-066-161: Command timeout | Returns E002 error |
| REQ-066-162: Output exceeds size limit | Returns E010 error |
| REQ-066-163: Invalid script path | Returns E006 error |
| REQ-066-164: Sanitize password in output | Password replaced with [REDACTED] |
15.3 Security Tests
| Test Scenario | Expected Result |
|---|---|
| REQ-066-165: Command with Invoke-Expression | Blocked, E005 |
| REQ-066-166: Command with path traversal | Blocked, V004 |
| REQ-066-167: Output with API key | Sanitized |
| REQ-066-168: Output with private key | Sanitized |
| REQ-066-169: Script execution timeout | Graceful termination |
15.4 Test Data
# Test commands for allowlist validation
ALLOWLIST_TEST_CASES = [
("Get-Process", True),
("Get-Service -Name wuauserv", True),
("Test-Path C:\\Windows", True),
("Select-Object Name, Value", True),
("Where-Object {$_.Status -eq 'Running'}", True),
("Remove-Item C:\\test.txt", False),
("Stop-Process -Name notepad", False),
("Invoke-Expression 'malicious'", False),
]
# Test commands for output sanitization
SANITIZATION_TEST_CASES = [
("password=secret123", "password=«redacted»
("api_key=abc123xyz", "api_key=«redacted»
("Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", "Bearer [REDACTED]"),
("ConnectionString=Server=localhost;Password=pwd", "ConnectionString=[REDACTED]"),
]
# Test timeout scenarios
TIMEOUT_TEST_CASES = [
(30, "Start-Sleep -Seconds 10", True), # Under timeout
(5, "Start-Sleep -Seconds 10", False), # Over timeout
(60, "Get-Process", True), # Default timeout
]
15.5 Test Framework
# Run unit tests
pytest tests/unit/test_powershell_tool.py -v
# Run integration tests
pytest tests/integration/test_powershell_tool.py -v
# Run security tests
pytest tests/security/test_powershell_sandbox.py -v
# Run all tests with coverage
pytest tests/ -v --cov=src.powershell_tool --cov-report=html
Integration Points
16.1 Tool Orchestration Integration
REQ-066-090: The PowerShell tool integrates with the orchestrata-ultimate tool ecosystem through:
- BaseTool Interface: Implements standard tool contract for lifecycle management
- Async Execution: Full async/await support for concurrent operations
- Structured Logging: JSON logs compatible with orchestrata logging system
- Error Propagation: Standardized error codes and messages
16.2 Security Framework Integration
REQ-066-091: The tool SHALL integrate with the security framework as listed below — PAM++ enforcement of the tool:powershell permission requirement, audit logging of all executions to the central audit system, and support for dynamic allowlist updates from security policy.
- PAM++ Integration: Enforces tool:powershell permission requirement
- Audit Logging: All executions logged to central audit system
- Allowlist Management: Supports dynamic allowlist updates from security policy
16.3 API Server Integration
REQ-066-092: The tool SHALL integrate with the API server as listed below — HTTP endpoints exposing a REST API for remote PowerShell execution, compatibility with the orchestrata authentication framework, and integration with tool server rate limiting.
- HTTP Endpoints: Exposes REST API for remote PowerShell execution
- Authentication: Compatible with orchestrata authentication framework
- Rate Limiting: Integrates with tool server rate limiting
16.4 Monitoring Integration
REQ-066-093: The tool SHALL integrate with monitoring as listed below — export of execution metrics (duration, count, success rate), OpenTelemetry spans for distributed tracing, and a /health endpoint for load balancer integration.
- Metrics: Exports execution metrics (duration, count, success rate)
- Tracing: OpenTelemetry spans for distributed tracing
- Health Checks: /health endpoint for load balancer integration
Success Criteria
17.1 Functional Completion
| Criteria | Target | Verification |
|---|---|---|
| REQ-066-170: Single command execution | 100% success rate on allowed commands | Integration tests |
| REQ-066-171: Script execution | Parameters bound correctly | Integration tests |
| REQ-066-172: Security enforcement | 100% of blocked commands rejected | Security tests |
| REQ-066-173: Output sanitization | 100% sensitive data redacted | Unit tests |
17.2 Performance Targets
| Metric | Target | Measurement |
|---|---|---|
| REQ-066-174: Command latency | < 100ms for simple commands | Load testing |
| REQ-066-175: Startup time | < 200ms for PowerShell init | Profiling |
| REQ-066-176: Throughput | 10 concurrent executions | Stress testing |
17.3 Security Objectives
| Security Goal | Acceptance Criteria | Verification |
|---|---|---|
| REQ-066-177: Command isolation | No unauthorized command execution | Penetration testing |
| REQ-066-178: Data protection | Zero sensitive data in logs | Audit review |
| REQ-066-179: Access control | Only authorized users can execute | Auth tests |
17.4 Quality Gates
- [ ] REQ-066-180: All unit tests pass (>85% coverage)
- [ ] REQ-066-181: All integration tests pass (100%)
- [ ] REQ-066-182: All security tests pass (100%)
- [ ] REQ-066-183: Documentation complete and reviewed
- [ ] REQ-066-184: Performance benchmarks met
- [ ] REQ-066-185: Security audit passed
- [ ] REQ-066-186: Compliance check passed
17.5 Operational Readiness
- [ ] REQ-066-187: Deployment scripts tested
- [ ] REQ-066-188: Monitoring dashboards configured
- [ ] REQ-066-189: Runbooks documented
- [ ] REQ-066-190: Incident response procedures defined
- [ ] REQ-066-191: Backup/restore procedures tested
Dependencies
14.1 Python Dependencies
REQ-066-192: The tool SHALL declare the dependencies shown below: python >=3.11, aiofiles >=23.0.0 and pydantic >=2.0.0, with the listed dev extras.
[project.dependencies]
python = ">=3.11"
aiofiles = ">=23.0.0"
pydantic = ">=2.0.0"
[project.optional-dependencies]
dev = [
"pytest>=7.4.0",
"pytest-asyncio>=0.21.0",
"pytest-cov>=4.1.0",
"pytest-mock>=3.12.0",
"black>=23.0.0",
"ruff>=0.1.0",
"mypy>=1.5.0",
]
14.2 System Requirements
| Requirement | Minimum Version |
|---|---|
| Python | 3.11+ |
| PowerShell (Windows) | 5.1 |
| PowerShell Core (Cross-platform) | 7.0 |
| Windows OS | Windows 10/Server 2019+ |
14.3 External Dependencies
| Dependency | Purpose | License |
|---|---|---|
| PowerShell 5.1+ | Command execution | Microsoft Windows |
| PowerShell Core 7+ | Cross-platform | MIT |
| Windows OS | Target platform | Microsoft |
Technical Design
10.1 PowerShell Detection Strategy
REQ-066-094: PowerShell binary detection SHALL proceed in the order shown below — C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe (Windows), pwsh in PATH (PowerShell Core), /usr/bin/pwsh (Linux/macOS), then powershell in PATH (Windows fallback) — and SHALL raise E001 if none is found.
- Check
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe(Windows) - Check
pwshin PATH (PowerShell Core) - Check
/usr/bin/pwsh(Linux/macOS) - Check
powershellin PATH (Windows fallback) - Raise E001 if not found
10.2 Execution Strategy
REQ-066-095: Command execution SHALL proceed in the order shown below: validate the command against the allowlist/blocklist, create a subprocess with timeout, capture stdout and stderr separately, convert output to UTF-8 with error handling, sanitize output for sensitive data, check output size against the limit, and return a structured ToolResult.
- Validate command against allowlist/blocklist
- Create subprocess with timeout
- Capture stdout and stderr separately
- Convert output to UTF-8 with error handling
- Sanitize output for sensitive data
- Check output size against limit
- Return structured ToolResult
10.3 Script Execution Strategy
REQ-066-096: Script execution SHALL proceed in the order shown below: validate that the script path exists and ends in .ps1, build the parameter string from the parameters dict, execute with powershell.exe -NoProfile -ExecutionPolicy Bypass -File <script> <params>, and apply the same validation and sanitization as command execution.
- Validate script path exists and ends in .ps1
- Build parameter string from parameters dict
- Execute with:
powershell.exe -NoProfile -ExecutionPolicy Bypass -File <script> <params> - Apply same validation and sanitization as command execution
Governance
Policy Enforcement
REQ-066-097: Execution SHALL require tool:powershell, the allowlist SHALL be enforced, and output SHALL be sanitized.
- Execution requires tool:powershell
- Allowlist enforced
- Output sanitized
Audit Logging
async def log_execution(command: str, result: dict):
await audit_log({
"event_type": "powershell_execution",
"command": command,
"success": result.success,
"duration_ms": result.duration_ms
})
Observability
Logging Requirements
REQ-066-193: Component logging SHALL log all major operations with appropriate log levels, include correlation IDs for request tracing, log performance metrics for critical operations, and log errors with full context for debugging.
- Component Logging
- Log all major operations with appropriate log levels
- Include correlation IDs for request tracing
- Log performance metrics for critical operations
- Log errors with full context for debugging
Metrics Requirements
REQ-066-194: Performance metrics SHALL comprise operation duration histograms, request/error rate counters, resource utilization gauges, and business metrics relevant to the domain.
- Performance Metrics
- Operation duration histograms
- Request/error rate counters
- Resource utilization gauges
- Business metrics relevant to domain
Tracing Requirements
REQ-066-195: Distributed tracing SHALL provide trace propagation across component boundaries, span attributes for domain-specific context, and trace sampling based on operational needs.
- Distributed Tracing
- Trace propagation across component boundaries
- Span attributes for domain-specific context
- Trace sampling based on operational needs
Alerting Requirements
REQ-066-196: Critical alerts SHALL cover error rate spikes, performance degradation, resource exhaustion, and business metric anomalies.
- Critical Alerts
- Error rate spikes
- Performance degradation
- Resource exhaustion
- Business metric anomalies
Dashboard Requirements
REQ-066-197: The operational dashboard SHALL present real-time system health, performance trends, error analysis, and resource monitoring.
- Operational Dashboard
- Real-time system health
- Performance trends
- Error analysis
- Resource monitoring
Revision History
| Version | Date | Changes |
|---|---|---|
| 1.0.0 | 2026-04-08 | Initial specification |