tinyagent-py 0.0.15__py3-none-any.whl → 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tinyagent/code_agent/providers/__init__.py +14 -1
- tinyagent/code_agent/providers/base.py +29 -1
- tinyagent/code_agent/providers/modal_provider.py +9 -0
- tinyagent/code_agent/providers/seatbelt_provider.py +1065 -0
- tinyagent/code_agent/tiny_code_agent.py +674 -5
- tinyagent/code_agent/utils.py +187 -22
- tinyagent/prompts/truncation.yaml +13 -0
- tinyagent/tiny_agent.py +402 -49
- {tinyagent_py-0.0.15.dist-info → tinyagent_py-0.0.16.dist-info}/METADATA +25 -1
- {tinyagent_py-0.0.15.dist-info → tinyagent_py-0.0.16.dist-info}/RECORD +13 -11
- {tinyagent_py-0.0.15.dist-info → tinyagent_py-0.0.16.dist-info}/WHEEL +0 -0
- {tinyagent_py-0.0.15.dist-info → tinyagent_py-0.0.16.dist-info}/licenses/LICENSE +0 -0
- {tinyagent_py-0.0.15.dist-info → tinyagent_py-0.0.16.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,17 @@
|
|
1
1
|
from .base import CodeExecutionProvider
|
2
2
|
from .modal_provider import ModalProvider
|
3
3
|
|
4
|
-
|
4
|
+
# Import SeatbeltProvider conditionally to avoid errors on non-macOS systems
|
5
|
+
import platform
|
6
|
+
if platform.system() == "Darwin":
|
7
|
+
try:
|
8
|
+
from .seatbelt_provider import SeatbeltProvider
|
9
|
+
except ImportError:
|
10
|
+
# If there's an issue importing, just don't make it available
|
11
|
+
pass
|
12
|
+
|
13
|
+
__all__ = ["CodeExecutionProvider", "ModalProvider"]
|
14
|
+
|
15
|
+
# Add SeatbeltProvider to __all__ if it was successfully imported
|
16
|
+
if platform.system() == "Darwin" and "SeatbeltProvider" in globals():
|
17
|
+
__all__.append("SeatbeltProvider")
|
@@ -21,6 +21,9 @@ class CodeExecutionProvider(ABC):
|
|
21
21
|
pip_packages: List[str] = None,
|
22
22
|
secrets: Dict[str, Any] = None,
|
23
23
|
lazy_init: bool = True,
|
24
|
+
bypass_shell_safety: bool = False,
|
25
|
+
additional_safe_shell_commands: Optional[List[str]] = None,
|
26
|
+
additional_safe_control_operators: Optional[List[str]] = None,
|
24
27
|
**kwargs
|
25
28
|
):
|
26
29
|
self.log_manager = log_manager
|
@@ -35,15 +38,36 @@ class CodeExecutionProvider(ABC):
|
|
35
38
|
self._locals_dict = kwargs.get("locals_dict", {})
|
36
39
|
self._user_variables = {}
|
37
40
|
self.code_tools_definitions = []
|
41
|
+
|
42
|
+
# Shell safety configuration
|
43
|
+
self.bypass_shell_safety = bypass_shell_safety
|
44
|
+
|
38
45
|
# Safe shell commands that don't modify the system or access sensitive data
|
39
46
|
self.safe_shell_commands: Set[str] = {
|
40
47
|
"ls", "cat", "grep", "find", "echo", "pwd", "whoami", "date",
|
41
48
|
"head", "tail", "wc", "sort", "uniq", "tr", "cut", "sed", "awk",
|
42
|
-
"ps", "df", "du", "uname", "which", "type", "file", "stat","rg","if",
|
49
|
+
"ps", "df", "du", "uname", "which", "type", "file", "stat", "rg", "if",
|
43
50
|
"tree"
|
44
51
|
}
|
52
|
+
|
53
|
+
# Add additional safe shell commands if provided
|
54
|
+
if additional_safe_shell_commands:
|
55
|
+
if "*" in additional_safe_shell_commands:
|
56
|
+
# If wildcard is provided, allow all commands (effectively bypassing the check)
|
57
|
+
self.bypass_shell_safety = True
|
58
|
+
else:
|
59
|
+
self.safe_shell_commands.update(additional_safe_shell_commands)
|
60
|
+
|
45
61
|
# Safe control operators for shell commands
|
46
62
|
self.safe_control_operators: Set[str] = {"&&", "||", ";", "|"}
|
63
|
+
|
64
|
+
# Add additional safe control operators if provided
|
65
|
+
if additional_safe_control_operators:
|
66
|
+
if "*" in additional_safe_control_operators:
|
67
|
+
# If wildcard is provided, allow all operators
|
68
|
+
self.safe_control_operators = set("*")
|
69
|
+
else:
|
70
|
+
self.safe_control_operators.update(additional_safe_control_operators)
|
47
71
|
|
48
72
|
@abstractmethod
|
49
73
|
async def execute_python(
|
@@ -102,6 +126,10 @@ class CodeExecutionProvider(ABC):
|
|
102
126
|
- safe: Boolean indicating if command is safe
|
103
127
|
- reason: Reason why command is not safe (if applicable)
|
104
128
|
"""
|
129
|
+
# If shell safety checks are bypassed, consider all commands safe
|
130
|
+
if self.bypass_shell_safety:
|
131
|
+
return {"safe": True}
|
132
|
+
|
105
133
|
if type(command) == str:
|
106
134
|
command = command.split(" ")
|
107
135
|
if not command or not isinstance(command, list) or len(command) == 0:
|
@@ -47,6 +47,9 @@ class ModalProvider(CodeExecutionProvider):
|
|
47
47
|
sandbox_name: str = "tinycodeagent-sandbox",
|
48
48
|
local_execution: bool = False,
|
49
49
|
check_string_obfuscation: bool = True,
|
50
|
+
bypass_shell_safety: bool = False, # Default to False for ModalProvider
|
51
|
+
additional_safe_shell_commands: Optional[List[str]] = None,
|
52
|
+
additional_safe_control_operators: Optional[List[str]] = None,
|
50
53
|
**kwargs
|
51
54
|
):
|
52
55
|
"""
|
@@ -67,6 +70,9 @@ class ModalProvider(CodeExecutionProvider):
|
|
67
70
|
sandbox_name: Name of the Modal sandbox
|
68
71
|
local_execution: Whether to execute code locally
|
69
72
|
check_string_obfuscation: If True (default), check for string obfuscation techniques. Set to False to allow legitimate use of base64 encoding and other string manipulations.
|
73
|
+
bypass_shell_safety: If True, bypass shell command safety checks (default: False for modal)
|
74
|
+
additional_safe_shell_commands: Additional shell commands to consider safe
|
75
|
+
additional_safe_control_operators: Additional shell control operators to consider safe
|
70
76
|
**kwargs: Additional keyword arguments
|
71
77
|
|
72
78
|
Note:
|
@@ -114,6 +120,9 @@ class ModalProvider(CodeExecutionProvider):
|
|
114
120
|
pip_packages=final_packages,
|
115
121
|
secrets=modal_secrets or {},
|
116
122
|
lazy_init=lazy_init,
|
123
|
+
bypass_shell_safety=bypass_shell_safety,
|
124
|
+
additional_safe_shell_commands=additional_safe_shell_commands,
|
125
|
+
additional_safe_control_operators=additional_safe_control_operators,
|
117
126
|
**kwargs
|
118
127
|
)
|
119
128
|
|