如需在沙箱中運行 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}`);