I wrote a python script that accesses system features which require root privileges. 
This "master" script is configured by running another Python script file, "config.py", using exec, that the user of my script would write and which configures some state variables in my script.
The master script file is root-owned while the config file is user owned (since my script users would want to modify this file).
Obviously this is not ideal, since the users of my script could run root-level commands in the config script. Is there a way to run the config file in user-level even if the master file was run in root?
Since it’s a config file, you might be better off making it something non-executable like a plain ini / yaml etc. I’m assuming you want to include it to access some constants. Sometimes it requires a little more work to set up, but ultimately, if the only code that runs is yours, you can be safe(er).
Run python file in sudo but config file in user space