How to make a piece of managed code execute in a security restricted environment, or how to "sandbox" it

Ivan Medvedev gives a nice detailed answer on https://www.dotnetthis.com/Articles/DynamicSandboxing.htm

(Check his blog !)