
What are Realms?
- Isolated/sandboxed execution environments
- Physical security layer between application segments
- Prevent untrusted code from poisoning the runtime environment (either accidentally or intentionally) for other code
What are Realms?

Roots vs Compartments
- Realms don't have any innate host objects (e.g. window, document, XMLHttpRequest, etc)
- Root realms receive copies of primitives
- Compartments receive shared references of primitives
Proposal
From a gist related to the Realm API: 'A realm object abstracts the notion of a distinct global environment, with its own global object, copy of the standard library, and "intrinsics" (standard objects that are not bound to global variables, like the initial value of Object.prototype).'
In other words, a realm is the concept of an encapsulated runtime container that gets its own root namespace, copy of the standard library, and fresh copies of primitive data types.
Shim
A shim is available to start using the new Realm API today, in both node (via vm.createContext) and in browsers (via same-origin iframes)
Security Impacts
- Realms provide a facility for running code in sandboxed environments
- The only external code realms have access to are whitelisted items that the realm creator provides to them as endowments
- Primitives are provided to root realm runtimes as copies of the ones from the containing realm
- Child realms can't poison the prototypes of the containing realm that created them, unless you give them a handle into the containing realm's runtime.
Caveats
- Identity discontinuity for 'instanceof' checks when passing certain primitive values between realms
- Primordial poisoning can still happen if you're not careful about what you're passing into a realm
- Primordial poisoning can still happen between related compartment realms


Frozen Realms
- Lightweight implementation of realms
- Created from shared, immutable root realm
- Prevents primordial poisoning between realms
- Ensures identity continuity between realms
Resources
- Realms Code Sandbox
- TC39 proposal for Realms
- TC39 proposal for Frozen Realms
- Report on current state of Realms shim, given in July 2018
- Frozen Realms proposal video
fn.
The Realms of Ecma
By Richard Lindsey
The Realms of Ecma
- 128