Skip to content

Commit

Permalink
Option to disable working directory restrictions (#1875)
Browse files Browse the repository at this point in the history
Remove restriction on working directory if RESTRICT_TO_WORKSPACE != True

---------

Co-authored-by: Reinier van der Leer <github@pwuts.nl>
  • Loading branch information
Josh-XT and Pwuts committed Apr 18, 2023
1 parent 24d5e1f commit 9514919
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions autogpt/commands/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

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
Expand Down
3 changes: 3 additions & 0 deletions autogpt/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __init__(self) -> None:
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()
Expand Down
8 changes: 6 additions & 2 deletions autogpt/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
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"

Expand Down Expand Up @@ -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

1 comment on commit 9514919

@fewmatty
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silly question! setting this to true or false removes the restriction?

Please sign in to comment.