Q:

Is it fine if an external program edit the sudoers file?

My program needs some local environment variables while running as root to perform certain tasks. Would it be fine to write a subroutine that can change users sudoers to keep these variables? It's not only going to run on my personal computer, it will run on many users computers. The environment variables I need are mainly DESKTOP_SESSION or any of its variants and QT_X11_NO_MITSHM

A:

Writing a subroutine that modifies system files (/etc/sudoers or any other really) whenever your program runs is a bad design idea. 
The more graceful  solution is that when you build and package your program for specific Linux distributions, such as for instance RHEL/CentOS 6 & 7, Ubuntu 16 & 18, you make use of and install a drop in configuration snippet in /etc/sudoers.d/program-name that will ensure that the specific sudo settings you need (such as protecting specific environment variables) are applied whenever your program runs. 

