fix(dify_cli): solve the permission error on e2b

This commit is contained in:
Harry
2026-01-21 01:25:21 +08:00
parent 705d4cbba9
commit 7fd9ef3d22
4 changed files with 26 additions and 3 deletions

View File

@ -49,6 +49,19 @@ class DifyCliInitializer(SandboxInitializer):
env.upload_file(DIFY_CLI_PATH, BytesIO(binary.path.read_bytes()))
# Use 'cp' with mode preservation workaround: copy file to itself to claim ownership,
# then use 'install' to set executable permission
pipeline(env).add(
[
"sh",
"-c",
f"cat '{DIFY_CLI_PATH}' > '{DIFY_CLI_PATH}.tmp' && "
f"mv '{DIFY_CLI_PATH}.tmp' '{DIFY_CLI_PATH}' && "
f"chmod +x '{DIFY_CLI_PATH}'",
],
error_message="Failed to mark dify CLI as executable",
).execute(raise_on_error=True)
logger.info("Dify CLI uploaded to sandbox, path=%s", DIFY_CLI_PATH)
artifact = SkillManager.load_tool_artifact(self._tenant_id, self._app_id, self._assets_id)

View File

@ -89,3 +89,12 @@ class CommandResult(BaseModel):
@property
def info_message(self) -> str:
return self.stdout.decode("utf-8", errors="replace") if self.stdout else ""
@property
def debug_message(self) -> str:
return (
f"stdout: {self.stdout.decode('utf-8', errors='replace')}\n"
f"stderr: {self.stderr.decode('utf-8', errors='replace')}\n"
f"exit_code: {self.exit_code}\n"
f"pid: {self.pid}"
)

View File

@ -30,7 +30,7 @@ class SandboxConfigValidationError(ValueError):
pass
class CommandExecutionError(Exception):
class CommandExecutionError(ValueError):
"""Raised when a command execution fails."""
result: CommandResult

View File

@ -1,5 +1,4 @@
import logging
import shlex
from collections.abc import Mapping, Sequence
from typing import Any
@ -90,7 +89,7 @@ class CommandNode(Node[CommandNodeData]):
try:
with with_connection(sandbox) as conn:
command = shlex.split(raw_command)
command = ["bash", "-c", raw_command]
sandbox_debug("command_node", "command", command)
@ -105,6 +104,8 @@ class CommandNode(Node[CommandNodeData]):
}
process_data = {"command": command, "working_directory": working_directory}
sandbox_debug("command_node", "outputs", result.debug_message)
if result.exit_code not in (None, 0):
stderr_text = result.stderr.decode("utf-8", errors="replace")
error_message = f"{stderr_text}\n\nCommand exited with code {result.exit_code}"