Hi,<br><br><div class="gmail_quote">On Fri, Nov 6, 2009 at 1:07 AM, Dino Viehland <span dir="ltr">&lt;<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">










<div link="blue" vlink="purple" lang="EN-US">

<div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">So you’ve run this as a standalone program and it’s failing?  In
the standalone app are all of the IronPython and DLR DLLs present
(IronPython.dll, IronPython.modules.dll, Microsoft.Scripting.Core.dll,
Microsoft.Scripting.dll, Microsoft.Dynamic.dll and Micrsoft.Scripting.Extensionattribute.dll)? 
</span></p></div></div></blockquote><div>Yes I have all this dlls present. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div link="blue" vlink="purple" lang="EN-US">
<div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">A slightly modified version of this, dropping the strong name,
works just fine for me:</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using System;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using Microsoft.Scripting;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using Microsoft.Scripting.Hosting;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using IronPython.Hosting;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using System.Security;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">using System.Security.Permissions;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">class Test {</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    public static void Main(string[] args) {</span></p><div class="im">

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        PermissionSet aRestrictedPermissionSet = new
PermissionSet(PermissionState.None);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        aRestrictedPermissionSet.AddPermission(new
SecurityPermission(SecurityPermissionFlag.Execution));</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        AppDomainSetup domaininfo = new AppDomainSetup();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        domaininfo.ApplicationBase =
System.Environment.CurrentDirectory;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

</div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        AppDomain aSandboxedDomain =
AppDomain.CreateDomain(&quot;Sandboxed Domain&quot;,</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">                  AppDomain.CurrentDomain.Evidence,</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">                  domaininfo,</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">                  aRestrictedPermissionSet);</span></p><div class="im">

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        ScriptEngine engine =
Python.CreateEngine(aSandboxedDomain);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        ScriptSource source =
engine.CreateScriptSourceFromString(&quot;2+2&quot;);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        ScriptScope scope = engine.CreateScope();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">        Console.WriteLine(source.Execute(scope));</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">    }</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">}</span></p></div></div></div></blockquote><div><br>Great, I will try this after university. Thanks! <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div><div class="im">

</div><p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Compile with:</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">csc test.cs /r:Microsoft.Scripting.Core.dll
/r:Microsoft.Scripting.dll /r:IronPython.dll</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">And run and it prints 4.  Does that not work for you?</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">We also have a different way we do this in our test suite which
also works:</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            AppDomainSetup info = new AppDomainSetup();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            info.ApplicationBase =
AppDomain.CurrentDomain.BaseDirectory;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            info.ApplicationName = &quot;Test&quot;;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            Evidence evidence = new Evidence();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            evidence.AddHost(new Zone(SecurityZone.Internet));</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            AppDomain newDomain =
AppDomain.CreateDomain(&quot;test&quot;, evidence, info);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            // create runtime in partial trust...</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            ScriptRuntime runtime = Python.CreateRuntime(newDomain);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            // get the Python engine...</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">            ScriptEngine engine =
runtime.GetEngine(&quot;py&quot;);</span></p></div></div></blockquote><div><br>This make sense too, I will try it. Thanks again. <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div link="blue" vlink="purple" lang="EN-US"><div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div style="border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; border-width: medium medium medium 1.5pt; padding: 0in 0in 0in 4pt;">

<div>

<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Nicolás
Buttarelli<br>
<b>Sent:</b> Thursday, November 05, 2009 11:18 AM<div><div></div><div class="h5"><br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Safe execution of python scripts on my .net
application</div></div></span></p>

</div>

</div><div><div></div><div class="h5">

<p class="MsoNormal"> </p>

<div>

<p class="MsoNormal">Again, thanks everyone for your help.</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<p class="MsoNormal">But.. I bring bad news. This is still not working and it
doesn&#39;t depend on the Test environment.</p>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">I create another proyect, a Form project, with one button
which executes the following code:</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<div>

<p class="MsoNormal"> // Creating the permission set to grant other
assemblies</p>

</div>

<div>

<p class="MsoNormal">PermissionSet aRestrictedPermissionSet = new
PermissionSet(PermissionState.None);</p>

</div>

<div>

<p class="MsoNormal">aRestrictedPermissionSet.AddPermission(new
SecurityPermission(SecurityPermissionFlag.Execution));</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">AppDomainSetup domaininfo = new AppDomainSetup();</p>

</div>

<div>

<p class="MsoNormal">domaininfo.ApplicationBase =
System.Environment.CurrentDirectory;</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">List&lt;StrongName&gt; strongNameList = new
List&lt;StrongName&gt;();</p>

</div>

<div>

<p class="MsoNormal">strongNameList.Add(CreateStrongName(Assembly.GetExecutingAssembly()));</p>

</div>

<div>

<p class="MsoNormal">            </p>

</div>

<div>

<p class="MsoNormal">AppDomain aSandboxedDomain =
AppDomain.CreateDomain(&quot;Sandboxed Domain&quot;,</p>

</div>

<div>

<p class="MsoNormal">              
                     
                     
                     
         AppDomain.CurrentDomain.Evidence,</p>

</div>

<div>

<p class="MsoNormal">              
                     
                     
                   
           domaininfo,</p>

</div>

<div>

<p class="MsoNormal">              
                     
                     
                   
           aRestrictedPermissionSet,</p>

</div>

<div>

<p class="MsoNormal">              
                     
                     
                   
           strongNameList.ToArray&lt;StrongName&gt;());</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">ScriptEngine engine = Python.CreateEngine(aSandboxedDomain);</p>

</div>

<div>

<p class="MsoNormal">ScriptSource source =
engine.CreateScriptSourceFromString(pythonScript);</p>

</div>

<div>

<p class="MsoNormal">ScriptScope scope = engine.CreateScope();</p>

</div>

<div>

<p class="MsoNormal">source.Execute(scope);</p>

</div>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">It throws this error:</p>

</div>

<div>

<p class="MsoNormal">Type is not resolved for member
&#39;Microsoft.Scripting.Hosting.ScriptRuntimeSetup,Microsoft.Scripting,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#39;.</p>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">I used the <span><span style="font-size: 11.5pt; color: rgb(31, 73, 125);">fuslogvw </span><span style="color: black;">application to see if the Microsoft.Scripting is loaded, an
it is.</span></span></p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">What seems strange for me is that anyone has tried this
before. I hope to find some more help here.</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">Regards,</p>

</div>

<div>

<p class="MsoNormal">Nicolas</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal"> </p>

<div>

<p class="MsoNormal">On Wed, Nov 4, 2009 at 7:36 PM, Shri Borde &lt;<a href="mailto:Shri.Borde@microsoft.com" target="_blank">Shri.Borde@microsoft.com</a>&gt; wrote:</p>

<div>

<div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"><a href="http://www.dev102.com/2008/03/22/3-ways-to-run-nunit-from-visual-studio/" target="_blank">http://www.dev102.com/2008/03/22/3-ways-to-run-nunit-from-visual-studio/</a>
has some info about test projects and appbase problems.</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">You can also use fuslogvw (<a href="http://msdn.microsoft.com/en-us/library/e74a18c4%28VS.71%29.aspx%29" target="_blank">http://msdn.microsoft.com/en-us/library/e74a18c4(VS.71).aspx)</a>
to see why Microsoft.Scripting.dll is failing to load.</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div>

<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>]
<b>On Behalf Of </b>Dino Viehland<br>
<b>Sent:</b> Tuesday, November 03, 2009 1:52 PM</span></p>

<div>

<div>

<p class="MsoNormal"><br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Safe execution of python scripts on my .net
application</p>

</div>

</div>

</div>

</div>

<div>

<div>

<p class="MsoNormal"> </p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Test projects are weird and somehow you
don’t end up inheriting the application base.  This seems to work though:</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> 
          AppDomainSetup
setup = new AppDomainSetup();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">           
setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">           
AppDomain aSandboxedDomain = AppDomain.CreateDomain(&quot;Sandboxed
Domain&quot;, null, setup);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">           
ScriptEngine engine = Python.CreateEngine(aSandboxedDomain);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">           
ScriptSource source = engine.CreateScriptSourceFromString(&quot;2+2&quot;);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">           
ScriptScope scope = engine.CreateScope();</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">           
Console.WriteLine(source.Execute(scope));</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div style="border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; border-width: medium medium medium 1.5pt; padding: 0in 0in 0in 4pt;">

<div>

<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>]
<b>On Behalf Of </b>Nicolás Buttarelli<br>
<b>Sent:</b> Tuesday, November 03, 2009 1:30 PM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Safe execution of python scripts on my .net
application</span></p>

