INNER CODE UNIT · Python
_check_danger
handrew/browserpilot · browserpilot/agents/gpt_selenium_agent.py:153
def _check_danger(self, action_str):
"""Check that the action is not dangerous. If so, just quit."""
if (self.disable_danger_check is True):
logger.warning("Caution! We are not checking for dangerous actions returned by the LLM.")
return
if (self._is_potentially_dangerous(action_str)):
logger.warning("Action is potentially dangerous. Exiting.")
logger.warning(f"Action: {action_str}")
sys.exit(1)
def _is_potentially_dangerous(self, code_str):
"""Isaac Asimov is rolling over in his grave."""
# Check that the code doesn't try any funny business with the importing.
if "import " in code_str:
return True
# Check that the code doesn't use any of the following libraries.
blacklisted_libraries = ["shutil", "requests", "urllib"] # "os", "sys".