Skip to main content
Mirage ships BoxResource in two runtimes:
  • @struktoai/mirage-node, uses client_id + client_secret + refresh token (rotated on each use)
  • @struktoai/mirage-browser, supports the same refresh token via PKCE (no client secret in the bundle)
Both runtimes hit the same Box v2 API endpoints (/folders/{id}/items, /files/{id}/content, /search). Credentials are obtained the same way in both runtimes, see Box Credentials.

Quick start: developer token

For exploration, skip the OAuth flow and use a developer token (one-button-click in the Box app console, 60-minute lifetime). The BoxResource accepts an accessToken field that short-circuits the refresh logic:
When the token expires (Box 401s with invalid_token), regenerate it in the console and re-run. See Box Credentials -> Quick Start.

Service account (client credentials, no refresh token)

For headless server auth, skip OAuth and refresh tokens entirely. Create a Box app with the Server Authentication (Client Credentials Grant) method, authorize it once in the Box admin console (Apps -> Custom Apps Manager), and pass the enterprise ID:
Tokens are minted for the app’s service account and re-fetched automatically on expiry; there is no refresh token to rotate or persist.
The service account is a separate Box user with its own (initially empty) root folder. To see your content, share folders with the service account’s email address, shown under the app’s General Settings in the developer console.

Node (server-side, long-running)

The BoxTokenManager caches the access token in memory (5-minute safety buffer before expiry) and rotates the refresh token on every refresh. Without onRefreshTokenRotated, the rotation is in-memory only and a process restart needs a fresh refresh token.

Browser (PKCE, no client secret)

Box requires the origin to be allowlisted on the app’s Allowed Origins config (see setup). The bundled examples/typescript/browser/src/box_pkce.ts runs the full PKCE dance and persists the rotated refresh token to localStorage.

VFS mode (patchNodeFs)

Only fs.promises.* is patched, sync forms aren’t supported.

FUSE mode

Requires macFUSE on macOS or libfuse on Linux.

Path → ID resolution

Box uses numeric folder/file IDs internally (root folder is id 0). Mirage caches the path → ID mapping in the RAMIndexCacheStore attached to the resource. The first time you ls /box/foo/bar/, it walks the tree top-down (one API call per level) and caches each entry’s ID. Subsequent reads of /box/foo/bar/anyfile.json hit the cache instead of re-walking. The cache TTL defaults to 24h. To force re-resolution, recreate the BoxResource.

Special file types

Five Box-specific file types get a .json suffix appended in the vfs and return clean, agent-friendly JSON when you cat them. The Box file ID is unchanged, the suffix is purely a vfs hint that cat returns JSON, mirroring Google Drive’s .gdoc.json style. In ls /box/:

.boxnote.json, Box Notes

.boxcanvas.json, Box Canvas (whiteboards)

.gdoc.json / .gsheet.json / .gslides.json, Box’s V2 Google files

Box’s V2 G Suite integration stores Google-format files as Office Open XML zips (.docx / .xlsx / .pptx). On cat, Mirage uses Box’s representations API with X-Rep-Hints: [extracted_text] to fetch Box’s auto-extracted plain-text version, then returns a JSON envelope:
This is different from Google Drive’s .gdoc.json, Box uses its own API + extracted-text representation; Google Drive uses Google’s full Documents API and returns the rich Document structure (paragraphs, named styles, lists, etc.). For real edits to the underlying Google Doc, mount Google Drive separately with Google credentials and use the GDocs / GSheets / GSlides resources, gws-docs-* commands won’t work on Box because the file IDs are in different namespaces.

Available commands

BoxResource ships the same shell command set as GDriveResource and DropboxResource:
  • Filesystem: ls, cat, head, tail, nl, wc, stat, find, tree, du, file, realpath, basename, dirname
  • Search/text: grep, rg, awk, sed, sort, uniq, cut, diff, cmp, jq
  • Encoding: base64
  • Format-aware: cat_parquet, cat_feather, cat_hdf5, plus head_*/grep_*/ls_*/ stat_*/tail_*/wc_*/file_*/cut_* variants for .parquet, .feather, .hdf5/.h5, .orc files

Examples

End-to-end runnable scripts are in examples/typescript/box/:
  • box.ts, Workspace.execute('ls/stat/cat/tree …') shell demo
  • box_parquet.ts, parquet preview through cat
  • box_boxnote.ts, .boxnote.json decoded into clean JSON
  • box_office.ts, .gdoc.json / .gsheet.json / .gslides.json via Box’s extracted_text representation
  • box_vfs.ts, patchNodeFs + native fs.promises.* calls
  • box_fuse.ts, FUSE mount with shell access in another terminal