</div>

</div>

<p class="MsoNormal"> </p>

<p class="MsoNormal">I
have create a new &quot;Test Project&quot; and an Unit Test class in order to
test the following code inside:</p>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<div>

<p class="MsoNormal">AppDomain
aSandboxedDomain = AppDomain.CreateDomain(&quot;Sandboxed Domain&quot;);</p>

</div>

<div>

<p class="MsoNormal">ScriptEngine
engine = Python.CreateEngine(aSandboxedDomain);</p>

</div>

<div>

<p class="MsoNormal">ScriptSource
source = engine.CreateScriptSourceFromString(pythonScript);</p>

</div>

<div>

<p class="MsoNormal">ScriptScope
scope = engine.CreateScope();</p>

</div>

<div>

<p class="MsoNormal">source.Execute(scope);</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<p class="MsoNormal">I
have add the references:</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">-
IronPython</p>

</div>

<div>

<p class="MsoNormal">-
Microsoft.Scripting</p>

</div>

<div>

<p class="MsoNormal">-
Microsoft.ScriptingCore</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">But
it still not working and throwing the
same System.Runtime.Serialization.SerializationException: Type is not
resolved for member &#39;Microsoft.Scripting.Hosting.ScriptRuntimeSetup,Microsoft.Scripting.</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">Any
ideas?</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal"> </p>

