docs: def command(self,
                  container: Container,
                  cmd: str,
                  context: Optional[str] = None,
                  stdout: bool = True,
                  stderr: bool = False,
                  block: bool = True,
                  verbose: bool = False,
                  time_limit: Optional[int] = None,
                  kill_after: Optional[int] = 1
                  ) -> Union[ExecResponse, PendingExecResponse]:
          """
          Executes a provided shell command inside a given container.
  
          Parameters:
              time_limit: an optional parameter that is used to specify the
                  number of seconds that the command should be allowed to run
                  without completing before it is aborted. Only supported by
                  blocking calls.
  
          Returns:
              a description of the response.
  
          Raises:
              TimeoutError: if a time limit is given and the command fails
                  to complete within that time. Only supported by blocking calls.
          """
          cmd_original = cmd
          logger_c = logger.getChild(container.uid)
          logger_c.debug('executing command "%s"', cmd)
          bug = self.__installation.bugs[container.bug]
  
          # TODO: we need a better long-term alternative
          if context is None:
              context = os.path.join(bug.source_dir, '..')
          logger_c.debug('using execution context: %s', context)
  
          cmd = 'source /.environment && cd {} && {}'.format(context, cmd)
          cmd_wrapped = "/bin/bash -c '{}'".format(cmd)
          if time_limit is not None and time_limit > 0:
              logger_c.debug("running command with time limit: %d seconds", time_limit)  # noqa: pycodestyle
              cmd_template = "timeout --kill-after={} --signal=SIGTERM {} {}"
              cmd_wrapped = cmd_template.format(kill_after,
                                                time_limit,
                                                cmd_wrapped)
          cmd = cmd_wrapped
  
          # based on: https://github.com/roidelapluie/docker-py/commit/ead9ffa34193281967de8cc0d6e1c0dcbf50eda5
          logger_c.debug("executing raw command: %s", cmd)
          logger_c.debug('creating exec object for command: %s', cmd)
          docker_client = self.__installation.docker
          try:
              response = docker_client.api.exec_create(container.id,
                                                       cmd,
                                                       tty=True,
                                                       stdout=stdout,
                                                       stderr=stderr)
          except docker.errors.APIError:
              logger_c.exception('failed to create exec object for command: %s', cmd)  # noqa: pycodestyle
              raise
          logger_c.debug("created exec object for command: %s", cmd)
          exec_id = response['Id']
  
          time_start = timer()
          out = self.__api_docker.exec_start(exec_id, stream=True)
  
          if not block:
              return PendingExecResponse(response, out)
  
          output = []
          for line in out:
              line = line.decode('utf-8').rstrip('\n')
              if verbose:
                  print(line, flush=True)
              output.append(line)
          time_running = timer() - time_start
          output = '\n'.join(output)
          code = self.__api_docker.exec_inspect(exec_id)['ExitCode']
          logger_c.debug('finished executing command: %s. (exited with code %d and took %.2f seconds.)\n%s',  # noqa: pycodestyle
                         cmd_original, code, time_running, output)
  
          return ExecResponse(code, time_running, output)