GitHub 37
Skip to content
ViteHub is still experimental. Expect bugs and breaking changes.

Shell

Run simple shell commands like ls, cat, and rg from your server, with limits you control.

Deploys on
  • Node
  • Docker
  • Cloudflare
server/utils/docs-shell.ts
import { createShellRuntime } from 'vite-hub/shell'
import {
  createJustBashDriver,
} from 'vite-hub/shell/providers/just-bash'
import {
  createReadonlyWorkspaceFs,
} from 'vite-hub/shell/workspace'
import { useWorkspace } from 'vite-hub/workspace'

// A shell that can only read the docs Workspace
export function docsShell() {
  const docs = useWorkspace('docs')
  return createShellRuntime({
    policy: { timeout: 10_000, maxOutputLength: 5_000 },
    // Bash in JavaScript: no real processes
    driver: createJustBashDriver({
      // The only commands it can run
      commands: ['ls', 'cat', 'rg'],
      fs: createReadonlyWorkspaceFs(docs.fs),
    }),
  })
}
server/utils/docs-shell.ts

Choose the allowed commands

List the commands a shell can run. Network access stays off unless you turn it on.

Work on your files

Commands see Workspace files under /workspace, read-only or writable.

Clear results

Every call returns its exit code, stdout, and stderr. Blocked commands exit with 126.

Limits across commands

A session shares one call limit, output cap, and timeout across many commands.

Check a command first

analyzeShellCommand() lists the programs, pipes, and redirects in a command, so you can decide what to allow.

Stop slow commands

Set a timeout or cancel a running command with an AbortSignal.