I am creating a wxpython application that I will compile with another freezing utility to create an executable file for several platforms.
the program will be a graphical editor for the tile-based game engine
in this application I want to provide a scripting system so that advanced users can change the behavior of the program, for example, change project data, export the project to another format, etc.
I want the system to work like this.
the user will put the python script that they want to run in the style text box, and then click the button to execute the script.
I am still happy with this; it's all very simple. get the script from the text field as a string that compiles it for the cod object with the built-in compile () function, then run the script with the status exec
script = textbox.text
The fact is that I want this function to not cause errors or errors, say, if there is an import statement in the script. will this cause any problems given that the code was compiled using something like py2exe or py2app?
how can I make sure that the user cannot break the critical part of the program, for example, modify part of the graphical interface, thereby allowing them to change project data (data is stored in global properties in its own module)? I think that would mean modifying the globals dict, which is passed to the eval function.
How can I make sure that this eval cannot cause the program to freeze due to a long or infinite loop? How can I make sure that an error that occurs inside the user code cannot lead to the failure of the entire application?
basically, how can I avoid all those problems that may arise when a user can run his own code?
EDIT: Regarding the responses received
I donโt feel that any of the answers so far really answered my questions yes, they were partially answered, but not completely. I know well that it is impossible to completely stop unsafe code. people are too smart for one person (or even abundance) to think of all the ways to circumvent the security system and prevent them.
I donโt really care if they do it. I am more concerned about some unintentional violation of what they did not know. if someone really wanted them to be able to tear the application to shreds using script functions, but I didn't care. this will be their instance, and the whole problem that they create will disappear when they restart the application, if they have not corrupted the files on HD. I want to prevent problems that occur when the user doses something stupid.
such as IOError, SystaxErrors, InfiniteLoopErrors, etc.
Now answered the part about the sphere. Now I understand how to determine what functions and global capabilities can be obtained from the eval function, but is there any way to make sure that their code can be stopped if it takes too long?
maybe a green thread system? (green because it will be eval so that users worry about thread safety)
also , if the user uses the import module statement to load a module from even the default library, which is not used in the rest of the class. can this cause problems with the application being frozen by Py2exe, Py2app or Freeze? what if they call the modal side of the standard library? would it be enough for the modal to be present in the same directory as the frozen executable?
I would like to get these answers without creating a new question, but I will if I have to.