The Environment API is Lix's abstraction layer that lets you run the same code everywhere — from browser tabs to Node.js servers to test suites. Each Environment is a container where the Lix Engine runs alongside SQLite, handling both where your data lives and how your code executes, so you don't have to worry about platform differences.
When building applications with Lix, you need different storage and runtime strategies depending on where your code runs:
Environments solve this by providing a consistent interface while handling platform-specific details under the hood.
The Lix SDK provides two built-in environments that cover most use cases:
The simplest environment that runs everything in memory on the current thread.
When to use:
Characteristics:
A production-ready browser environment using Web Workers and OPFS SAH (Origin Private File System with Synchronous Access Handles).
When to use:
Characteristics:
Each environment is a runtime container that hosts the Lix Engine and manages two key responsibilities:
Environments decide where and how your SQLite database lives — whether that's in memory, in browser storage, or on disk. They handle creating, loading, and persisting your data.
Environments determine where the Lix Engine executes. The InMemoryEnvironment runs the engine on your main thread (simple but can block UI), while OpfsSahEnvironment runs the engine in a Web Worker (non-blocking but requires message passing). The engine always runs inside the environment, never separately.
Most applications should use openLix()
which automatically selects the right environment:
When you need specific control:
If you need to run Lix somewhere else—another storage backend, a specialized worker, a native shell—you can implement your own environment by satisfying the LixEnvironment
interface.
At minimum you must provide persistence primitives (create
, exists
, exec
, export
, close
) and implement open()
so the SDK can boot the engine next to your database. The call()
method must forward engine RPCs across your boundary (e.g. to a worker thread or other process).
Environments that support isolated execution can additionally expose spawnActor(opts)
:
The SDK uses this capability to offload work (for example, diff rendering) when available, but will fall back to running tasks inline when spawnActor
is absent. When authoring a custom environment you only need to implement this hook if you can actually spawn workers in your target runtime; otherwise, you can omit it.