code: def _setup_environment(self, environments):
          
          # If keepEnv is set or sudo is used, start from a fresh environment,
          # otherwise with the current one.
          # keepEnv specifies variables to copy from the current environment,
          # newEnv specifies variables to set to a new value,
          # additionalEnv specifies variables where some value should be appended, and
          # clearEnv specifies variables to delete.
          if self._user is not None or environments.get("keepEnv", None) is not None:
              run_environment = {}
          else:
              run_environment = os.environ.copy()
          for key, value in environments.get("keepEnv", {}).items():
              if key in os.environ:
                  run_environment[key] = os.environ[key]
          for key, value in environments.get("newEnv", {}).items():
              run_environment[key] = value
          for key, value in environments.get("additionalEnv", {}).items():
              run_environment[key] = os.environ.get(key, "") + value
          for key in environments.get("clearEnv", {}).items():
              run_environment.pop(key, None)
  
          logging.debug("Using additional environment %s.", environments)
          return run_environment
docs: Return map with desired environment variables for run.