From 5b01f544d19610d5a7800b08e18ed49a42c0bfc2 Mon Sep 17 00:00:00 2001 From: Harry Date: Wed, 7 Jan 2026 15:48:14 +0800 Subject: [PATCH] refactor(command-node): streamline command execution and directory checks - Simplified the command execution logic by removing unnecessary shell invocations. - Enhanced working directory validation by directly using the `test` command. - Improved command parsing with `shlex.split` for better handling of raw commands. --- api/core/workflow/nodes/command/node.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/core/workflow/nodes/command/node.py b/api/core/workflow/nodes/command/node.py index 4159410aba..0fe837e009 100644 --- a/api/core/workflow/nodes/command/node.py +++ b/api/core/workflow/nodes/command/node.py @@ -87,7 +87,7 @@ class CommandNode(Node[CommandNodeData]): # Once the interface adds a `cwd` parameter, remove this shell hack # and pass working_directory directly to run_command. if working_directory: - check_cmd = ["sh", "-c", f"test -d {shlex.quote(working_directory)}"] + check_cmd = ["test", "-d", working_directory] check_future = self.sandbox.run_command(connection_handle, check_cmd) check_result = check_future.result(timeout=timeout) @@ -98,9 +98,9 @@ class CommandNode(Node[CommandNodeData]): error_type="WorkingDirectoryNotFoundError", ) - command = ["sh", "-lc", f"cd {shlex.quote(working_directory)} && {raw_command}"] + command = ["sh", "-c", f"cd {shlex.quote(working_directory)} && {raw_command}"] else: - command = ["sh", "-lc", raw_command] + command = shlex.split(raw_command) future = self.sandbox.run_command(connection_handle, command) result = future.result(timeout=timeout)