@adobe/aio-lib-sandbox

中文文档
0.1.0-alpha.12发布于 2026/09/04Apache-2.0CommonJS近 30 天下载 1.4万

JavaScript SDK for Adobe Runtime Sandboxes

原始使用文档
文档目录16 节
  1. Pre-requisites
  2. Install
  3. Quickstart
  4. Configuration
  5. Usage
  6. Create Sandbox
  7. Get Status
  8. Exec
  9. Detached Commands
  10. File Management
  11. Exec a File
  12. Write to Stdin
  13. Destroy
  14. Preview URLs
  15. Network Policies
  16. Development

App Builder Sandbox SDK

Version Downloads/week Node.js CI License Codecov Coverage

JavaScript SDK for Adobe Runtime Sandboxes.

A sandbox is an ephemeral, isolated compute environment. You create one, run commands and read/write files inside it over a WebSocket session, then destroy it.

Pre-requisites

To use this library, you must have Sandboxes enabled for your Runtime namespace. Please contact Michael Goberling ([email protected]) or Cosmin Stanciu ([email protected]) to request this.

Install

npm install @adobe/aio-lib-sandbox

Quickstart

Inside a Runtime action, no configuration is needed to use the SDK as credentials are read automatically from the environment.

const { Sandbox } = require('@adobe/aio-lib-sandbox')

async function main (params) {
  const sandbox = await Sandbox.create({ name: 'my-sandbox' })

  const { stdout } = await sandbox.exec('node --version', { timeout: 10_000 })

  await sandbox.destroy()
  return { stdout: stdout.trim() }
}

exports.main = main

Configuration

When running inside a Runtime action, the SDK reads credentials from the environment automatically:

VariableDescription
__OW_API_HOSTRuntime API host
__OW_NAMESPACERuntime namespace
__OW_API_KEYRuntime API key (basic auth)

You can override any of these by passing them explicitly to Sandbox.create() or Sandbox.get():

const sandbox = await Sandbox.create({
  apiHost:   'https://adobeioruntime.net',
  namespace: 'my-namespace',
  auth:    'my-api-key',
  name:      'my-sandbox'
})

Usage

Create Sandbox

const { Sandbox } = require('@adobe/aio-lib-sandbox')

const sandbox = await Sandbox.create({
  name:        'my-sandbox',
  region:      'va6',
  type:        'cpu:default',
  idleTimeout: 900,
  maxLifetime: 3600,
  ports:       [3000, 8080],
  envs:        { API_KEY: 'your-api-key' }
})

The canonical sandbox API host is latency-routed and can send a request to a cluster outside the region named in the request body. When region is set, the SDK therefore routes the canonical host directly to that regional endpoint. Region identifiers use two to four letters followed by one or two digits and are normalized to lowercase. Custom and already-regional apiHost values are left unchanged. Omitting region preserves the default latency-routed API host behavior.

Sandbox lifetime model

A sandbox is always deleted when maxLifetime has elapsed. It will also be deleted after the idleTimeout has elapsed, if there has been no activity.

To keep a sandbox alive, send at least one command or check the status every idleTimeout seconds.

Get Status

const sandbox = await Sandbox.get(sandbox.id)
console.log('status:', sandbox.status)

Exec

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

Note: Commands run in the /workspace directory by default, this is not configurable

Detached Commands

Pass detached: true to run a long-lived background process.

// Start a background server
const command = await sandbox.exec('node server.js', { detached: true })

// Wait for it to exit (e.g. after you stop it)
const result = await command.wait()
console.log('exit code:', result.exitCode)

// Send a signal to stop it
await command.kill()

If the process is still running and you need a handle to it from a different context, use getCommand() to re-attach by execId:

const command = await sandbox.getCommand(execId, { onOutput: (data, stream) => process.stdout.write(data) })
await command.wait()

Note: Only 5 background processes are allowed to run at once currently.

File Management

