Please ignore my previous question. Sucessfully added FileIOPermission with PathDiscovery and it worked:<div><br></div><div><div>      var pythonLibsPath = ExpressionEvaluator.GetPythonLibsPath();</div><div>      permissionSet.AddPermission(new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, pythonLibsPath));</div>
</div><div><br></div><div><br></div><div>Now I&#39;m facing some problem with Emit permissions. Added ReflectionPermission(PermissionState.Unrestricted) but still doesn&#39;t work.</div><div><br></div><div>I&#39;m using .NET 4 in this project at work. Sorry if the subject is too general and off-topic.</div>
<div><br></div><div>Best regards</div><div>Mello</div><div><br></div><div>Message: Request for the permission of type &#39;System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&#39; failed.</div>
<div><br></div><div><div>at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp; stackMark, Boolean isPermSet)</div><div>   at System.Security.CodeAccessPermission.Demand()</div><div>   at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModuleInternalNoLock(String name, Boolean emitSymbolInfo, StackCrawlMark&amp; stackMark)</div>
<div>   at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModuleInternal(String name, Boolean emitSymbolInfo, StackCrawlMark&amp; stackMark)</div><div>   at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule(String name, Boolean emitSymbolInfo)</div>
<div>   at Microsoft.Scripting.Generation.AssemblyGen..ctor(AssemblyName name, String outDir, String outFileExtension, Boolean isDebuggable, PortableExecutableKinds peKind, ImageFileMachine machine)</div><div>   at Microsoft.Scripting.Generation.AssemblyGen..ctor(AssemblyName name, String outDir, String outFileExtension, Boolean isDebuggable)</div>
<div>   at Microsoft.Scripting.Generation.Snippets.CreateNewAssembly(String nameSuffix, Boolean emitSymbols)</div><div>   at Microsoft.Scripting.Generation.Snippets.GetOrCreateAssembly(Boolean emitSymbols, AssemblyGen&amp; assembly)</div>
<div>   at Microsoft.Scripting.Generation.Snippets.GetAssembly(Boolean emitSymbols)</div><div>   at Microsoft.Scripting.Generation.Snippets.DefineType(String name, Type parent, Boolean preserveName, Boolean emitDebugSymbols)</div>
<div>   at Microsoft.Scripting.Generation.CompilerHelpers.CompileToMethod(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator, Boolean emitDebugSymbols)</div><div>   at Microsoft.Scripting.Generation.CompilerHelpers.CompileToMethod[T](Expression`1 lambda, DebugInfoGenerator debugInfoGenerator, Boolean emitDebugSymbols)</div>
<div>   at Microsoft.Scripting.Generation.CompilerHelpers.Compile[T](Expression`1 lambda, Boolean emitDebugSymbols)</div><div>   at IronPython.Compiler.RuntimeScriptCode.Compile()</div><div>   at IronPython.Compiler.RuntimeScriptCode.EnsureCompiled()</div>
<div>   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)</div><div>   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)</div><div>   at IronPython.Runtime.PythonContext.InitializeModule(String fileName, ModuleContext moduleContext, ScriptCode scriptCode, ModuleOptions options)</div>
<div>   at IronPython.Runtime.PythonContext.CompileModule(String fileName, String moduleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode&amp; scriptCode)</div><div>   at IronPython.Runtime.PythonContext.CompileModule(String fileName, String moduleName, SourceUnit sourceCode, ModuleOptions options)</div>
<div>   at IronPython.Runtime.Importer.LoadFromSourceUnit(CodeContext context, SourceUnit sourceCode, String name, String path)</div><div>   at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)</div>
<div>   at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)</div><div>   at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)</div>
<div>   at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)</div><div>   at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)</div><div>
   at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)</div><div>   at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)</div>
<div>   at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)</div><div>   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)</div><div>   at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)</div>
<div>   at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)</div><div>   at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)</div>
<div>   at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)</div><div>   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)</div><div>   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)</div>
<div>   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)</div><div>   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)</div><div>   at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope)</div>
<div>   at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope)</div><div>   at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink)</div><div>   at Microsoft.Scripting.SourceUnit.Execute(Scope scope)</div>
<div>   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)</div><div>   at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)</div><div>   at Microsoft.Scripting.Hosting.ScriptEngine.Execute(String expression, ScriptScope scope)</div>
<div>   at Elipse.Epm.Scripting.ExpressionEvaluator.ImportStandardModules(ScriptScope scope) in D:\proj\epm_5527\Source\EpmCommon\Elipse.Epm.Scripting\ExpressionEvaluator.cs:line 174</div><div>   at Elipse.Epm.Scripting.ExpressionEvaluator.AddExpression(Expression expression, Object clientHandle) in D:\proj\epm_5527\Source\EpmCommon\Elipse.Epm.Scripting\ExpressionEvaluator.cs:line 82</div>
</div><div><br></div><div><br><br><div class="gmail_quote">On Mon, Mar 5, 2012 at 3:18 PM, Cesar Mello <span dir="ltr">&lt;<a href="mailto:cmello@gmail.com">cmello@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi!<div><br></div><div>Is there a way to load modules without giving permission to the AppDomain to read .py files from disk?</div><div><br></div><div>I need to run user code with limited permissions. They should be able to do some simple calculations. But when I try to import a module like &#39;decimal&#39;, filesystem access permission is required. </div>

<div><br></div><div>Thank you a lot for the attention!</div><div><br></div><div>Best regards</div><span class="HOEnZb"><font color="#888888"><div>Mello</div>
</font></span></blockquote></div><br></div>