Skip to content

Commit 6ef8d22

Browse files
authored
Merge pull request #1445 from lolsZz/main
Add sudo support for apt package installation in Terminal
2 parents 286e9c5 + 623b776 commit 6ef8d22

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,4 @@ misc/
235235

236236
# Ignore litellm_uuid.txt
237237
litellm_uuid.txt
238+
.aider*

interpreter/core/computer/terminal/terminal.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import os
33
import time
4+
import subprocess
5+
import getpass
46

57
from ..utils.recipient_utils import parse_for_recipient
68
from .languages.applescript import AppleScript
@@ -45,6 +47,29 @@ def __init__(self, computer):
4547
]
4648
self._active_languages = {}
4749

50+
def sudo_install(self, package):
51+
try:
52+
# First, try to install without sudo
53+
subprocess.run(['apt', 'install', '-y', package], check=True)
54+
except subprocess.CalledProcessError:
55+
# If it fails, try with sudo
56+
print(f"Installation of {package} requires sudo privileges.")
57+
sudo_password = getpass.getpass("Enter sudo password: ")
58+
59+
try:
60+
# Use sudo with password
61+
subprocess.run(
62+
['sudo', '-S', 'apt', 'install', '-y', package],
63+
input=sudo_password.encode(),
64+
check=True
65+
)
66+
print(f"Successfully installed {package}")
67+
except subprocess.CalledProcessError as e:
68+
print(f"Failed to install {package}. Error: {e}")
69+
return False
70+
71+
return True
72+
4873
def get_language(self, language):
4974
for lang in self.languages:
5075
if language.lower() == lang.name.lower() or (
@@ -55,6 +80,14 @@ def get_language(self, language):
5580
return None
5681

5782
def run(self, language, code, stream=False, display=False):
83+
# Check if this is an apt install command
84+
if language == "shell" and code.strip().startswith("apt install"):
85+
package = code.split()[-1]
86+
if self.sudo_install(package):
87+
return [{"type": "console", "format": "output", "content": f"Package {package} installed successfully."}]
88+
else:
89+
return [{"type": "console", "format": "output", "content": f"Failed to install package {package}."}]
90+
5891
if language == "python":
5992
if (
6093
self.computer.import_computer_api

0 commit comments

Comments
 (0)