Skip to main content

@flow-state-dev/tools/bash

Interfaces​

CreateBashBlocksOptions​

Properties​

collections?​
collections?: BashCollectionSpec[];

Explicit list of collections to mount. Each entry is either a key (string) or { key, writable }. When provided, ONLY these collections are mounted and exclude is ignored.

When omitted (the default), bash auto-discovers every collection present on the block's runtime resource context — any ResourceCollectionRef on ctx.resources is mounted at its pattern prefix.

createState?​
createState?: (relativePath) => ProjectedEntryExtra;

Extra resource state to stamp on each file written back to a collection. Receives the workspace-relative path (e.g. artifacts/notes.md).

The workspace sets path, hash, and updatedAt. A value returned for one of those keys is ignored. Default: () => ({}).

Parameters​
relativePath​

string

Returns​

ProjectedEntryExtra

destination?​
destination?: string;

Virtual workspace root visible to the LLM. Defaults to "/workspace" for most providers; for the Vercel adapter the default is "/vercel/sandbox/workspace" because the sandbox's vercel-sandbox runtime user can't mkdir outside /vercel/sandbox (its home). writeFiles extracts tarballs at /, so any absolute path outside the user's home fails with Cannot mkdir: Permission denied at tar extraction time.

exclude?​
exclude?: string[];

Keys to skip during auto-discovery. Useful when you want "everything except X". Ignored when collections is set explicitly.

provider?​
provider?: SandboxProvider;

Sandbox provider. Default: { type: "just-bash" }, the in-process emulator. The host shell ({ type: "local" }) runs real commands on the host and is only ever an explicit choice.


CreateBashCapabilityOptions​

Properties​

collections?​
collections?: BashCollectionSpec[];

Explicit list of collections to mount. Strings are shorthand for writable mounts; { key, writable: false } opts a specific collection out of flush-back. When omitted, every collection on the block's resource context is mounted (default).

createState?​
createState?: (relativePath) => ProjectedEntryExtra;

Extra state stamped on each file written back to a collection. Receives the workspace-relative path (e.g. artifacts/notes.md).

The workspace sets path, hash, and updatedAt. A value returned for one of those keys is ignored.

Parameters​
relativePath​

string

Returns​

ProjectedEntryExtra

destination?​
destination?: string;

Virtual workspace root. Default: "/workspace" for most providers, "/vercel/sandbox/workspace" for the Vercel adapter (required for tarball-extract permissions).

exclude?​
exclude?: string[];

Keys to skip during auto-discovery. Ignored when collections is set.

provider?​
provider?: SandboxProvider;

Sandbox provider. Default: { type: "just-bash" }.

Type Aliases​

BashCollectionSpec​

type BashCollectionSpec =
| string
| {
key: string;
writable?: boolean;
};

A collection selection entry. A bare string is shorthand for { key, writable: true }.


ExecutionLimits​

type ExecutionLimits = object;

Execution limits for just-bash sandboxes.

Properties​

maxAwkIterations?​
maxAwkIterations?: number;
maxCallDepth?​
maxCallDepth?: number;
maxCommandCount?​
maxCommandCount?: number;
maxLoopIterations?​
maxLoopIterations?: number;
maxSedIterations?​
maxSedIterations?: number;

NetworkConfig​

type NetworkConfig = object;

Network configuration for just-bash sandboxes.

Properties​

allowedUrls?​
allowedUrls?: object[];

Allowlisted URL prefixes with optional method and header constraints.

headers?​
headers?: Record<string, string>;
methods?​
methods?: string[];
url​
url: string;
dangerouslyAllowFullInternetAccess?​
dangerouslyAllowFullInternetAccess?: boolean;

Bypass all URL restrictions. Use only in trusted environments.


UpstashBoxClient​

type UpstashBoxClient = UpstashBoxClientLike;

Public-facing alias for the structural client shape declared in ../types.


WorkspaceScope​

