Running commands on host and get the output

I need to run a command on the host and get the output back. To be precise I need to run pkexec nvidia-smi <args> and get the exit code and output of it.

With Flatpak I can use flatpak-spawn --host <command> to do exactly this.
Is there an equivalent for Snap?

(this is a similar question, the difference is that here I want to run as root a command on the host system and there the I want to run as root a script part of the snap package)

There is no equivalent in snapd yet. What kind of permission controls flatpak-spawn --host? What kind of working directory is used?

It requires the extra permission --talk-name=org.freedesktop.Flatpak

Unfortunately I can’t answer this question right now because I’m not home and, for my use case, the working directory is not important so I never checked it (I just have to pkexec nvidia-smi).

Would the classic confinement help with this?

Since this is equivalent to breaking out of the confinement system. Using classic confinement is both “better” (you can run anything) but also worse (since you now need to ensure compatibility in a more complex way).

Yeah, I’m still trying to avoid it but it still good to know that there is the option, if needed.