9

I'm using this guide to create a scripting platform inside my program.

I'd like to sandbox what they are allowed to do and what not.

I have a few namespaces that I'd like to only allow the code from using it and pretty much disallow everything else.

The assembly compiled from the custom code at runtime is linked to the main program via code I found:

foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
    try
    {
        string location = assembly.Location;
        if (!String.IsNullOrEmpty(location))
        {
            parameters.ReferencedAssemblies.Add(location);
        }
    }
    catch (NotSupportedException)
    {
        // this happens for dynamic assemblies, so just ignore it. 
    }
}

So that the mods (dynamically generated code at runtime) can communicate with the main program.

With my limited knowledge and research it seems like I need to create a custom AppDomain and use PermissionSet, but I'm not sure how I can achieve this.

Alex
  • 790
  • 7
  • 20
user6516781
  • 177
  • 6
  • 1
    If you wait a bit you might be able to use the Roslyn compiler with Unity once it supports netstandard 2.0 – Scott Chamberlain May 14 '17 at 21:27
  • 1
    Suggest you take a look at this similar issue [C# Loading Sanboxed Assembly](http://stackoverflow.com/questions/8691363/c-sharp-load-sandboxed-assembly) – TomServo May 14 '17 at 21:42
  • @JLH It looks like CSScript requires a version of Microsoft.CodeAnalysist, but none of them seems to be working after even installing the DLLs the plugins folder. Any ideas? – user6516781 May 15 '17 at 04:54

0 Answers0