如需在沙箱中运行 Web 服务等常驻进程,可以在创建沙箱后通过后台命令启动。
Python 示例:
server = sandbox.commands.run(
"python3 -m http.server 8000",
background=True,
)
host = sandbox.get_host(8000)
print(f"https://{host}")TypeScript 示例:
const server = await sandbox.commands.run("python3 -m http.server 8000", {
background: true,
});
const host = sandbox.getHost(8000);
console.log(`https://${host}`);该文章对您有帮助吗?