@@ -375,13 +375,14 @@ def _write_seatbelt_profile_to_temp_file(self):
375375 self .logger .error ("Failed to write seatbelt profile to temporary file: %s" , str (e ))
376376 raise RuntimeError (f"Failed to write seatbelt profile: { str (e )} " )
377377
378- async def execute_python (self , code_lines : List [str ], timeout : int = 120 ) -> Dict [str , Any ]:
378+ async def execute_python (self , code_lines : List [str ], timeout : int = 120 , debug_mode : bool = False ) -> Dict [str , Any ]:
379379 """
380380 Execute Python code within a sandbox and return the result.
381381
382382 Args:
383383 code_lines: List of Python code lines to execute
384384 timeout: Maximum execution time in seconds
385+ debug_mode: Whether to print the executed code (useful for debugging)
385386
386387 Returns:
387388 Dictionary containing execution results
@@ -391,14 +392,16 @@ async def execute_python(self, code_lines: List[str], timeout: int = 120) -> Dic
391392
392393 full_code = "\n " .join (code_lines )
393394
394- print ("#" * 100 )
395- print ("##########################################code##########################################" )
396- print (full_code )
397- print ("#" * 100 )
395+ if debug_mode :
396+ print ("#" * 100 )
397+ print ("##########################################code##########################################" )
398+ print (full_code )
399+ print ("#" * 100 )
398400
399401 # Prepare the full code with tools and default codes if needed
400402 if self .executed_default_codes :
401- print ("✔️ default codes already executed" )
403+ if debug_mode :
404+ print ("✔️ default codes already executed" )
402405 complete_code = "\n " .join (self .code_tools_definitions ) + "\n \n " + full_code
403406 else :
404407 complete_code = "\n " .join (self .code_tools_definitions ) + "\n \n " + "\n " .join (self .default_python_codes ) + "\n \n " + full_code
@@ -701,7 +704,7 @@ def _sanitize_state_dict(d):
701704 result ["error" ] = f"Process exited with code { process .returncode } "
702705
703706 # Log the response
704- self ._log_response (result )
707+ self ._log_response (result , debug_mode )
705708
706709 return clean_response (result )
707710
@@ -738,29 +741,30 @@ def _sanitize_state_dict(d):
738741 except Exception :
739742 pass
740743
741- def _log_response (self , response : Dict [str , Any ]):
744+ def _log_response (self , response : Dict [str , Any ], debug_mode : bool = False ):
742745 """Log the response from code execution."""
743- print ("######################### SEATBELT EXECUTION #########################" )
744- print ("#########################<printed_output>#########################" )
745- print (response ["printed_output" ])
746- print ("#########################</printed_output>#########################" )
747- if response .get ("return_value" , None ) not in [None , "" ]:
748- print ("#########################<return_value>#########################" )
749- print (response ["return_value" ])
750- print ("#########################</return_value>#########################" )
751- if response .get ("stderr" , None ) not in [None , "" ]:
752- print ("#########################<stderr>#########################" )
753- print (response ["stderr" ])
754- print ("#########################</stderr>#########################" )
755- if response .get ("error_traceback" , None ) not in [None , "" ]:
756- print ("#########################<traceback>#########################" )
757- # Check if this is a security exception and highlight it in red if so
758- error_text = response ["error_traceback" ]
759- if "SECURITY" in error_text :
760- print (f"{ COLOR ['RED' ]} { error_text } { COLOR ['ENDC' ]} " )
761- else :
762- print (error_text )
763- print ("#########################</traceback>#########################" )
746+ if debug_mode :
747+ print ("######################### SEATBELT EXECUTION #########################" )
748+ print ("#########################<printed_output>#########################" )
749+ print (response ["printed_output" ])
750+ print ("#########################</printed_output>#########################" )
751+ if response .get ("return_value" , None ) not in [None , "" ]:
752+ print ("#########################<return_value>#########################" )
753+ print (response ["return_value" ])
754+ print ("#########################</return_value>#########################" )
755+ if response .get ("stderr" , None ) not in [None , "" ]:
756+ print ("#########################<stderr>#########################" )
757+ print (response ["stderr" ])
758+ print ("#########################</stderr>#########################" )
759+ if response .get ("error_traceback" , None ) not in [None , "" ]:
760+ print ("#########################<traceback>#########################" )
761+ # Check if this is a security exception and highlight it in red if so
762+ error_text = response ["error_traceback" ]
763+ if "SECURITY" in error_text :
764+ print (f"{ COLOR ['RED' ]} { error_text } { COLOR ['ENDC' ]} " )
765+ else :
766+ print (error_text )
767+ print ("#########################</traceback>#########################" )
764768
765769
766770 def _quote_command_for_shell (self , command : List [str ]) -> str :
@@ -915,7 +919,7 @@ async def _prepare_git_sandbox_command(self, command: List[str]) -> List[str]:
915919# Check if it's a GitHub URL
916920if [[ "$REMOTE_URL" == *"github.com"* ]]; then
917921 # Extract the repo path from the URL
918- REPO_PATH=$(echo "$REMOTE_URL" | sed -E 's|https://[^/]*github\.com/||' | sed -E 's|git@github\.com:||' | sed 's|\.git$||')
922+ REPO_PATH=$(echo "$REMOTE_URL" | sed -E 's|https://[^/]*github\\ .com/||' | sed -E 's|git@github\\ .com:||' | sed 's|\ \ .git$||')
919923
920924 # Set the remote URL with the token
921925 git remote set-url { remote_name } "https://{ github_username } :{ github_token } @github.com/$REPO_PATH.git"
0 commit comments