Skip to content

Commit 674e34a

Browse files
refactor: change lib dir.
1 parent f341930 commit 674e34a

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

apps/common/utils/tool_code.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, sandbox=False):
2929
else:
3030
self.sandbox_path = os.path.join(PROJECT_DIR, 'data', 'sandbox')
3131
self.user = None
32-
self.sandbox_so_path = f'{self.sandbox_path}/sandbox.so'
32+
self.sandbox_so_path = f'{self.sandbox_path}/lib/sandbox.so'
3333
self.process_timeout_seconds = int(CONFIG.get("SANDBOX_PYTHON_PROCESS_TIMEOUT_SECONDS", '3600'))
3434
try:
3535
self._init_dir()
@@ -60,10 +60,9 @@ def _init_dir(self):
6060
tmp_dir_path = os.path.join(self.sandbox_path, 'tmp')
6161
os.makedirs(tmp_dir_path, 0o700, exist_ok=True)
6262
os.system(f"chown -R {self.user}:root {tmp_dir_path}")
63-
if os.path.exists(self.sandbox_so_path):
64-
os.chmod(self.sandbox_so_path, 0o440)
6563
# 初始化sandbox配置文件
66-
sandbox_conf_file_path = f'{self.sandbox_path}/.sandbox.conf'
64+
sandbox_lib_path = os.path.dirname(self.sandbox_so_path)
65+
sandbox_conf_file_path = f'{sandbox_lib_path}/.sandbox.conf'
6766
if os.path.exists(sandbox_conf_file_path):
6867
os.remove(sandbox_conf_file_path)
6968
allow_subprocess = CONFIG.get("SANDBOX_PYTHON_ALLOW_SUBPROCESS", '0')
@@ -75,7 +74,7 @@ def _init_dir(self):
7574
with open(sandbox_conf_file_path, "w") as f:
7675
f.write(f"SANDBOX_PYTHON_BANNED_HOSTS={banned_hosts}\n")
7776
f.write(f"SANDBOX_PYTHON_ALLOW_SUBPROCESS={allow_subprocess}\n")
78-
os.chmod(sandbox_conf_file_path, 0o440)
77+
os.system(f"chmod -R g-wx {sandbox_lib_path}")
7978

8079
def exec_code(self, code_str, keywords):
8180
_id = str(uuid.uuid7())

installer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update && \
1313
apt-get clean all && \
1414
rm -rf /var/lib/apt/lists/*
1515
WORKDIR /opt/maxkb-app
16-
RUN gcc -shared -fPIC -o ${MAXKB_SANDBOX_HOME}/sandbox.so /opt/maxkb-app/installer/sandbox.c -ldl && \
16+
RUN gcc -shared -fPIC -o ${MAXKB_SANDBOX_HOME}/lib/sandbox.so /opt/maxkb-app/installer/sandbox.c -ldl && \
1717
rm -rf /opt/maxkb-app/ui && \
1818
pip install uv --break-system-packages && \
1919
python -m uv pip install -r pyproject.toml && \

0 commit comments

Comments
 (0)