Skip to content

feat: support for agent sandboxes#226

Draft
MichaelGoberling wants to merge 13 commits intomasterfrom
agent-sandboxes
Draft

feat: support for agent sandboxes#226
MichaelGoberling wants to merge 13 commits intomasterfrom
agent-sandboxes

Conversation

@MichaelGoberling
Copy link
Copy Markdown
Contributor

@MichaelGoberling MichaelGoberling commented Mar 19, 2026

npm install github:adobe/aio-lib-runtime#agent-sandboxes
const { init } = require('@adobe/aio-lib-runtime')

async function main () {
  const runtime = await init({
    apihost: "http://localhost",
    namespace: "test_namespace",
    api_key: "test_key"
  })

  const sandbox = await runtime.compute.sandbox.create({
    region: 'us-east-1',
    name: 'my-sandbox',
    size: 'MEDIUM',
    type: 'cpu:nodejs',
    workspace: 'workspace',
    maxLifetime: 3600,
    envs: {
      API_KEY: 'your-api-key'
    }
  })

  console.log('sandbox ready:', sandbox.id)

  const status = await runtime.compute.sandbox.getStatus(sandbox.id)
  console.log('status:', status)

  console.log('executing command...')
  const result = await sandbox.exec('ls -al', { timeout: 10000 })
  console.log('stdout:', result.stdout.trim())
  console.log('exit code:', result.exitCode)

  // write a file using the file API instead of echo-redirects
  console.log('writing file via writeFile...')
  const script = `console.log('hello from sandbox script', process.version)\n`
  const writeResult = await sandbox.writeFile('hello.js', script)
  console.log('writeFile result:', writeResult)

  // read it back to confirm
  console.log('reading file back via readFile...')
  const content = await sandbox.readFile('hello.js')
  console.log('readFile content:', content.trim())

  // list the directory
  console.log('listing /workspace via listFiles...')
  const entries = await sandbox.listFiles('.')
  console.log('listFiles entries:', entries)

  // run the script
  console.log('running the script...')
  const result4 = await sandbox.exec('node hello.js', { timeout: 10000 })
  console.log('stdout:', result4.stdout.trim())
  console.log('stderr:', result4.stderr.trim())
  console.log('exit code:', result4.exitCode)

  await sandbox.destroy()
  console.log('sandbox destroyed')
}

main().catch(err => { console.error(err); process.exit(1) })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant