SDK reference
JavaScript SDK
LayerFS ships three JavaScript packages, split by who calls them, on one native addon. Agents need only@layerfs/agent. A tool that runs agents, such as DSH, also uses @layerfs/runtime and@layerfs/backend.
Which package
| Package | For | What it does |
|---|---|---|
@layerfs/agent | Agents and their scripts | Everything an agent does on one project: Branches, files, Workspaces and Sandboxes. |
@layerfs/runtime | Integration hosts | One LayerFS installation: which projects exist, starting Init, the worker on macOS and Windows, cleanup. |
@layerfs/backend | Integration hosts | What a host shows in its own views: history, storage numbers, live Workspace state, background processes and daemon logs. |
All three share one version and load the same Rust addon, layerfs.node, which opens the project's Store and talks to Sandbox daemons. LayerFS ships no UI and serves no HTTP: an integration draws its own views from these calls. For coding agents, the layerfs-js-sdk skill is the guide to @layerfs/agent.
import { LayerFS } from "@layerfs/agent";
const layerfs = await LayerFS.open("shop"); // settings come from the environment
try {
await layerfs.branch.fork("cart");
await layerfs.fs.write("cart", "/README.md", "# Shop\n", "readme");
const own = await layerfs.sandbox.create(); // { sandbox: "1", image }
try {
const ws = await layerfs.workspace.mount(own.sandbox, "cart");
try {
const run = await layerfs.workspace.exec(ws, "timeout 110 npm test 2>&1", "step 1");
await layerfs.workspace.commit(ws, `step 1: npm test (exit ${run.exitCode})`);
} finally {
await layerfs.workspace.unmount(ws);
}
} finally {
await layerfs.sandbox.close(own.sandbox);
}
} finally {
await layerfs.close();
}Two routes
- Store calls (
project,branch,fs, and the backend'sstore.*) open the project's Store file in your process and read, save and publish there. The file isglobal/store.sqlitein the project's Docker volume, named byLAYERFS_STORE_PATH. - Workspace calls (
workspace.*,sandbox.*, and the backend'sdaemon.*) go to the daemon in a Sandbox container, through Docker. The daemon opens the same Store.
Where calls run
Every process that opens a Store must share one Linux kernel, with the Store on a local ext4, xfs or btrfs filesystem. Anywhere else, Store calls fail Unsupported, with no fallback.
| Platform | Store calls | Workspace calls |
|---|---|---|
| Linux | In your own process | The Sandbox daemon, through Docker Engine |
| macOS, through the worker | The LayerFS home's worker container, layerfs-worker, that runs the real SDK in Linux | The Sandbox daemon, through Docker Desktop |
| Windows, through the worker | The LayerFS home's worker, a Node process in a WSL2 Linux distribution | The Sandbox daemon, through that distribution's Docker Engine |
The worker route is open to any integration. @layerfs/runtimestarts the worker and hands it to @layerfs/agent in its own process; any other process, such as an agent's command, uses it when its LAYERFS_WORKER_ENDPOINT names the worker's endpoint file. An agent's script is the same on all three. See Platform and limits.
Install
The packages are folders of the LayerFS checkout's api/ folder (api/agent/sdk,api/backend, api/runtime); they aren't published to npm. They need Node 20 or newer. Set them up once in the checkout:
npm --prefix "$LAYERFS_REPO/api" install # links the three packages to each other; downloads nothing
npm --prefix "$LAYERFS_REPO/api" run build:native # the addon, api/binding/layerfs.node, on the host that loads itThen link @layerfs/agent into the folder your scripts run in:
npm init -y >/dev/null && npm pkg set type=module
npm install --no-audit --no-fund "file:$LAYERFS_REPO/api/agent/sdk" # the LayerFS checkoutAn integration host links api/runtime and api/backend the same way. Thelayerfs command, one agent call per shell command, is the checkout's api/agent/cli/ folder: npm --prefix "$LAYERFS_REPO/api/agent/cli" install links it to @layerfs/agent. The repository'sapi/README.md covers builds and tests.
Coming from v1.0.0
v1.0.0 shipped one package, @layerfs/sdk, described in itsREADME. The groupsfs and branch, project.list_branches, and the Workspace calls other than mount and status take the same arguments and answer the same results. What changed:
| v1.0.0 | Now |
|---|---|
import … from "@layerfs/sdk" | import … from "@layerfs/agent" |
the sdk/js folder | the api/ folder: api/agent/sdk, api/agent/cli, api/backend, api/runtime, and the addon at api/binding/layerfs.node |
new LayerFS(name, { storePath, storePolicy, … }) | await LayerFS.open(name), ready when it returns; new LayerFS() is refused |
| options on the client | the environment only: LAYERFS_STORE_PATH, LAYERFS_STORE_POLICY, LAYERFS_DAEMON_HOST, LAYERFS_TRACE; an options object is refused InvalidInput |
DSH_LAYERFS_* names as fallbacks | not read any more: LayerFS reads only LAYERFS_*, and an integration that can set only its own names maps them itself |
layerfs.project.init(folder) | await LayerFS.init(name, folder, timeout?), 300 s by default, answering an open client |
workspace.mount(branch, { image }?), placed in a Sandbox for you | sandbox.create({ image }?), then workspace.mount(sandbox, branch): the mount names its Sandbox, and there is no placement |
operator.sandbox.list(); no way to stop a Sandbox | project.list_sandboxes, sandbox.list_workspaces, sandbox.close |
workspace.status(ws) | backend.daemon.workspace.status(ws) in @layerfs/backend |
operator.* reads and processes (@layerfs/sdk/operator) | @layerfs/backend (LayerFSBackend.of(layerfs)) and @layerfs/runtime; old trace names map through RENAMED_METHODS |
| Store calls on Linux only | on macOS and Windows too, through the LayerFS home's worker (LAYERFS_WORKER_ENDPOINT), which @layerfs/runtime starts |
| a Node script for every call | or the layerfs command, one call per command |
Old trace files keep the names calls had when they ran; RENAMED_METHODS in @layerfs/agentmaps each old name to its new one.


