<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _run_command(self, ssh, cmd, pty=True):
 """Run a command remotely via SSH. :param object ssh: The SSHClient :param str cmd: The command to execute :param list cmd: The `shlex.split` command to execute :param bool pty: Whether to allocate a pty :return: tuple: The stdout and stderr of the command execution :raises: :class:`CalledProcessError` if the command fails """


        if isinstance(cmd, str):
            cmd = shlex.split(cmd)

        if type(cmd) is not list:
            cmd = [cmd]

        cmds = ' '.join(cmd)
        stdin, stdout, stderr = ssh.exec_command(cmds, get_pty=pty)
        retcode = stdout.channel.recv_exit_status()

        if retcode > 0:
            output = stderr.read().strip()
            raise CalledProcessError(returncode=retcode, cmd=cmd,
                                     output=output)
        return (
            stdout.read().decode('utf-8').strip(),
            stderr.read().decode('utf-8').strip()
        )