Could that be
var scriptEngine = (IScriptEngine)ComponentManager.Singleton.InstanceFactory.GetSystemInstance(typeof(IScriptEngine).FullName);
if (scriptEngine == null)
throw new InvalidOperationException("No ScriptEngine accessible error.");
Also, if I have this running in a plugin (that is the way to do it?) in a separate thread, can I just call the Execute method or is there some dependency on the main thread?
Yes, that source looks like a valid, minimal script execution.
For more control about the script, you can create an IScriptExecutor.
IronPython by itself does not depend on the main thread, it is (or should be) as threading capable as other .NET languages like C#.
However, the standard scripting API we provide to the scripts using the script drivers is inherently bound to the primary thread (UI thread), as it calls into Automation Platform APIs.
If you do not want to use that API, just use an IScriptExecutor and don't call the "LoadScriptDrivers()" Method. Then your scripts can still use the whole .NET and IronPython standard library, as well as any APIs you provide or any Assemblies the script loads directly.
Check out the CODESYS store: http://store.codesys.com/CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions