Skip to main content

Script Execution Service

Script execution service for safely running Python scripts

Overview

Provides secure subprocess-based execution of Python scripts with proper timeout handling, resource cleanup, and cross-platform compatibility.

Classes

ScriptExecutionService

Abstract interface for script execution

Inherits from: ABC

Abstract class

Methods

execute_script
execute_script(self, script_path: pathlib.Path, args: List[str]) -> specify_cli.services.script_execution_service.script_execution_service.ScriptResult

Execute Python script with given arguments

Parameters:

  • script_path (Path, required) - Path to Python script to execute
  • args (List, required)

Returns: ScriptResult

execute_script_json_mode
execute_script_json_mode(self, script_path: pathlib.Path, args: List[str]) -> specify_cli.services.script_execution_service.script_execution_service.ScriptResult

Execute script expecting JSON output

Parameters:

  • script_path (Path, required) - Path to Python script to execute
  • args (List, required)

Returns: ScriptResult

execute_script_with_timeout
execute_script_with_timeout(self, script_path: pathlib.Path, args: List[str], timeout_seconds: int) -> specify_cli.services.script_execution_service.script_execution_service.ScriptResult

Execute Python script with timeout

Parameters:

  • script_path (Path, required) - Path to Python script to execute
  • args (List, required)
  • timeout_seconds (int, required) - Maximum execution time in seconds

Returns: ScriptResult

validate_script_path
validate_script_path(self, script_path: pathlib.Path, project_path: Optional[pathlib.Path] = None) -> bool

Validate script path for security

Parameters:

  • script_path (Path, required) - Path to validate
  • project_path (Optional, optional) - Optional project root path for containment check

Returns: bool

SubprocessScriptExecutionService

Subprocess-based implementation of script execution service

Inherits from: ScriptExecutionService

Methods

execute_script
execute_script(self, script_path: pathlib.Path, args: List[str]) -> specify_cli.services.script_execution_service.script_execution_service.ScriptResult

Execute Python script with given arguments

Parameters:

  • script_path (Path, required)
  • args (List, required)

Returns: ScriptResult

execute_script_json_mode
execute_script_json_mode(self, script_path: pathlib.Path, args: List[str]) -> specify_cli.services.script_execution_service.script_execution_service.ScriptResult

Execute script expecting JSON output

Parameters:

  • script_path (Path, required)
  • args (List, required)

Returns: ScriptResult

execute_script_with_timeout
execute_script_with_timeout(self, script_path: pathlib.Path, args: List[str], timeout_seconds: int) -> specify_cli.services.script_execution_service.script_execution_service.ScriptResult

Execute Python script with timeout

Parameters:

  • script_path (Path, required)
  • args (List, required)
  • timeout_seconds (int, required)

Returns: ScriptResult

get_default_timeout
get_default_timeout(self) -> int

Get current default timeout

Returns: int

set_default_timeout
set_default_timeout(self, timeout_seconds: int) -> None

Set default timeout for script execution

Parameters:

  • timeout_seconds (int, required)
validate_script_path
validate_script_path(self, script_path: pathlib.Path, project_path: Optional[pathlib.Path] = None) -> bool

Validate script path for security

Parameters:

  • script_path (Path, required)
  • project_path (Optional, optional)

Returns: bool