mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-02-08 07:44:22 +01:00
Option to disable working directory restrictions (#1875)
Remove restriction on working directory if RESTRICT_TO_WORKSPACE != True --------- Co-authored-by: Reinier van der Leer <github@pwuts.nl>
This commit is contained in:
@@ -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 memory
|
||||
BROWSE_CHUNK_MAX_LENGTH=8192
|
||||
# USER_AGENT - Define the user-agent used by the requests library to browse website (string)
|
||||
|
||||
@@ -3,8 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import os.path
|
||||
from pathlib import Path
|
||||
from typing import Generator, List
|
||||
from typing import Generator
|
||||
|
||||
import requests
|
||||
from colorama import Back, Fore
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -3,6 +3,10 @@ from __future__ import annotations
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from autogpt.config import Config
|
||||
|
||||
CFG = Config()
|
||||
|
||||
# Set a dedicated folder for file I/O
|
||||
WORKSPACE_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
|
||||
|
||||
Reference in New Issue
Block a user