<div>

<p class="MsoNormal">2009/11/3
Nicolás Buttarelli &lt;<a href="mailto:nbuttarelli@gmail.com" target="_blank">nbuttarelli@gmail.com</a>&gt;</p>

<p class="MsoNormal">Thanks
Shri, I will try.</p>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">In
addition, I found this open issue: <a href="http://dlr.codeplex.com/WorkItem/View.aspx?WorkItemId=2816" target="_blank">http://dlr.codeplex.com/WorkItem/View.aspx?WorkItemId=2816</a>.
I think that it is related.</p>

<div>

<div>

<p class="MsoNormal" style="margin-bottom: 12pt;"> </p>

<div>

<p class="MsoNormal">On
Tue, Nov 3, 2009 at 9:29 PM, Shri Borde &lt;<a href="mailto:Shri.Borde@microsoft.com" target="_blank">Shri.Borde@microsoft.com</a>&gt;
wrote:</p>

<div>

<div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">I think this happens if the new
appdomain cannot load the required assembly. By default, the new appdomain
should inherit its BaseDirectory property from the creating domain and should
be able to load Microsoft.Scripting.dll. Is your exe and all the dlls in the
same folder? If not, can you try to put all assemblies in the same folder (or
in the GAC) to see if it works? If that works, you can then figure out how to
configure the new appdomain such that it can load Microsoft.Scripting.dll.
There may be some setting in AppDomainSetup, or you could hook the
AssemblyResolve event…</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>]
<b>On Behalf Of </b>Nicolás Buttarelli<br>
<b>Sent:</b> Tuesday, November 03, 2009 12:08 PM</span></p>

<div>

<div>

<p class="MsoNormal"><br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Safe execution of python scripts on my .net
application</p>

</div>

</div>

</div>

<div>

<div>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Hi
again, thanks for your clear response.</p>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">I
was trying to do what you proposed but it is not working. I am
receiving an exception:</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal" style="margin-bottom: 12pt;"><i>Test
method CadworX3WCFRestTest.IronPython.SafeScriptExecutionTest.writingAFileTest
threw exception:  System.Runtime.Serialization.SerializationException:
Type is not resolved for member
&#39;Microsoft.Scripting.Hosting.ScriptRuntimeSetup,Microsoft.Scripting,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#39;..</i></p>

</div>

<div>

<p class="MsoNormal">I
tried to find a solution but I couldn&#39;t. This is the minimal code that I am
running to get this exception (I have removed all the security stuff but
apparently that does not resolve the problem):</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<div>

<p class="MsoNormal"><i>AppDomain
aSandboxedDomain = AppDomain.CreateDomain(&quot;Sandboxed Domain&quot;);</i></p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal"><i>ScriptEngine
engine = Python.CreateEngine(aSandboxedDomain);</i></p>

</div>

<div>

<p class="MsoNormal"><i>ScriptSource
source = engine.CreateScriptSourceFromString(pythonScript);</i></p>

</div>

<div>

<p class="MsoNormal"><i>SriptScope
scope = engine.CreateScope();</i></p>

</div>

<div>

<p class="MsoNormal"><i>source.Execute(scope);</i></p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">The
exception is thronged in this line: </p>

</div>

<div>

<p class="MsoNormal"><i>ScriptEngine
engine = Python.CreateEngine(aSandboxedDomain);</i></p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">Do
you have any idea which could be the problem?</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">Thanks
again,</p>

</div>

<div>

<p class="MsoNormal">Nicolas</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">On
Mon, Nov 2, 2009 at 10:25 PM, Dino Viehland &lt;<a href="mailto:dinov@microsoft.com" target="_blank">dinov@microsoft.com</a>&gt;
wrote:</p>

<div>

