title: Running processes using the Process class of C# in a safe and restricted manner
body: <p>I have a WCF service that executes a <strong>.NET exe</strong> file or a <strong>JAVA .class</strong> file by using the <strong>Process</strong> class available in C#.</p>
  
  <p><strong><em>Sample code that executes a class file by starting a new process:</em></strong></p>
  
  <pre><code> public bool Run(string classFilePath, string[] commandLineParameters)
      {
          var process = new Process { StartInfo = this.GetProcessStartInfoForExecution(classFilePath) };
  
          try
          {
              process.Start();
              process.WaitForExit();
          }
          catch(Exception e)
          {
              throw new Exception("Process start caused an exception");
          }
  
          if (process.ExitCode != 0)
          {
              this.WriteErrorToFile(classFilePath, process.StandardError.ReadToEnd());
  
              return false;
          }
  
          return true;
      }
  </code></pre>
  
  <p>I have read that <strong>AppDomain</strong> class can be used to sandbox and run assemblies in a safe environment, with the problem being that it can only be used for managed code.</p>
  
  <p>So, my question is, is there a way to run processes from C# in a safe and restricted manner not just for .net assemblies, but for any process started using the Process class.</p>
  
  <p>By safe and restricted, I mean restricting accesses to files, resources and preventing the execution of any malicious code.</p>
  
  <p>Thanks-</p>