"Operation not permitted" on using os.setuid( ) [python]

car*_*esh 6 python privileges operating-system setuid

I'm trying to build a platform to launch some scripts. This scripts are placed in home folder of each user. Every launch should be done with each user id so, I'm doing, for each user, this:

user_id = pwd.getpwnam( user )[ 3 ]
user_home = pwd.getpwnam( user )[ 5 ]

os.chdir( user_home )
os.setuid( user_id )

subprocess.Popen( shlex.split( "user_script.py" ) )
Run Code Online (Sandbox Code Playgroud)

But, when python trys to do os.setuid( user_id ) it raise this exception:

Traceback (most recent call last):
  File "launcher.py", line XX, in <module>

OSError: [Errno 1] Operation not permitted
Run Code Online (Sandbox Code Playgroud)

By the way, the user who starts this script is in the root group (on GNU/linux OS) and it has all the root privileges.

If I try to launch the same code with root user I get a different error:

OSError: [Errno 13] Permission denied
Run Code Online (Sandbox Code Playgroud)

If someone can help me to understand what's happening please...

ott*_*t-- 5

Only root can do a setuid, being in the root-group is not enough.