> For the complete documentation index, see [llms.txt](/llms.txt).

# Snaps execution environment

Snaps are untrusted JavaScript programs that execute safely in a sandboxed environment that runs [Secure ECMAScript (SES)](#secure-ecmascript-ses). This allows MetaMask to restrict access to global JavaScript APIs and to isolate a Snap's code from other parts of the application.

This environment does not have a DOM, Node.js built-ins, or platform-specific APIs other than the default `snap` global and MetaMask's `ethereum` global.

The execution environment is designed to:

- Prevent Snaps from polluting the global environment.
- Prevent malicious Snaps from stealing from users.
- Prevent Snaps from accessing sensitive JavaScript global APIs (such as `fetch`) without permission.
- Be "fully virtualizable," or platform-independent.

This allows you to safely execute Snaps anywhere, without the Snap needing to worry about where and how it's executed.

## Supported globals[​](#supported-globals "Direct link to Supported globals")

A Snap can access the [Snaps API](/snaps/learn/about-snaps/apis/#snaps-api) using the `snap` global, and the [Wallet API](/snaps/learn/about-snaps/apis/#wallet-api) using the `ethereum` global. To access the `ethereum` global, a Snap must request the [endowment:ethereum-provider](/snaps/reference/permissions/#endowmentethereum-provider) permission.

Almost all [standard JavaScript globals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global%5FObjects)that are also in Node.js are available to Snaps. This includes globals such as `Promise`, `Error`, `Math`, `Set`, and `Reflect`.

The following globals are also available:

- `console`
- `fetch` (with the [endowment:network-access](/snaps/reference/permissions/#endowmentnetwork-access) permission)
- `setTimeout` / `clearTimeout`
- `setInterval` / `clearInterval`
- `SubtleCrypto`
- `WebAssembly` (with the [endowment:webassembly](/snaps/reference/permissions/#endowmentwebassembly) permission)
- `TextEncoder` / `TextDecoder`
- `atob` / `btoa`
- `URL`

note

To use Node.js built-in modules such as `crypto` and `path`, set the [polyfills](/snaps/reference/config-options/#polyfills) configuration option to `true`.

## Secure ECMAScript (SES)[​](#secure-ecmascript-ses "Direct link to Secure ECMAScript (SES)")

[Secure ECMAScript (SES)](https://github.com/endojs/endo/tree/master/packages/ses) is an implementation of the [Hardened JavaScript](https://hardenedjs.org/) proposal. Hardened JavaScript is a subset of JavaScript designed to enable mutually suspicious programs to execute in the same JavaScript process (or the same [realm](https://tc39.es/ecma262/#realm)). You can think of it as a more severe form of [JavaScript strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict%5Fmode).
