def METHOD_NAME(
        cmd: list[str],
        cwd: str | Path | None = None,
        env: dict[str, str] | None = None,
) -> list[str]:
    if not running_as_root():
        return cmd
    if isinstance(cwd, str):
        cwd = Path(cwd)
    env = env or {}
    args = parse_args()
    user_id = args.user_id
    base_root_isolator: list[str]
    preserve_envs = get_envs_to_preserve()
    if user_id:
        preserve_envs += list(env.keys())
        if PikaurConfig().misc.PrivilegeEscalationTool.get_str() == "doas":
            base_root_isolator = [
                PikaurConfig().misc.PrivilegeEscalationTool.get_str(),
                "-u", f"{user_id}",
            ]
        else:
            base_root_isolator = [
                PikaurConfig().misc.PrivilegeEscalationTool.get_str(),
                f"--user=#{user_id}",
            ]
            if preserve_envs:
                base_root_isolator.append(
                    "--preserve-env=" + ",".join(preserve_envs),
                )
            base_root_isolator.append(
                "--",
            )
    else:
        base_root_isolator = [
            "/usr/sbin/systemd-run",
            "--service-type=oneshot",
            "--pipe", "--wait", "--pty",
            "-p", "DynamicUser=yes",
            "-p", "CacheDirectory=pikaur",
            "-E", f"HOME={_UserTempRoot()()}",
        ]
        if cwd is not None:
            base_root_isolator += ["-p", "WorkingDirectory=" + str(cwd.resolve())]
        for env_var_name in preserve_envs:
            base_root_isolator += ["-E", f"{env_var_name}={os.environ[env_var_name]}"]
        for env_var_name, env_var_value in env.items():
            base_root_isolator += ["-E", f"{env_var_name}={env_var_value}"]
    return base_root_isolator + cmd