Skip to content

API Reference parrot_tools.codeinterpreter.executor

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.codeinterpreter.executor

View source

Isolated code execution environment using Docker containers. Provides secure Python code execution with resource limits and timeout controls.

Class ExecutionResult

Result from code execution in isolated environment

Parameter Type Default Description
success bool
stdout str
stderr str
exit_code int
execution_time_ms int
error_message Optional[str] None

Fields:

Field Type Default Description
success bool
stdout str
stderr str
exit_code int
execution_time_ms int
error_message Optional[str] None

Class IsolatedExecutor

Manages isolated Python code execution using Docker containers.

Features:

  • Resource limits (memory, CPU)
  • Execution timeout
  • Network isolation
  • Read-only filesystem (except work directory)
  • Container reuse for better performance
Parameter Type Default Description
image str 'python:3.11-alpine' Docker image to use for execution
memory_limit str '512m' Memory limit (e.g., "512m", "1g")
cpu_quota int 50000 CPU quota in microseconds per 100ms period
timeout_seconds int 30 Maximum execution time in seconds
enable_network bool False Whether to allow network access

Method IsolatedExecutor.execute_code

Execute Python code in an isolated Docker container.

execute_code(code: str, working_dir: Optional[Path] = None, additional_files: Optional[Dict[str, str]] = None) -> ExecutionResult

Parameter Type Default Description
code str Python code to execute
working_dir Optional[Path] None Optional directory to mount as working directory
additional_files Optional[Dict[str, str]] None Optional dict of filename -> content to create

Returns: ExecutionResult — ExecutionResult with execution details

Method IsolatedExecutor.execute_tests

Execute pytest tests in isolated environment.

execute_tests(test_code: str, source_code: Optional[str] = None, requirements: Optional[list[str]] = None) -> ExecutionResult

Parameter Type Default Description
test_code str Test code using pytest
source_code Optional[str] None Optional source code being tested
requirements Optional[list[str]] None Optional list of pip packages to install

Returns: ExecutionResult — ExecutionResult with test execution details

Method IsolatedExecutor.validate_syntax

Validate Python syntax without executing.

validate_syntax(code: str) -> Tuple[bool, Optional[str]]

Parameter Type Default Description
code str Python code to validate

Returns: Tuple[bool, Optional[str]] — Tuple of (is_valid, error_message)

Method IsolatedExecutor.cleanup

Clean up Docker resources

cleanup()

Class SubprocessExecutor

Fallback executor using subprocess with basic restrictions. WARNING: Less secure than Docker-based isolation.

Parameter Type Default Description
timeout_seconds int 30

Method SubprocessExecutor.execute_code

Execute code using subprocess

execute_code(code: str, working_dir: Optional[Path] = None, additional_files: Optional[Dict[str, str]] = None) -> ExecutionResult

Parameter Type Default Description
code str
working_dir Optional[Path] None
additional_files Optional[Dict[str, str]] None

Returns: ExecutionResult

Method SubprocessExecutor.validate_syntax

Validate Python syntax

validate_syntax(code: str) -> Tuple[bool, Optional[str]]

Parameter Type Default Description
code str

Returns: Tuple[bool, Optional[str]]

Method SubprocessExecutor.cleanup

No cleanup needed for subprocess executor

cleanup()

Function create_executor

Factory function to create appropriate executor.

create_executor(use_docker: bool = True, **kwargs) -> IsolatedExecutor | SubprocessExecutor

Parameter Type Default Description
use_docker bool True Whether to use Docker (falls back to subprocess if Docker unavailable)
**kwargs {} Additional arguments for executor

Returns: IsolatedExecutor | SubprocessExecutor — Executor instance

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally