0

我希望允许用户创建自己的 Python 脚本,在服务器上运行并向用户提供输出。我可能会允许用户在他们的脚本中使用 Selenium,并写入特定文件夹中的文件。我是 Python 新手,但假设存在安全风险。您如何建议我保护服务器免受恶意用户代码的侵害?下面是我目前用来运行 Python 的 C# 代码。

    public static string Run()
    {
        string fileName = @"C:\temp\text.py";

        Process p = new Process();
        p.StartInfo = new ProcessStartInfo(@"python", fileName)
        {
            RedirectStandardOutput = true,
            UseShellExecute = false,
            CreateNoWindow = true
        };
        p.Start();

        string output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();
        return output;
    }
4

0 回答 0