type WorkspaceScope = "session" | "user" | "org" | "run";

Workspace scope for the local provider. Determines the workspace directory.

Functions​

createBashBlocks()​

function createBashBlocks(options?):
| {
bashCommand: BlockDefinition<ZodObject<{
command: ZodString;
}, "strip", ZodTypeAny, {
command: string;
}, {
command: string;
}>, ZodObject<{
exitCode: ZodNumber;
stderr: ZodString;
stdout: ZodString;
}, "strip", ZodTypeAny, {
exitCode: number;
stderr: string;
stdout: string;
}, {
exitCode: number;
stderr: string;
stdout: string;
}>, {
command: string;
}, CommandResult>;
bashReadFile: BlockDefinition<ZodObject<{
path: ZodString;
}, "strip", ZodTypeAny, {
path: string;
}, {
path: string;
}>, ZodObject<{
content: ZodString;
}, "strip", ZodTypeAny, {
content: string;
}, {
content: string;
}>, {
path: string;
}, {
content: string;
}>;
bashWriteFile: BlockDefinition<ZodObject<{
content: ZodString;
path: ZodString;
}, "strip", ZodTypeAny, {
content: string;
path: string;
}, {
content: string;
path: string;
}>, ZodObject<{
refused: ZodDefault<ZodNullable<ZodString>>;
success: ZodBoolean;
}, "strip", ZodTypeAny, {
refused: string | null;
success: boolean;
}, {
refused?: string | null;
success: boolean;
}>, {
content: string;
path: string;
}, {
refused: string | null;
success: boolean;
}>;
}
| {
bashCommand: SequencerDefinition<{
command: string;
}, {
exitCode: number;
stderr: string;
stdout: string;
}, undefined, undefined>;
bashReadFile: SequencerDefinition<{
path: string;
}, {
content: string;
}, undefined, undefined>;
bashWriteFile: | BlockDefinition<ZodObject<{
content: ZodString;
path: ZodString;
}, "strip", ZodTypeAny, {
content: string;
path: string;
}, {
content: string;
path: string;
}>, ZodObject<{
refused: ZodDefault<ZodNullable<ZodString>>;
success: ZodBoolean;
}, "strip", ZodTypeAny, {
refused: string | null;
success: boolean;
}, {
refused?: string | null;
success: boolean;
}>, {
content: string;
path: string;
}, {
refused: string | null;
success: boolean;
}>
| SequencerDefinition<{
content: string;
path: string;
}, {
refused: string | null;
success: boolean;
}, undefined, undefined>;
};

Creates bash handler blocks backed by a sandbox and synced with collections auto-discovered from the block's resource context. Returns three blocks: bashCommand, bashReadFile, bashWriteFile.

The sandbox is created lazily per session and collections are mounted at their pattern prefixes on first access. See the module docstring for the full path layout and write-back rules.

Parameters​

options?​

CreateBashBlocksOptions

Returns​

| { bashCommand: BlockDefinition<ZodObject<{ command: ZodString; }, "strip", ZodTypeAny, { command: string; }, { command: string; }>, ZodObject<{ exitCode: ZodNumber; stderr: ZodString; stdout: ZodString; }, "strip", ZodTypeAny, { exitCode: number; stderr: string; stdout: string; }, { exitCode: number; stderr: string; stdout: string; }>, { command: string; }, CommandResult>; bashReadFile: BlockDefinition<ZodObject<{ path: ZodString; }, "strip", ZodTypeAny, { path: string; }, { path: string; }>, ZodObject<{ content: ZodString; }, "strip", ZodTypeAny, { content: string; }, { content: string; }>, { path: string; }, { content: string; }>; bashWriteFile: BlockDefinition<ZodObject<{ content: ZodString; path: ZodString; }, "strip", ZodTypeAny, { content: string; path: string; }, { content: string; path: string; }>, ZodObject<{ refused: ZodDefault<ZodNullable<ZodString>>; success: ZodBoolean; }, "strip", ZodTypeAny, { refused: string | null; success: boolean; }, { refused?: string | null; success: boolean; }>, { content: string; path: string; }, { refused: string | null; success: boolean; }>; } | { bashCommand: SequencerDefinition<{ command: string; }, { exitCode: number; stderr: string; stdout: string; }, undefined, undefined>; bashReadFile: SequencerDefinition<{ path: string; }, { content: string; }, undefined, undefined>; bashWriteFile: | BlockDefinition<ZodObject<{ content: ZodString; path: ZodString; }, "strip", ZodTypeAny, { content: string; path: string; }, { content: string; path: string; }>, ZodObject<{ refused: ZodDefault<ZodNullable<ZodString>>; success: ZodBoolean; }, "strip", ZodTypeAny, { refused: string | null; success: boolean; }, { refused?: string | null; success: boolean; }>, { content: string; path: string; }, { refused: string | null; success: boolean; }> | SequencerDefinition<{ content: string; path: string; }, { refused: string | null; success: boolean; }, undefined, undefined>; }


createBashCapability()​

function createBashCapability(options?): DefinedCapability<"bash", Record<string, never>, "default" | "guidance" | "tools", Record<string, PresetDef<any>>, undefined, undefined, undefined, undefined, undefined> & object & object;

Creates a bash capability that bundles tool blocks and context guidance.

Returned capability has two presets (both on by default):

  • tools — the three bash handler blocks (bashCommand, bashReadFile, bashWriteFile)
  • guidance — dynamic context function describing the workspace + mounted paths

Parameters​

options?​

CreateBashCapabilityOptions

Returns​

DefinedCapability<"bash", Record<string, never>, "default" | "guidance" | "tools", Record<string, PresetDef<any>>, undefined, undefined, undefined, undefined, undefined> & object & object


createLocalFsSandbox()​

function createLocalFsSandbox(options?): Sandbox;

Creates a sandbox backed by the local filesystem.

Commands run via /bin/bash in the specified working directory. File reads/writes go through node:fs. Parent directories are created automatically on write.

The optional destination parameter specifies the virtual workspace prefix (e.g. /workspace) that callers prepend to file paths. When set, the adapter strips this prefix before resolving against cwd, so /workspace/src/index.ts maps to <cwd>/src/index.ts on the real filesystem.

Parameters​

options?​

LocalFsSandboxOptions

Returns​

Sandbox


createSandboxPlace()​

function createSandboxPlace(sandbox, destination): Place;

Wrap sandbox as a place rooted at destination.

Paths crossing this boundary are workspace-relative (artifacts/foo.md); everything absolute stays on the sandbox side of it.

Parameters​

sandbox​

Sandbox

destination​

string

Returns​

Place


hashContent()​

function hashContent(content): string;

A hex SHA-256 of content. The only comparison the projection makes.

Parameters​

content​

string

Returns​

string


releaseBashSandbox()​

function releaseBashSandbox(provider, ctx): Promise<void>;

Release the bash sandbox associated with the given context, if any.

Resolves the same registry key the matching createBashBlocks call uses, looks up the entry, calls sandbox.stop?.() (best-effort), and removes it from the registry. Errors are logged, never thrown — onFinished fires after the response is on its way back to the client and a throw here would only show up in server logs.

Parameters​

provider​

SandboxProvider

ctx​

BlockContext

Returns​

Promise<void>

References​

BashSessionState​

Re-exports BashSessionState


BashToolkit​

Re-exports BashToolkit


CommandResult​

Re-exports CommandResult


createBashTool​

Re-exports createBashTool


CreateBashToolOptions​

Re-exports CreateBashToolOptions


CreateBashToolResult​

Re-exports CreateBashToolResult


Sandbox​

Re-exports Sandbox


SandboxProvider​

Re-exports SandboxProvider