compute_rhino3d.Util.PythonEvaluate() script raises import error

Hello everyone!

I have recently tried to run and debug Compute locally by following the guides and then tried to call compute with python. I am particularly interested in the PythonEvaluate() function as I already have scripts that open the right Grasshopper files, manipulate their parameters and export the data from Rhino in a specific format.

However, when I try to import some important modules such as os, re or even Grasshopper (which is the only way to access the Grasshopper SDK I guess), I get this Exception:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Exception: Attempt to import module that is not permitted

After some research, some modules are apparently restricted as they can be used maliciously. Is there a way to still evaluate python scripts importing other modules than the Rhino namespace?

Most of what I have explored lately such as launching a local server or csharp programming is still very very new to me so please be free to correct me if I’m incorrect in any way.

Thank you very much for your time and attention,

Have an excellent day :slight_smile:

PS: here is the python code that tries to call the PythonEvaluate() function of Rhino.Compute.
When placing only ‘import Rhino’ for example in the script docstring, I get a code 200, however, when I try to import anything else such as Grasshopper I get the error mentioned above

import compute_rhino3d.Util

compute_rhino3d.Util.url = “http://localhost:6500/

compute_rhino3d.Util.apiKey = “”

Open the main.py file

“”“with open(“main.py”, “r”) as f:
# Read the contents of the file into a string
script = f.read()”“”

script = “”"
import Rhino
import Grasshopper
“”"

result = compute_rhino3d.Util.PythonEvaluate(script, {}, )