Using python shlex shlex (SHell Lexical analyzer) is a great way for improving python inputs sanitization Updated the code from the python2 examples taken from Python Module Of The Week's great work https://pymotw.com/2/shlex/