Skip to main content
HfSpacesResource mounts a Hugging Face Space repo (app code, README, config, requirements) at a prefix such as /s/. The TypeScript backend mirrors the Python one and returns identical results. For credential setup, see HF Spaces Setup.
Node only. The backend uses the native opendal binding, which does not run in the browser.

Node

pnpm add @struktoai/mirage-node
import { HfSpacesResource, MountMode, Workspace } from '@struktoai/mirage-node'

const space = new HfSpacesResource({
  repoId: 'HuggingFaceBio/carbon-demo', // "namespace/space-name"
  token: process.env.HF_TOKEN, // optional for public spaces
  // Optional:
  // endpoint: 'https://huggingface.co',
  // revision: 'main',
})

const ws = new Workspace({ '/s/': space }, { mode: MountMode.READ })

console.log((await ws.execute('ls /s/')).stdoutText)
console.log((await ws.execute("find /s/ -name '*.py'")).stdoutText)
console.log((await ws.execute('cat /s/README.md | head -n 15')).stdoutText)

Shell Commands

Same set as HF Buckets.