|
@@ -13,6 +13,8 @@ import json
|
|
|
import os
|
|
import os
|
|
|
import re
|
|
import re
|
|
|
import subprocess
|
|
import subprocess
|
|
|
|
|
+
|
|
|
|
|
+from lambdagent.builtin_tools._sandbox import check_write_allowed
|
|
|
from typing import Any, Dict, Optional
|
|
from typing import Any, Dict, Optional
|
|
|
|
|
|
|
|
|
|
|
|
@@ -190,6 +192,11 @@ def edit_file(input_val: Any) -> str:
|
|
|
new = params["new_string"]
|
|
new = params["new_string"]
|
|
|
replace_all = params.get("replace_all", False)
|
|
replace_all = params.get("replace_all", False)
|
|
|
|
|
|
|
|
|
|
+ # P1 工作文件夹硬沙箱:工作区模式下禁止改写所选文件夹之外的文件。
|
|
|
|
|
+ ok, err = check_write_allowed(path)
|
|
|
|
|
+ if not ok:
|
|
|
|
|
+ return err
|
|
|
|
|
+
|
|
|
if not os.path.exists(path):
|
|
if not os.path.exists(path):
|
|
|
return f"[ERROR] File not found: {path}"
|
|
return f"[ERROR] File not found: {path}"
|
|
|
|
|
|
|
@@ -246,6 +253,11 @@ def write_file(input_val: Any) -> str:
|
|
|
path = params["file_path"]
|
|
path = params["file_path"]
|
|
|
content = params["content"]
|
|
content = params["content"]
|
|
|
|
|
|
|
|
|
|
+ # P1 工作文件夹硬沙箱:工作区模式下禁止写到所选文件夹之外。
|
|
|
|
|
+ ok, err = check_write_allowed(path)
|
|
|
|
|
+ if not ok:
|
|
|
|
|
+ return err
|
|
|
|
|
+
|
|
|
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
|
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
|
|
|
|
|
|
|
existed = os.path.exists(path)
|
|
existed = os.path.exists(path)
|