.net 新进程沙箱用于不受信任的代码
所以我需要在新进程中运行动态编译的不受信任的代码。我找到了如何在新的 AppDomain (http://msdn.microsoft.com/en-us/library/bb763046.aspx) 中执行此操作,但没有在新进程中执行此操作。可以做吗?
我需要新进程的原因是因为它更容易捕获标准输出、查看内存和 CPU 消耗并终止它。
最终目标是编写在线 C# 编译器。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AppDomain 是一种隔离系统中 .NET 代码的方法。进程是操作系统的一种隔离机制。在某种程度上,您将放弃 .NET 代码的优点,并且必须手动管理进程之间的数据传输。
查看 Process 类。听起来您要么需要将代码编译为 .exe,要么在 .NET 中创建一个主机 .exe 来加载您的代码。后者似乎更好,因为您只需编写一次主机,然后编写与该主机的标准通信代码。
您没有提供有关最终目标的大量信息,但 .NET 的最新版本提供了各种 插件 API 可能值得快速浏览一下。
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.