sandbox/executor.py
def execute(self, container: Container) -> Tuple[bool, dict]:
        """Execute the command on the given container."""
        start = time.time()
        try:
            exec_run = timeout(
                self.timeout, use_signals=False
            )(container.exec_run)
            exit_code, output = exec_run(
                ["bash", "-c", self.command], environment=self.environ, demux=True)
            stdout, stderr = ("" if out is None else out.decode().strip() for out in output)
        except TimeoutError:
            exit_code = SandboxErrCode.TIMEOUT.value
            stdout = ""
            stderr = f"Command timed out after {self.timeout} seconds\n"
        except Exception:  # pragma: no cover
            logger.exception(f"An error occurred while executing the command '{self.command}'")
            exit_code = SandboxErrCode.UNKNOWN.value
            stdout = ""
            stderr = "An unknown error occurred on the sandbox\n"
        
        result = {
            "command":   self.command,
            "exit_code": exit_code,
            "stdout":    stdout,
            "stderr":    stderr,
            "time":      time.time() - start,
        }
        
        if exit_code < 0 and exit_code != SandboxErrCode.TIMEOUT.value:  # pragma: no cover
            status = False
        elif self.ignore_failure:
            status = True
        else:
            status = (exit_code == 0)
        
        return status, result
Execute the command on the given container.
Execute the command on the given container.
Execute the command on the given container .
def execute(self, container: Container) -> Tuple[bool, dict]:
        start = time.time()
        try:
            exec_run = timeout(
                self.timeout, use_signals=False
            )(container.exec_run)
            exit_code, output = exec_run(
                ["bash", "-c", self.command], environment=self.environ, demux=True)
            stdout, stderr = ("" if out is None else out.decode().strip() for out in output)
        except TimeoutError:
            exit_code = SandboxErrCode.TIMEOUT.value
            stdout = ""
            stderr = f"Command timed out after {self.timeout} seconds\n"
        except Exception:  
            logger.exception(f"An error occurred while executing the command '{self.command}'")
            exit_code = SandboxErrCode.UNKNOWN.value
            stdout = ""
            stderr = "An unknown error occurred on the sandbox\n"
        result = {
            "command":   self.command,
            "exit_code": exit_code,
            "stdout":    stdout,
            "stderr":    stderr,
            "time":      time.time() - start,
        }
        if exit_code < 0 and exit_code != SandboxErrCode.TIMEOUT.value:  
            status = False
        elif self.ignore_failure:
            status = True
        else:
            status = (exit_code == 0)
        return status, result
def execute ( self , container : Container ) -> Tuple [ bool , dict ] : start = time . time ( ) try : exec_run = timeout ( self . timeout , use_signals = False ) ( container . exec_run ) exit_code , output = exec_run ( [ "bash" , "-c" , self . command ] , environment = self . environ , demux = True ) stdout , stderr = ( "" if out is None else out . decode ( ) . strip ( ) for out in output ) except TimeoutError : exit_code = SandboxErrCode . TIMEOUT . value stdout = "" stderr = f"Command timed out after {self.timeout} seconds\n" except Exception : logger . exception ( f"An error occurred while executing the command '{self.command}'" ) exit_code = SandboxErrCode . UNKNOWN . value stdout = "" stderr = "An unknown error occurred on the sandbox\n" result = { "command" : self . command , "exit_code" : exit_code , "stdout" : stdout , "stderr" : stderr , "time" : time . time ( ) - start , } if exit_code < 0 and exit_code != SandboxErrCode . TIMEOUT . value : status = False elif self . ignore_failure : status = True else : status = ( exit_code == 0 ) return status , result
Execute the command on the given container.
Execute the command on the given container .
"""Execute the command on the given container.""" # pragma: no cover # pragma: no cover
self
container
Container