@architect/sandbox

中文文档
9.0.0发布于 2025/11/28Apache-2.0CommonJS近 30 天下载 1.6万

Architect dev server: run full Architect projects locally & offline

原始使用文档
文档目录16 节
  1. @architect/sandbox
  2. Install
  3. CLI
  4. Start the sandbox
  5. CLI options
  6. Environment variables
  7. API
  8. Sandbox
  9. sandbox.start(options[, callback]) → [Promise]
  10. sandbox.end([callback]) → [Promise]
  11. Example
  12. Tape
  13. Jest
  14. Development
  15. Requirements
  16. Running Tests

@architect/sandbox

Architect local development environment: run full Architect projects locally & offline in an in-memory sandbox

GitHub CI status

Install

npm i @architect/sandbox

CLI

Start the sandbox

npx sandbox

Or if running Sandbox from within @architect/architect:

npx arc sandbox

CLI options

  • -p, --port - Manually specify HTTP port
    • Defaults to 3333
  • -h, --host - Specify the host interface for Sandbox to listen on
    • Defaults to 0.0.0.0 (all available interfaces on your machine)
    • To accept local connections only, specify localhost
  • -v, --verbose - Enable verbose logging
  • -d, --debug - Enable debug logging
  • -q, --quiet - Disable (most) logging
  • --disable-delete-vendor - Disable deleting Lambda vendor dirs upon startup
  • --disable-symlinks - Disable symlinking src/shared into all functions and use file copying instead

Environment variables

  • ARC_API_TYPE - Set the API Gateway API type
    • Can be one of http (aliased to httpv2), httpv1, rest
    • Defaults to http
  • ARC_ENV - testing|staging|production
    • Defaults to testing
  • ARC_HOST - Specify the host interface for Sandbox to listen on
    • Defaults to 0.0.0.0 (all available interfaces on your machine)
    • To accept local connections only, specify localhost
  • ARC_LOCAL- If present and used in conjunction with ARC_ENV=staging|production, emulates live staging or production environment
    • Uses your local preferences @env environment variables for the appropriate stage
    • Connects Sandbox to live AWS events and DynamoDB infrastructure
    • Requires valid AWS credentials with the same profile name as defined in your project manifest
  • Specify ports:
    • ARC_PORT - Manually specify HTTP port
      • Defaults to 3333
    • ARC_EVENTS_PORT- Manually specify event bus port
      • Defaults to 4444
    • ARC_TABLES_PORT- Manually specify local DynamoDB port
      • Defaults to 5555
    • ARC_INTERNAL_PORT- Manually specify internal Sandbox + AWS services port
      • Defaults to 2222
  • ARC_DB_EXTERNAL - (Boolean) Use an external DynamoDB tool (such as AWS NoSQL Workbench)
  • ARC_QUIET - If present, disable (most) logging

API

Sandbox is designed to be integrated into your application's test suite. In most cases you'll only need to make use of sandbox.start() and sandbox.end(). However, individual Sandbox services can also be individually started and stopped. (See below.)

Methods may be passed an options object containing the following parameters:

  • apigateway - String - Specify the API Gateway API type
    • Defaults to http
    • Can be one of http (aliased to httpv2), httpv1, rest
  • cwd - String - Specify a working directory (handy for aiming Sandbox at test mocks)
  • deleteVendor - Boolean - Delete Lambda vendor dirs upon startup
    • Defaults to true
  • env - Object - Environment variables for Lambda invocations in automated testing
    • String values overwrite env vars of the same name set via .env or prefs.arc files
    • undefined values delete any env vars of the same name set via .env or prefs.arc files
  • port - String or Number - Specify HTTP port
    • Defaults to 3333
  • quiet - Boolean - Disables (most) logging
  • runStartupCommands - Boolean - Disable @sandbox-start commands
    • Defaults to true
  • runtimeCheck - String - Check for runtime version mismatches
    • If set to warn Sandbox will warn of mismatches in stdout
    • If set to error (suggested for test environments) Sandbox will fail to start up
    • Does not run by default
  • symlink - Boolean - Use symlinking to Architect shared code from within each Lambda's dependencies (e.g. src/http/get-index/node_modules/@architect/shared → src/shared)
    • Defaults to true
    • false copies shared code into each Lambda, which can result much slower startup and dependency rehydration speeds
  • watcher - Boolean - Disable the Sandbox file watcher (and related Sandbox file watcher plugin API)
    • Defaults to true

Sandbox

Start and shut down the Sandbox; unless you have specific per-service needs, we generally advise most folks use this interface for testing

sandbox.start(options[, callback]) → [Promise]

Starts the Sandbox; first checks that ports are available to consume, prints a banner, loads Architect and userland environment variables, hydrates application dependencies, and starts various Sandbox services (including @events, @queues, @tables, @indexes, @http, @static and @ws).

Invokes callback once everything is ready, or returns a promise if callback is falsy.

sandbox.end([callback]) → [Promise]

Shuts down anything started by sandbox.start(). Invokes callback once shut down, or returns a promise if callback is falsy.


Example

Tape

let sandbox = require('@architect/sandbox')
let test = require('tape')

test('Start the Sandbox', async t => {
  t.plan(1)
  let result = await sandbox.start()
  t.equal(result, 'Sandbox successfully started')
})

test('Tests go here', t => {
  // Make use of various Sandbox resources in your tests...
})

test('Shut down the Sandbox', async t => {
  t.plan(1)
  let result = await sandbox.end()
  t.equal(result, 'Sandbox successfully shut down')
})

Jest

let sandbox = require('@architect/sandbox')

beforeAll(async () => {
  let result = await sandbox.start()
  expect(result).toBe('Sandbox successfully started')
})

afterAll(async () => {
  let result = await sandbox.end()
  expect(result).toBe('Sandbox successfully shut down')
})

test('Tests go here', () => {
  // Make use of various Sandbox resources in your tests...
})

Development

Requirements

The tests in this repository require that you have the deno runtime installed on your local machine. Install deno by visiting: https://deno.land/#installation

Running Tests

To work on sandbox, first make sure you have installed the dependencies:

npm install

To run all tests, including the linter:

npm test

To run just the linter:

npm run lint

To run just the unit tests (which are located under test/unit):

npm run test:unit

To get a code coverage report based on unit test execution:

npm run coverage

To run just the integration tests (which are located under `test/integration'):

npm run test:integration

To make tests run extra noisy-like, add the NOISY_TESTS=true env var

版本与发布记录

@architect/sandbox 共发布 331 个版本,首次发布于 2019/05/30;过去 12 个月发布了 3 个版本。

版本发布日期距今
9.0.0latest2025/11/2811 个月前
9.0.0-RC.0RC2025/11/2611 个月前
8.0.02025/11/1811 个月前
8.0.0-RC.22025/09/261.1 年前
8.0.0-RC.12025/09/251.1 年前
8.0.0-RC.02025/09/201.1 年前

关于 @architect/sandbox 的常见问题

@architect/sandbox 是什么?

Architect dev server: run full Architect projects locally & offline

如何安装 @architect/sandbox?

在项目目录运行 npm install @architect/sandbox,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 sandbox、arc-sandbox,可以用 npx sandbox 直接运行。

@architect/sandbox 支持 TypeScript 吗?

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

@architect/sandbox 支持 ESM 还是 CommonJS?

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

@architect/sandbox 需要什么版本的 Node.js?

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

@architect/sandbox 可以商用吗?

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

@architect/sandbox 的下载量有多少?

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

@architect/sandbox 还在维护吗?

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