How to make snap use system environment variables?

My snap needs to access the PATH environment variable because it runs commands. However, the PATH environment variable for the snap is different than my system PATH. I’m pretty sure this is because it’s confinement is strict, but, for example, to use files I was able to use the home plug. What is the plug to access the system environment variables so I can get the correct PATH variable?

Snaps generally already inherit environment variables, though certain ones as you’ve noticed are overwritten.

It wouldn’t make sense to use the PATH variable from the host since the a strict snap exists in a mount namespace provided by the core snap that means it has a consistent view of a filesystem that’s independent of the host.

The strict model is incompatible with being able to run binaries from the host, if you need a command to be available it’s expected that it’s specifically bundled along with the snap, is there something in particular that you’re relying upon?

My app is supposed to be able to use the user-installed version if they want, due to that usually working better. However, since the PATH variable isn’t the same, it doesn’t work. Is there a way of forcing it to overwrite the PATH variable with the host’s? My program has all libraries embedded into the executable so it doesn’t use the PATH variable in any way besides the system command thing.

Only classic apps can get unrestricted access to arbitrary binaries, and generally few apps are granted classic permissions. In the strict confinement model, there’s no way to achieve arbitrary binary access.

Since you can pick the binaries in the snap itself, you should in theory be able to pick ones that work best for your snap without having to rely on the users system, but of course this depends what binaries you’re actually expecting to use, so it’d be helpful to know which binaries you’re reliant upon.

There’s some limited potential to open applications outside your snap for the purposes of viewing/editing files, e.g, you could attempt to load a specific file in a text editor, image viewer, etc; by opening a GUI that the user can pick the app of their choice from and that app doesn’t have to be bundled with your snap, if this is what you’re looking for you can probably achieve it in a strict snap by making use of what’s known as xdg-desktop-portals.