code: def nailgunned_stdio(cls, sock, env, handle_stdin=True):
      
      # Determine output tty capabilities from the environment.
      stdin_isatty, stdout_isatty, stderr_isatty = NailgunProtocol.isatty_from_env(env)
      is_tty_capable = all((stdin_isatty, stdout_isatty, stderr_isatty))
  
      if is_tty_capable:
        with cls._tty_stdio(env) as finalizer:
          yield finalizer
      else:
        with cls._pipe_stdio(
          sock,
          stdin_isatty,
          stdout_isatty,
          stderr_isatty,
          handle_stdin
        ) as finalizer:
          yield finalizer
docs: Redirects stdio to the connected socket speaking the nailgun protocol.