How to execute programs outside of snap package

I’m trying to make a snap package for my program, the program should be able to execute any outside program (specified by user).

The programs are executed like you would normally do it in a terminal (“programName args”);

But doing that it says something like: “/bin/sh: 1: programName: not found”.

So I am closer to the solution. What I did was I added the environment key in my snapcraft.yaml with these contents:

environment:
    "PATH": "$PATH:/var/lib/snapd/hostfs/bin"

Which makes the hosts bin directory accessible to the snap

What I’d like to do is to add all the values of $PATH from the host user to the snap environment’s $PATH

Running apps this way will break if that app tries to find stuff in the file system (like /var/lib or something)

You’re running in devmode. Once you switch to strict confinement the access of /var/lib/snapd/hostfs/bin will stop working. A couple of questions that will enable us to answer a bit more concretely:

  • Why do you need access to binaries on the host system?
  • Can you get away with bundling these binaries into your snap?
  • Does your snap need to be able to run on Ubuntu Core devices?

The app is a sort of a “build system”. It executes scripts according to a config file. One script might call some compiler or another program to do some stuff. It is essential to how the project works, so I can’t bundle these apps.

And I’m not even sure what Ubuntu Core devices are, so I guess not?

For build systems we tend to recommend classic confinement which means your snap has full access to the system on which it is running. It is required that you go through the process of applying for classic confinement. Classic confinement is not possible to be used on an Ubuntu Core device, however.

Yeah I’m fine with that. But how would I go about giving all apps proper paths and stuff without having to adjust it manually for every map?

For example if I want to run a command “pug” inside the package which depends on node, it would complain that it couldn’t find node in /some/path. The path should be on the host system but the program is looking inside the snap.