попытка сделать изоляцию
This commit is contained in:
parent
a1235cf255
commit
59f6e5bc4e
4 changed files with 27 additions and 14 deletions
|
|
@ -3,7 +3,7 @@ import pwd
|
|||
import subprocess
|
||||
from typing import Any
|
||||
|
||||
from deepagents.backends.local_shell import LocalShellBackend, DEFAULT_EXECUTE_TIMEOUT
|
||||
from deepagents.backends.local_shell import LocalShellBackend
|
||||
|
||||
|
||||
class IsolatedShellBackend(LocalShellBackend):
|
||||
|
|
@ -34,8 +34,9 @@ class IsolatedShellBackend(LocalShellBackend):
|
|||
f"timeout must be positive, got {effective_timeout}"
|
||||
)
|
||||
|
||||
proc: subprocess.Popen[str] | None = None
|
||||
proc: subprocess.Popen | None = None
|
||||
try:
|
||||
print(f"Running shell: {command}")
|
||||
proc = subprocess.Popen(
|
||||
command,
|
||||
shell=True,
|
||||
|
|
@ -69,12 +70,13 @@ class IsolatedShellBackend(LocalShellBackend):
|
|||
if proc.returncode != 0:
|
||||
output = f"{output.rstrip()}\n\nExit code: {proc.returncode}"
|
||||
|
||||
return self._make_response(output, proc.returncode, truncated)
|
||||
result = self._make_response(output, proc.returncode, truncated)
|
||||
print(result)
|
||||
return result
|
||||
|
||||
except subprocess.TimeoutExpired:
|
||||
if proc:
|
||||
proc.kill()
|
||||
proc.communicate()
|
||||
proc.kill()
|
||||
proc.communicate()
|
||||
msg = f"Error: Command timed out after {effective_timeout} seconds."
|
||||
return self._make_response(msg, 124, False)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ def create_agent():
|
|||
)
|
||||
|
||||
workspace_dir = os.environ["WORKSPACE_DIR"]
|
||||
agent_user = os.environ["AGENT_USER"]
|
||||
agent_user = os.environ.get("AGENT_USER", "agent")
|
||||
|
||||
backend = IsolatedShellBackend(
|
||||
user=agent_user,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue