AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Option to disable working directory restrictions (#1875)
Josh XT9514919d376c
diff --git a/.env.template b/.env.templateindex 855cb91ffd..4fb09cf22a 100644--- a/.env.template+++ b/.env.template@@ -3,6 +3,8 @@################################################################################# EXECUTE_LOCAL_COMMANDS - Allow local command execution (Example: False)EXECUTE_LOCAL_COMMANDS=False+# RESTRICT_TO_WORKSPACE - Restrict file operations to workspace ./auto_gpt_workspace (Default: True)+RESTRICT_TO_WORKSPACE=True# BROWSE_CHUNK_MAX_LENGTH - When browsing website, define the length of chunk stored in memoryBROWSE_CHUNK_MAX_LENGTH=8192# USER_AGENT - Define the user-agent used by the requests library to browse website (string)diff --git a/autogpt/commands/file_operations.py b/autogpt/commands/file_operations.pyindex 72b02b5d31..ad145ec956 100644--- a/autogpt/commands/file_operations.py+++ b/autogpt/commands/file_operations.py@@ -3,8 +3,7 @@ from __future__ import annotationsimport osimport os.path-from pathlib import Path-from typing import Generator, List+from typing import Generatorimport requestsfrom colorama import Back, Forediff --git a/autogpt/config/config.py b/autogpt/config/config.pyindex 2fd300dd9a..1fe44edf28 100644--- a/autogpt/config/config.py+++ b/autogpt/config/config.py@@ -39,6 +39,9 @@ class Config(metaclass=Singleton):self.execute_local_commands = (os.getenv("EXECUTE_LOCAL_COMMANDS", "False") == "True")+ self.restrict_to_workspace = (+ os.getenv("RESTRICT_TO_WORKSPACE", "True") == "True"+ )if self.use_azure:self.load_azure_config()diff --git a/autogpt/workspace.py b/autogpt/workspace.pyindex 964a94d14d..6fb0e3113e 100644--- a/autogpt/workspace.py+++ b/autogpt/workspace.py@@ -3,6 +3,10 @@ from __future__ import annotationsimport osfrom pathlib import Path+from autogpt.config import Config++CFG = Config()+# Set a dedicated folder for file I/OWORKSPACE_PATH = Path(os.getcwd()) / "auto_gpt_workspace"@@ -35,9 +39,9 @@ def safe_path_join(base: Path, *paths: str | Path) -> Path:"""joined_path = base.joinpath(*paths).resolve()- if not joined_path.is_relative_to(base):+ if CFG.restrict_to_workspace and not joined_path.is_relative_to(base):raise ValueError(- f"Attempted to access path '{joined_path}' outside of working directory '{base}'."+ f"Attempted to access path '{joined_path}' outside of workspace '{base}'.")return joined_path