exec() is not safe to use in Python because it runs every code that it passed, so by through the exec() function hackers can access Python variables and sensitive data, any hacker can read and write files at host system so it is very dangerous to use exec() function.