<div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">Assuming the app domain is setup
properly then there’s no way for the Python code to elevate permissions (modulo
CLR security bugs which are few and far between).  This is because IronPython
its self is 100% security transparent and does not affect any security
decisions or assert any form of trust – so it’s all up to the CLR to limit
permissions.  So for example while you can access the file object, or
import ctypes, or call various other Python APIs which would require trust
you’ll get a security exception from the CLR when you don’t have permissions to
do something.</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">For more complex scenarios you might
also have an object model which you expose to the application and inject in via
its scope.  Once you’ve done that you’ll want to make sure that the object
model is also secure.</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div style="border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; border-width: medium medium medium 1.5pt; padding: 0in 0in 0in 4pt;">

<div>

<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>]
<b>On Behalf Of </b>Nicolás Buttarelli<br>
<b>Sent:</b> Monday, November 02, 2009 1:20 PM<br>
<b>To:</b> Discussion of IronPython<br>
<b>Subject:</b> Re: [IronPython] Safe execution of python scripts on my .net
application</span></p>

</div>

</div>

<div>

<div>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Thanks
for your response.</p>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">But
what happens with the python code? Does not exist a way to write some
scripts that can do some damage to my app, the server, the database, etc?</p>

</div>

<div>

<p class="MsoNormal"> </p>

</div>

<div>

<p class="MsoNormal">Thanks
again,</p>

</div>

<div>

<p class="MsoNormal">Nicolas</p>

</div>

<div>

<p class="MsoNormal"> </p>

<div>

<p class="MsoNormal">On
Mon, Nov 2, 2009 at 9:41 PM, Dino Viehland &lt;<a href="mailto:dinov@microsoft.com" target="_blank">dinov@microsoft.com</a>&gt;
wrote:</p>

<div>

<div>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">After creating your app domain you can
do:</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">ScriptEngine engine =
Python.CreateEngine(someAppDomain);</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);">And then the rest of your code should work
as it’s written.</span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<p class="MsoNormal"><span style="font-size: 11pt; color: rgb(31, 73, 125);"> </span></p>

<div style="border-style: none none none solid; border-color: -moz-use-text-color -moz-use-text-color -moz-use-text-color blue; border-width: medium medium medium 1.5pt; padding: 0in 0in 0in 4pt;">

<div>

<div style="border-style: solid none none; border-color: rgb(181, 196, 223) -moz-use-text-color -moz-use-text-color; border-width: 1pt medium medium; padding: 3pt 0in 0in;">

<p class="MsoNormal"><b><span style="font-size: 10pt;">From:</span></b><span style="font-size: 10pt;"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>
[mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>]
<b>On Behalf Of </b>Nicolás Buttarelli<br>
<b>Sent:</b> Monday, November 02, 2009 12:39 PM<br>
<b>To:</b> <a href="mailto:users@lists.ironpython.com" target="_blank">users@lists.ironpython.com</a><br>
<b>Subject:</b> [IronPython] Safe execution of python scripts on my .net
application</span></p>

</div>

</div>

<div>

<div>

<p class="MsoNormal"> </p>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">Sorry, I don&#39;t know if my previous message have
arrived. So, here it is:</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<p class="MsoNormal"><span style="font-size: 10pt;">Hello all,</span></p>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">I am starting with python and I would like to add to
my web application some web services. This services will allow the different clients
of my application to execute some python scripts. </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">I would like to know if someone did this before and
how can I do this in a secure way. I mean, how can I do to restrict the
environment where the scripts will be executed. </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">In .net I can do this using the AppDoman and setting
the permission set.</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);">AppDomain.CreateDomain( </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">string</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);"> friendlyName,<br>

                        Evidence
securityInfo,<br>
                        AppDomainSetup
info,<br>
                        PermissionSet
grantSet,<br>
                        </span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">params</span><span style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: rgb(51, 51, 51);"> StrongName[]
fullTrustAssemblies);</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">Is there a way to do the same with my python
scripts? </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">I am running them using this:</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">ScriptEngine engine = Python.CreateEngine();</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">ScriptSource source = engine.CreateScriptSourceFromString(scriptAsString);</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">ScriptScope scope = engine.CreateScope();</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">source.Execute(scope);</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;"> </span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">Thanks in advance.</span></p>

</div>

<div>

<p class="MsoNormal"><span style="font-size: 10pt;">Nicolas</span></p>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>

</div>

<p class="MsoNormal"> </p>

</div>

</div>

</div>

</div>

</div>

</div>

<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>

</div>

<p class="MsoNormal"> </p>

</div>

</div>

</div>

</div>

</div>

<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>

</div>

<p class="MsoNormal"> </p>

</div>

</div>

</div>

</div>

<p class="MsoNormal"> </p>

</div>

</div>

</div>

</div>

</div>

</div>

<p class="MsoNormal" style="margin-bottom: 12pt;"><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a></p>

</div>

<p class="MsoNormal"> </p>

</div>

</div>

</div></div></div>

</div>

</div>


<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br>