From ad1742fd0fdcfe7c7f6657f17420e5d6c53840d6 Mon Sep 17 00:00:00 2001 From: liqiang-fit2cloud Date: Mon, 10 Nov 2025 09:39:54 +0800 Subject: [PATCH] refactor: delete .SANDBOX_BANNED_HOSTS file if SANDBOX_PYTHON_BANNED_KEYWORDS is empty/ --- apps/common/utils/tool_code.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/common/utils/tool_code.py b/apps/common/utils/tool_code.py index 828819362..2e6abd4c6 100644 --- a/apps/common/utils/tool_code.py +++ b/apps/common/utils/tool_code.py @@ -28,14 +28,14 @@ class ToolExecutor: os.system(f"chown -R {self.user}:root {self.sandbox_path}") self.banned_keywords = CONFIG.get("SANDBOX_PYTHON_BANNED_KEYWORDS", 'nothing_is_banned').split(','); try: + banned_hosts_file_path = f'{self.sandbox_path}/.SANDBOX_BANNED_HOSTS' + if os.path.exists(banned_hosts_file_path): + os.remove(banned_hosts_file_path) banned_hosts = CONFIG.get("SANDBOX_PYTHON_BANNED_HOSTS", '').strip() if banned_hosts: hostname = socket.gethostname() local_ip = socket.gethostbyname(hostname) banned_hosts = f"{banned_hosts},{hostname},{local_ip}" - banned_hosts_file_path = f'{self.sandbox_path}/.SANDBOX_BANNED_HOSTS' - if os.path.exists(banned_hosts_file_path): - os.remove(banned_hosts_file_path) with open(banned_hosts_file_path, "w") as f: f.write(banned_hosts) os.chmod(banned_hosts_file_path, 0o644)