Home / Class/ BaseExecutionPolicy Class — langchain Architecture

BaseExecutionPolicy Class — langchain Architecture

Architecture documentation for the BaseExecutionPolicy class in _execution.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  54947cfa_44ad_df6e_ebe6_8908dfdafc92["BaseExecutionPolicy"]
  a7063f14_dbac_d9f7_9cc6_a20aa09f5461["_execution.py"]
  54947cfa_44ad_df6e_ebe6_8908dfdafc92 -->|defined in| a7063f14_dbac_d9f7_9cc6_a20aa09f5461
  bd4a56b1_d4eb_2279_d417_ef528a7aa29c["__post_init__()"]
  54947cfa_44ad_df6e_ebe6_8908dfdafc92 -->|method| bd4a56b1_d4eb_2279_d417_ef528a7aa29c
  29f56f3f_9ee5_4ab0_ea77_8c7c98917847["spawn()"]
  54947cfa_44ad_df6e_ebe6_8908dfdafc92 -->|method| 29f56f3f_9ee5_4ab0_ea77_8c7c98917847

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/_execution.py lines 57–88

class BaseExecutionPolicy(abc.ABC):
    """Configuration contract for persistent shell sessions.

    Concrete subclasses encapsulate how a shell process is launched and constrained.

    Each policy documents its security guarantees and the operating environments in
    which it is appropriate. Use `HostExecutionPolicy` for trusted, same-host execution;
    `CodexSandboxExecutionPolicy` when the Codex CLI sandbox is available and you want
    additional syscall restrictions; and `DockerExecutionPolicy` for container-level
    isolation using Docker.
    """

    command_timeout: float = 30.0
    startup_timeout: float = 30.0
    termination_timeout: float = 10.0
    max_output_lines: int = 100
    max_output_bytes: int | None = None

    def __post_init__(self) -> None:
        if self.max_output_lines <= 0:
            msg = "max_output_lines must be positive."
            raise ValueError(msg)

    @abc.abstractmethod
    def spawn(
        self,
        *,
        workspace: Path,
        env: Mapping[str, str],
        command: Sequence[str],
    ) -> subprocess.Popen[str]:
        """Launch the persistent shell process."""

Frequently Asked Questions

What is the BaseExecutionPolicy class?
BaseExecutionPolicy is a class in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/_execution.py.
Where is BaseExecutionPolicy defined?
BaseExecutionPolicy is defined in libs/langchain_v1/langchain/agents/middleware/_execution.py at line 57.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free