Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: Adjust tool execution sandbox to be under ~/.letta (#591)
Matthew Zhouf311e447fa32
diff --git a/letta/constants.py b/letta/constants.pyindex 139b8f252..d1a18e371 100644--- a/letta/constants.py+++ b/letta/constants.py@@ -2,6 +2,7 @@ import osfrom logging import CRITICAL, DEBUG, ERROR, INFO, NOTSET, WARN, WARNINGLETTA_DIR = os.path.join(os.path.expanduser("~"), ".letta")+LETTA_DIR_TOOL_SANDBOX = os.path.join(LETTA_DIR, "tool_sandbox_dir")ADMIN_PREFIX = "/v1/admin"API_PREFIX = "/v1"diff --git a/letta/services/sandbox_config_manager.py b/letta/services/sandbox_config_manager.pyindex 391d4aad7..63313c87f 100644--- a/letta/services/sandbox_config_manager.py+++ b/letta/services/sandbox_config_manager.py@@ -1,6 +1,6 @@-from pathlib import Pathfrom typing import Dict, List, Optional+from letta.constants import LETTA_DIR_TOOL_SANDBOXfrom letta.log import get_loggerfrom letta.orm.errors import NoResultFoundfrom letta.orm.sandbox_config import SandboxConfig as SandboxConfigModel@@ -35,7 +35,7 @@ class SandboxConfigManager:default_config = {} # Emptyelse:# TODO: May want to move this to environment variables v.s. persisting in database- default_local_sandbox_path = str(Path(__file__).parent / "tool_sandbox_env")+ default_local_sandbox_path = LETTA_DIR_TOOL_SANDBOXdefault_config = LocalSandboxConfig(sandbox_dir=default_local_sandbox_path).model_dump(exclude_none=True)sandbox_config = self.create_or_update_sandbox_config(SandboxConfigCreate(config=default_config), actor=actor)diff --git a/letta/services/tool_execution_sandbox.py b/letta/services/tool_execution_sandbox.pyindex e07c4ea2d..3e68ad291 100644--- a/letta/services/tool_execution_sandbox.py+++ b/letta/services/tool_execution_sandbox.py@@ -119,8 +119,9 @@ class ToolExecutionSandbox:env.update(additional_env_vars)# Safety checks- if not os.path.isdir(local_configs.sandbox_dir):- raise FileNotFoundError(f"Sandbox directory does not exist: {local_configs.sandbox_dir}")+ if not os.path.exists(local_configs.sandbox_dir) or not os.path.isdir(local_configs.sandbox_dir):+ logger.warning(f"Sandbox directory does not exist, creating: {local_configs.sandbox_dir}")+ os.makedirs(local_configs.sandbox_dir)# Write the code to a temp file in the sandbox_dirwith tempfile.NamedTemporaryFile(mode="w", dir=local_configs.sandbox_dir, suffix=".py", delete=False) as temp_file:diff --git a/letta/services/tool_sandbox_env/.gitkeep b/letta/services/tool_sandbox_env/.gitkeepdeleted file mode 100644index e69de29bb..000000000diff --git a/letta/settings.py b/letta/settings.pyindex 3f83bde21..0d5f9f804 100644--- a/letta/settings.py+++ b/letta/settings.py@@ -10,10 +10,13 @@ from letta.local_llm.constants import DEFAULT_WRAPPER_NAMEclass ToolSettings(BaseSettings):composio_api_key: Optional[str] = None- # Sandbox configurations+ # E2B Sandbox configurationse2b_api_key: Optional[str] = Nonee2b_sandbox_template_id: Optional[str] = None # Updated manually+ # Local Sandbox configurations+ local_sandbox_dir: Optional[str] = None+class ModelSettings(BaseSettings):