Skip to content
docs
type to search↑↓ move↵ openesc close
v0.2.4github

Connect a TypeScript backend

2 min readv0.2.4this page as markdown
let your agent do it
Connect my Node or Bun backend to Hermitbox.
Paste it into your agent. It follows this page as Markdown: typescript.md

Create a sandbox, run a command, and delete it from a Node or Bun backend with the TypeScript SDK.

  1. Install hermitbox in your Node backend with its package manager.
  2. Set HERMITBOX_API_URL and HERMITBOX_API_KEY in the backend’s private environment.
  3. Run this module with your application’s normal TypeScript runner or build.
typescript
import { Hermitbox } from 'hermitbox'

// Connect with HERMITBOX_API_URL and HERMITBOX_API_KEY from the environment.
const hb = new Hermitbox()

// Use the install's default tier. A container also needs an image.
const { defaults } = await hb.project()
if (!defaults) throw new Error('The install did not report its default tier')
const { isolation } = defaults
const box = await hb.sandbox(
  isolation === 'container' ? { isolation, image: 'alpine:3.22' } : { isolation },
)

try {
  // Run a command and stop if it failed.
  const result = await box.run('echo hello')
  if (result.code !== 0) throw new Error(result.stderr)
  console.log(result.stdout) // hello
} finally {
  // Delete the sandbox, even when something failed.
  await box.delete()
}

Keep this on the server: browser bundles must never contain a project key. On serverless platforms, await work inside the request lifetime or use a supported background worker; the platform can stop an unawaited promise when the request ends.

Long streams need a runtime that permits their duration. The host tier still controls capabilities and isolation. SDK reference.

run it yourself
$curl -fsSL https://hbx.sh | sh
or ask your agent
Install Hermitbox and set it up for me
Linux (x86_64 or aarch64), no root, no Docker. Agents can read every page: llms.txt · llms-full.txt
the floor · nothing below this line