Home / Function/ execute() — langchain Function Reference

execute() — langchain Function Reference

Architecture documentation for the execute() function in shell_tool.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  da18dc22_e4fc_2b4a_2829_9217c9f5d8f5["execute()"]
  cf4eeaa4_4bcc_69d9_a0f3_664b1eecb4e8["ShellSession"]
  da18dc22_e4fc_2b4a_2829_9217c9f5d8f5 -->|defined in| cf4eeaa4_4bcc_69d9_a0f3_664b1eecb4e8
  c6011545_45bb_9aa6_7568_fa418072d163["_run_startup_commands()"]
  c6011545_45bb_9aa6_7568_fa418072d163 -->|calls| da18dc22_e4fc_2b4a_2829_9217c9f5d8f5
  a8939a21_12d2_1636_cdd0_de50dcefea64["_run_shutdown_commands()"]
  a8939a21_12d2_1636_cdd0_de50dcefea64 -->|calls| da18dc22_e4fc_2b4a_2829_9217c9f5d8f5
  8b644660_40e4_465a_3e51_e1a3166de4f9["_run_shell_tool()"]
  8b644660_40e4_465a_3e51_e1a3166de4f9 -->|calls| da18dc22_e4fc_2b4a_2829_9217c9f5d8f5
  6de1caf7_edd6_8519_6774_9efe986ad3fe["_drain_queue()"]
  da18dc22_e4fc_2b4a_2829_9217c9f5d8f5 -->|calls| 6de1caf7_edd6_8519_6774_9efe986ad3fe
  cd8522f1_4b7e_553a_b994_d38d2c6d02fb["_collect_output_after_exit()"]
  da18dc22_e4fc_2b4a_2829_9217c9f5d8f5 -->|calls| cd8522f1_4b7e_553a_b994_d38d2c6d02fb
  89d586a2_0b74_ac5c_97da_a6a18a02f59d["_collect_output()"]
  da18dc22_e4fc_2b4a_2829_9217c9f5d8f5 -->|calls| 89d586a2_0b74_ac5c_97da_a6a18a02f59d
  style da18dc22_e4fc_2b4a_2829_9217c9f5d8f5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/shell_tool.py lines 217–238

    def execute(self, command: str, *, timeout: float) -> CommandExecutionResult:
        """Execute a command in the persistent shell."""
        if not self._process or self._process.poll() is not None:
            msg = "Shell session is not running."
            raise RuntimeError(msg)

        marker = f"{_DONE_MARKER_PREFIX}{uuid.uuid4().hex}"
        deadline = time.monotonic() + timeout

        with self._lock:
            self._drain_queue()
            payload = command if command.endswith("\n") else f"{command}\n"
            try:
                self._stdin.write(payload)
                self._stdin.write(f"printf '{marker} %s\\n' $?\n")
                self._stdin.flush()
            except (BrokenPipeError, OSError):
                # The shell exited before we could write the marker command.
                # This happens when commands like 'exit 1' terminate the shell.
                return self._collect_output_after_exit(deadline)

            return self._collect_output(marker, deadline, timeout)

Domain

Subdomains

Frequently Asked Questions

What does execute() do?
execute() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py.
Where is execute() defined?
execute() is defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py at line 217.
What does execute() call?
execute() calls 3 function(s): _collect_output, _collect_output_after_exit, _drain_queue.
What calls execute()?
execute() is called by 3 function(s): _run_shell_tool, _run_shutdown_commands, _run_startup_commands.

Analyze Your Own Codebase

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

Try Supermodel Free