# near-sandbox

> CLI tool for testing NEAR smart contracts

Latest version **0.3.4** (published 2026-09-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install near-sandbox
pnpm add near-sandbox
yarn add near-sandbox
bun add near-sandbox
```

Provides the commands `sandbox`, `near-sandbox`.

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.3.4 |
| Published | 2026-09-04 |
| First published | 2021-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22.22.2 |
| Dependencies | 5 |
| Unpacked size | 181.7 KB |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2 |
| Author | Near Inc |
| Maintainers | frol, sirwillem, chaotictempest |

## Links

- npm: https://www.npmjs.com/package/near-sandbox
- Repository: https://github.com/near/near-sandbox-js
- Homepage: https://github.com/near/near-sandbox-js#readme
- Issues: https://github.com/near/near-sandbox-js/issues
- npm.io page: https://npm.io/package/near-sandbox

## Dependencies (5)

- [got](https://npm.io/package/got.md) ^11.8.6
- [tar](https://npm.io/package/tar.md) 7.5.13
- [tmp-promise](https://npm.io/package/tmp-promise.md) ^3.0.3
- [proper-lockfile](https://npm.io/package/proper-lockfile.md) ^4.1.2
- [json-merge-patch](https://npm.io/package/json-merge-patch.md) ^1.0.2

## Recent versions

- 0.3.4 (latest) — 2026-09-04
- 0.3.3 — 2026-08-11
- 0.3.2 — 2026-07-29
- 0.3.1 — 2026-07-21
- 0.3.0 — 2026-05-01
- 0.2.1 — 2025-11-30
- 0.2.0 — 2025-08-21
- 0.1.5 — 2025-05-12
- 0.1.4 — 2025-03-14
- 0.1.3 — 2024-12-17
- 0.1.2 — 2024-11-15
- 0.1.1 — 2024-09-24
- 0.1.0 — 2024-09-04
- 0.0.21 — 2024-08-22
- 0.0.20 — 2024-08-15
- … 23 more at https://npm.io/package/near-sandbox/versions

## README

<div align="center">

  <h1>NEAR Sandbox (JS and TS Edition)</h1>

  <p>
    <strong>JavaScript and TypeScript library for running a local NEAR node for development and testing.</strong>
  </p>

  <p>
     <a href="https://npmjs.com/near-sandbox"><img src="https://img.shields.io/npm/v/near-sandbox.svg?style=flat-square" alt="Latest Release Version" /></a>
    <a href="https://npmjs.com/near-sandbox"><img src="https://img.shields.io/npm/d/near-sandbox.svg?style=flat-square" alt="Download" /></a>
  </p>
</div>

## Release Notes

Release notes and unreleased changes can be found in the [CHANGELOG](./CHANGELOG.md).

## What is NEAR Sandbox?

NEAR Sandbox is a [custom build](https://github.com/near/nearcore/blob/9f5e20b29f1a15a00fc50d6051b3b44bb6db60b6/Makefile#L67-L69) of the NEAR blockchain optimized for local development and testing.  
If you're familiar with [Ganache for Ethereum](https://www.trufflesuite.com/ganache), this tool serves a similar purpose for NEAR.

This library provides a simple JavaScript API to quickly download, start, and configure your local NEAR Sandbox instance. The binary is automatically managed and launched for you.

## Installation

Install the package globally or as a development dependency:

Using npm:

```bash
pnpm install --save-dev near-sandbox
```

## Simple Testing Example

Here's an example of how you might use NEAR Sandbox in a test with async/await:

```javascript
const { Sandbox } = require("near-sandbox");

(async () => {
  // Start a sandbox instance with default configuration.
  const sandbox = await Sandbox.start({});
  try {
    // Your test code here.
    // You can interact with the sandbox via its RPC `sandbox.rpc` etc.
    console.log(`Sandbox RPC available at: ${sandbox.rpcUrl}`);
  } catch (error) {
    console.error("Error during execution:", error);
  } finally {
    // Stop the sandbox and clean up any files that were created. Note, if you want to persist the sandbox network state and just stop the node, use `stop()` method.
    await sandbox.tearDown();
  }
})();
```

You can find more and detailed examples in [examples](examples/)

## Features

- **Easy sandbox startup:** Start a local NEAR node with Sandbox.start({}).
- **Version selection:** Download and run a specific NEAR Sandbox version.
- **Custom configuration:** Adjust settings such as genesis parameters or network configurations. Add your own accounts as TLA to node.
- **Automatic binary management:** Automatically downloads and manages the NEAR Sandbox binary if not already present.
- **RPC access:** Access the sandbox node's RPC endpoint for interacting with your local network.
- **Environment variable configuration:** Customize binary source, timeouts, and more through environment variables.
- **Dumping:** dump() the entire chain that return all config files(genesis, config, node_key, validator_key as Records). Genesis and key files can be used to start sandbox as params to run prepared state.

### Starting a Sandbox

You can start a sandbox with default settings:

```javascript
const { Sandbox } = require("near-sandbox");

(async () => {
  const sandbox = await Sandbox.start({});
  // Use sandbox.rpc to interact with the local NEAR node.
  await sandbox.tearDown();
})();
```

Or, you can specify a particular version:

```javascript
const { Sandbox } = require("near-sandbox");

(async () => {
  const sandbox = await Sandbox.start({ version: "2.6.3" });
  // Use `sandbox.rpc` for your further interactions.
  await sandbox.tearDown();
})();
```

Or configure the sandbox with custom settings:

```javascript
const { Sandbox } = require("near-sandbox");

(async () => {
  // Define your custom configuration here with interface `SandboxConfig`
  const config = {
    rpcPort: rpcPort,
  };
  const sandbox = await Sandbox.start({ config: config });

  await sandbox.tearDown();
})();
```

### CLI using

- Initialize the Sandbox node

      near-sandbox --home /tmp/near-sandbox init

* Run it

      near-sandbox --home /tmp/near-sandbox run

  by default it is running on `http:/127.0.0.1:3030`

* Stop the sandox node. Once you're finished using the sandbox node you can stop it by using <kbd>Ctrl</kbd><kbd>C</kbd>. To clean up the data it generates:

      rm -rf /tmp/near-sandbox

To find out other things you can do:

    near-sandbox --help

### Automatic Binary Management

- On sandbox startup, the appropriate binary for your platform is automatically downloaded if not found locally.
- It will be saved in `bin` directory inside package (usually located inside `node_modules` folder of the project).
- The sandbox process runs in the background, and can be terminated by calling `stop()` or `tearDown()` methods.

## Environment Variables

Customize sandbox behavior using the following environment variables:

- `SANDBOX_ARTIFACT_URL`: Specify an alternative URL for downloading the `near-sandbox` binary.
- `NEAR_SANDBOX_BIN_PATH`: Use a custom-built `near-sandbox` binary instead of the default.
- `DIR_TO_DOWNLOAD_BINARY`: Specify direction where you want save Binary. The default is /bin within the package
- `NEAR_RPC_TIMEOUT_SECS`: Set the timeout (in seconds) for waiting for the sandbox to start (default: 10).
- `NEAR_ENABLE_SANDBOX_LOG`: Set to `1` to enable sandbox logging of `near-sandbox` (helpful for debugging).

---
_Source: https://npm.io/package/near-sandbox · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
