import { Sandbox } from '@e2b/desktop'
// 创建虚拟桌面实例
const desktop = await Sandbox.create()
// 启动桌面流
await desktop.stream.start()
// 获取可交互的 VNC 访问地址
const url = desktop.stream.getUrl()
console.log(url)
// 输出示例:
// 可以通过浏览器打开下面的链接,与虚拟桌面进行交互。您也可以将这个地址集成到应用中。
// https://6080-imy3gjw1i6tjpwysk2e5t-1e67fa95.sandbox.ppio.cn/vnc.html?autoconnect=true&resize=scale
// 获取只读模式的 VNC 访问地址(禁用用户交互)。
const urlDisabledInteraction = desktop.stream.getUrl({ viewOnly: true })
console.log(urlDisabledInteraction)
// 输出示例:
// 可以通过浏览器打开下面的链接,查看虚拟桌面(只读模式)。您也可以将这个地址集成到应用中。
// https://6080-imy3gjw1i6tjpwysk2e5t-1e67fa95.sandbox.ppio.cn/vnc.html?autoconnect=true&view_only=true&resize=scale
// 清理资源
// await desktop.stream.stop() // 停止流
// await desktop.kill() // 销毁沙箱