Search code examples
c#.netprocesssandbox

.net new process sandbox for untrusted code


So I need to run dynamically compiled untrusted code in a new process. I found how to do that in a new AppDomain (http://msdn.microsoft.com/en-us/library/bb763046.aspx) but not new process. Is it possible to do?

The reason I need new process is because it is easier to capture standard output, see memory and cpu consumption and terminate it.

The end goal is to write online C# compiler.


Solution

  • AppDomains are a way to isolate .NET code in a system. Processes are an operating system mechanism for isolation. To some degree you will give up the niceties of .NET code and have to manually manage the transfer of data between processes.

    Check out the Process class. It sounds like you either need to compile your code to a .exe, or create a host .exe in .NET that loads your code. The latter seems better as you can just write the host once and then write standard communication code with that host.

    You don't provide a lot of information on your end goals but recent versions of .NET provide various plug-in APIs that might be worth a quick look.