code: def _join_shell_commands(
      commands: List[str], env: Optional[Dict[str, str]] = None
  ) -> str:
      if env is None:
          env = {}
      commands = [f"export {k}={v}" for k, v in env.items()] + commands
      for i, cmd in enumerate(commands):
          cmd = cmd.strip()
          if cmd.endswith("&"):  # escape background command
              cmd = "{ %s }" % cmd
          commands[i] = cmd
      return " && ".join(commands)
  
imports: import shlex
  import sys
  from abc import ABC, abstractmethod
  from typing import Dict, List, Optional
  import dstack.version
  from dstack._internal.core.models.configurations import ConfigurationType, PortMapping, PythonVersion, RegistryAuth
  from dstack._internal.core.models.profiles import SpotPolicy
  from dstack._internal.core.models.runs import AppSpec, DiskRequirements, Gateway, GpusRequirements, JobSpec, Requirements, RetryPolicy, RunSpec
  from dstack._internal.core.services.ssh.ports import filter_reserved_ports
label_desc: Use image node_id 1 for calling a global function with example usage: _join_shell_commands(commands, env) and returns: str