From eeb05de861fc1d8b4955dd145688b97d9139656f Mon Sep 17 00:00:00 2001 From: Hui Guan Date: Fri, 16 Jan 2026 22:31:58 +0000 Subject: [PATCH] fix(shell): close PTY file descriptor to prevent resource leak --- src/strands_tools/shell.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/strands_tools/shell.py b/src/strands_tools/shell.py index f45fced4..61fe00f0 100644 --- a/src/strands_tools/shell.py +++ b/src/strands_tools/shell.py @@ -185,6 +185,12 @@ def execute_with_pty(self, command: str, cwd: str, non_interactive_mode: bool) - return exit_code, "".join(output), "" finally: + # Close the PTY file descriptor + if "fd" in locals() and pid > 0: + try: + os.close(fd) + except OSError: + pass # Restore terminal settings only if they were saved and changed. if not non_interactive_mode and old_tty: termios.tcsetattr(sys.stdin, termios.TCSAFLUSH, old_tty)