Skip to content

TypeScript SDK

Install

Terminal window
npm install isorun

Authenticate

Terminal window
export ISORUN_API_KEY="isorun_live_<region>_<id>_<hmac>"
export ISORUN_API_URL="https://api.isorun.ai" # optional

Quickstart

import { Sandbox } from 'isorun'
const sb = await Sandbox.create('python')
try {
const result = await sb.exec("python3 -c 'print(42)'")
console.log(result.stdout.trim())
} finally {
await sb.close()
}

Core patterns

exec()

const result = await sb.exec('pytest -q', { timeout: 180 })
if (result.exitCode !== 0) {
console.error(result.stderr)
}

execStream()

const result = await sb.execStream('python3 train.py', {
timeout: 600,
onStdout: (chunk) => process.stdout.write(chunk),
onStderr: (chunk) => process.stderr.write(chunk),
})
console.log(result.exitCode)

run()

const version = await sb.run('python3 --version')
console.log(version.trim())

Snapshots, files, URLs

const snapId = await sb.checkpoint()
const restored = await Sandbox.restore(snapId)
await sb.upload('/workspace/input.txt', 'hello\n')
const text = await sb.readFile('/workspace/input.txt')
await sb.exec('python3 -m http.server 8000')
const url = await sb.expose(8000)
console.log(url)
await restored.close()

Lifecycle helpers

import { withSandbox, run } from 'isorun'
await withSandbox('python', async (sandbox) => {
return sandbox.run("python3 -c 'print(6*7)'")
})
const once = await run("python3 -c 'print(42)'")
console.log(once.stdout.trim())

Production checklist

  • Always call close() in finally.
  • Set explicit command timeouts.
  • Use execStream() for long-running commands.
  • Use network allow/deny policy for untrusted code.
  • Log sandbox IDs with request/job IDs.