<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(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Path) -> Result: """ Gets or builds an image for the repo, gets or starts a container for the image and runs the script. :param repo: Repository URL :param branch: Branch ane :param task: :class:`Task` to run. :param git_repo: :class:`Repo <git.repo.base.Repo>` of the cloned repository. :param repo_path: :class:`Path <pathlib.Path>` to the cloned location. """

        self.check_docker_access()

        container_name = self.get_container_name(repo, branch, git_repo)

        container = self.container_running(container_name)
        if container is None:
            image = self.get_image_for_repo(repo, branch, git_repo, repo_path)

            container = self.start_container(image, container_name, repo_path)

        task_filename, task_json = self.serialized_task(task)

        container.put_archive("/srv/scripts", self.tar_task_definition(task_filename, task_json))

        res = None

        try:
            command = ["timeout"]

            if self.inherit_image:
                if self.alpine_inherited or b"Alpine" in container.exec_run(["cat", "/etc/issue"], tty=True).output:
                    self.alpine_inherited = True
                    command = ["timeout", "-t"]

            command += [str(task.timeout),
                        "python",
                        "/srv/scripts/runner.py",
                        f"/srv/scripts/{task_filename}"]

            logger.debug("Running command %s", " ".join(command))

            res = container.exec_run(command, tty=True)

            # 124 is the standard, 143 on alpine
            if res.exit_code in {124, 143}:
                raise BuildTimeoutError(f"The task timeouted after {task.timeout} seconds.")

            return Result(res.output)
        except BuildError:  # can be raised by  :meth:`Result.__init__`
            raise
        except Exception as e:
            logger.exception(e)
            if res is not None:
                logger.warning(res.output)

            raise BuildError("The build failed", extra_info={
                "exception": e,
                "output": res if res is None else res.output
            })
        finally:
            if not self.keep_container_running:
                container.kill(signal.SIGKILL)
            else:
                self._containers.add(container)