title: Sandboxed ironpython in c# SecurityException
body: <p>Alright so this is what I have</p>
  
  <pre><code>private static AppDomain CreateSandbox()
  {
    var permissions = new PermissionSet(PermissionState.None);
    permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution));
  
    permissions.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read| FileIOPermissionAccess.PathDiscovery, AppDomain.CurrentDomain.BaseDirectory));
    var appinfo = new AppDomainSetup();
    appinfo.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
  
    return AppDomain.CreateDomain("Scripting sandbox", null, appinfo, permissions, fullTrustAssembly);
  }
  </code></pre>
  
  <p>And when I try to load up some broken python code</p>
  
  <pre><code>try
  {
      var src = engine.CreateScriptSourceFromString(s.Python, SourceCodeKind.Statements);
      src.Execute(ActionsScope);
  }
  catch (Exception e)
  {
      ExceptionOperations eo = engine.GetService&lt;ExceptionOperations&gt;();
      string error = eo.FormatException(e);
      Debug.WriteLine(error);
  }
  </code></pre>
  
  <p>This gives me a <code>SecurityException</code> instead of letting me see the actual exception from the code.
  If I set the <code>PermissionSet(PermissionState.Unrestricted)</code> it works fine.</p>
  
  <p>Any ideas on what permissions I need in order to catch these blasted errors?</p>
  
  <pre class="lang-none prettyprint-override"><code>System.Security.SecurityException was caught
    Message=Request failed.
    Source=Microsoft.Scripting
    GrantedSet=&lt;PermissionSet class="System.Security.PermissionSet"
  version="1"&gt;
  &lt;IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
  version="1"
  Read="F:\Programming\OCTGN\octgnFX\Octgn\bin\ReleaseMode with Debug\"
  PathDiscovery="F:\Programming\OCTGN\octgnFX\Octgn\bin\ReleaseMode with Debug\"/&gt;
  &lt;IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
  version="1"
  Flags="Execution"/&gt;
  &lt;/PermissionSet&gt;
  
    PermissionState=&lt;PermissionSet class="System.Security.PermissionSet"
  version="1"
  Unrestricted="true"/&gt;
  
    RefusedSet=""
    Url=file:///F:/Programming/OCTGN/octgnFX/Octgn/bin/ReleaseMode with Debug/Microsoft.Scripting.DLL
    StackTrace:
         at Microsoft.Scripting.SyntaxErrorException.GetObjectData(SerializationInfo info, StreamingContext context)
         at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String&amp; typeName, String&amp; assemName, String[]&amp; fieldNames, Object[]&amp; fieldValues)
         at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
         at Octgn.Scripting.Engine.LoadScripts() in F:\Programming\OCTGN\octgnFX\Octgn\Scripting\Engine.cs:line 58
    InnerException: 
  </code></pre>