akseljoonas HF Staff commited on
Commit
76996d0
·
1 Parent(s): 8ded4a9

enabled passing sandbox scripts to hf jobs

Browse files
Files changed (1) hide show
  1. agent/tools/jobs_tool.py +21 -0
agent/tools/jobs_tool.py CHANGED
@@ -1015,6 +1015,27 @@ async def hf_jobs_handler(
1015
  Event(event_type="tool_log", data={"tool": "hf_jobs", "log": log})
1016
  )
1017
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1018
  # Get token and namespace from HF token
1019
  hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
1020
  namespace = HfApi(token=hf_token).whoami().get("name") if hf_token else None
 
1015
  Event(event_type="tool_log", data={"tool": "hf_jobs", "log": log})
1016
  )
1017
 
1018
+ # If script is a sandbox file path, read it from the sandbox
1019
+ script = arguments.get("script", "")
1020
+ sandbox = getattr(session, "sandbox", None) if session else None
1021
+ is_path = (
1022
+ sandbox
1023
+ and isinstance(script, str)
1024
+ and script.strip() == script
1025
+ and not any(c in script for c in "\r\n\0")
1026
+ and (
1027
+ script.startswith("/")
1028
+ or script.startswith("./")
1029
+ or script.startswith("../")
1030
+ )
1031
+ )
1032
+ if is_path:
1033
+ import shlex
1034
+ result = await asyncio.to_thread(sandbox.bash, f"cat {shlex.quote(script)}")
1035
+ if not result.success:
1036
+ return f"Failed to read {script} from sandbox: {result.error}", False
1037
+ arguments = {**arguments, "script": result.output}
1038
+
1039
  # Get token and namespace from HF token
1040
  hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_HUB_TOKEN")
1041
  namespace = HfApi(token=hf_token).whoami().get("name") if hf_token else None