const script = "console.log('hello from sandbox script', process.version)\n"
await sandbox.writeFile('hello.js', script)

const content = await sandbox.readFile('hello.js')
console.log('readFile content:', content.trim())

const entries = await sandbox.listFiles('.')
console.log('listFiles entries:', entries)

Exec a File

const result = await sandbox.exec('node hello.js', { timeout: 10_000 })
console.log('stdout:', result.stdout.trim())
console.log('stderr:', result.stderr.trim())
console.log('exit code:', result.exitCode)

Write to Stdin

Command start

const result = await sandbox.exec('node process_csv.js', {
  stdin: 'col1,col2\nval1,val2\n',
  timeout: 10_000
})
console.log('stdout:', result.stdout.trim())

Running command

const task = sandbox.exec('cat -n', { timeout: 10_000 })

sandbox.writeStdin(task.execId, 'line 1\n')
sandbox.writeStdin(task.execId, 'line 2\n')
sandbox.closeStdin(task.execId)

const result = await task
console.log('stdout:', result.stdout.trim())

Destroy

await sandbox.destroy()

Preview URLs

Ports that should be publicly accessible must be declared at creation time via the ports array.

const sandbox = await Sandbox.create({
  name:  'web-sandbox',
  ports: [3000, 8080]
})

// Start a server inside the sandbox on the declared port
await sandbox.exec('node server.js &', { timeout: 50_000 })

// Retrieve the pre-provisioned preview URL — synchronous, no network call
const url = sandbox.getUrl(3000)
console.log('preview:', url)
// https://sb-abc123-va6-0-xK3mPq2nAeB-3000.sandbox-adobeioruntime.net

Network Policies

Sandboxes are default-deny. All outbound traffic is blocked unless explicitly allowed.

Pass a policy.network.egress array at creation time to allowlist outbound endpoints, paths, or HTTP verbs.

const sandbox = await Sandbox.create({
  name:        'policy-sandbox',
  maxLifetime: 300,
  policy: {
    network: {
      egress: [
        { host: 'httpbin.org', port: 443 },
        {
          host: 'api.github.com',
          port: 443,
          rules: [
            { methods: ['GET'], pathPattern: '/repos/**' }
          ]
        }
      ]
    }
  }
})

Development

Install development dependencies:

npm install

To run the same checks used by CI:

npm test

Linting is powered by ESLint:

npm run lint
npm run lint-fix

版本与发布记录

@adobe/aio-lib-sandbox 共发布 10 个版本,首次发布于 2026/05/28;过去 12 个月发布了 10 个版本。

版本发布日期距今
0.1.0-alpha.12latest2026/09/042 个月前
0.1.0-alpha.112026/07/303 个月前
0.1.0-alpha.102026/07/303 个月前
0.1.0-alpha.92026/06/234 个月前
0.1.0-alpha.82026/06/114 个月前
0.1.0-alpha.72026/06/055 个月前

关于 @adobe/aio-lib-sandbox 的常见问题

@adobe/aio-lib-sandbox 是什么?

JavaScript SDK for Adobe Runtime Sandboxes

如何安装 @adobe/aio-lib-sandbox?

在项目目录运行 npm install @adobe/aio-lib-sandbox,或使用 pnpm add / yarn add / bun add。

@adobe/aio-lib-sandbox 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adobe__aio-lib-sandbox 是否存在。

@adobe/aio-lib-sandbox 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@adobe/aio-lib-sandbox 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@adobe/aio-lib-sandbox 可以商用吗?

@adobe/aio-lib-sandbox 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/aio-lib-sandbox 的下载量有多少?

根据 npm 官方下载统计,@adobe/aio-lib-sandbox 在 2026/10/05 – 2026/11/03 这 30 天内被下载 14,071 次,日均约 469 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/aio-lib-sandbox 还在维护吗?

最新版本 0.1.0-alpha.12 发布于 2026/09/04(2 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/05/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。