import { Sandbox } from 'ppio-sandbox/code-interpreter'
const sandbox = await Sandbox.create()
// 您需要传入一个端口号来获取公共 URL。
const host = sandbox.getHost(3000)
console.log(`https://${host}`)
// 输出示例:
// https://3000-icl2ke7w1grxep2o771m1-abf219fd.sandbox.ppio.cn
await sandbox.kill()
import { Sandbox } from 'ppio-sandbox/code-interpreter'
const sandbox = await Sandbox.create()
// 启动一个简单的 HTTP 服务器。
const commandHandle = await sandbox.commands.run('python -m http.server 3000', { background: true })
const host = sandbox.getHost(3000)
const url = `https://${host}`
console.log('Server started at:', url)
// 从服务器获取数据。
const response = await fetch(url);
const data = await response.text();
console.log('Response from server inside sandbox:', data);
// 终止服务器进程。
await commandHandle.kill()
await sandbox.kill()