Skip to content

armgit / letta

Public Imported from GitHub
0

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.py
index 139b8f252..d1a18e371 100644
--- a/letta/constants.py
+++ b/letta/constants.py
@@ -2,6 +2,7 @@ import os
from logging import CRITICAL, DEBUG, ERROR, INFO, NOTSET, WARN, WARNING
LETTA_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.py
index 391d4aad7..63313c87f 100644
--- a/letta/services/sandbox_config_manager.py
+++ b/letta/services/sandbox_config_manager.py
@@ -1,6 +1,6 @@
-from pathlib import Path
from typing import Dict, List, Optional
+from letta.constants import LETTA_DIR_TOOL_SANDBOX
from letta.log import get_logger
from letta.orm.errors import NoResultFound
from letta.orm.sandbox_config import SandboxConfig as SandboxConfigModel
@@ -35,7 +35,7 @@ class SandboxConfigManager:
default_config = {} # Empty
else:
# 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_SANDBOX
default_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.py
index 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_dir
with 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/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
diff --git a/letta/settings.py b/letta/settings.py
index 3f83bde21..0d5f9f804 100644
--- a/letta/settings.py
+++ b/letta/settings.py
@@ -10,10 +10,13 @@ from letta.local_llm.constants import DEFAULT_WRAPPER_NAME
class ToolSettings(BaseSettings):
composio_api_key: Optional[str] = None
- # Sandbox configurations
+ # E2B Sandbox configurations
e2b_api_key: Optional[str] = None
e2b_sandbox_template_id: Optional[str] = None # Updated manually
+ # Local Sandbox configurations
+ local_sandbox_dir: Optional[str] = None
+
class ModelSettings(BaseSettings):