.net new process sandbox for untrusted code

亡梦爱人 提交于 2019-12-09 13:38:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6161678/net-new-process-sandbox-for-untrusted-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!