@hachej/boring-execution
Optional working environments use Pi's public FileSystem, Shell and ExecutionEnv contracts. /native re-exports those contracts. /contracts adds acquisition and lease identity without requiring recovery, a shell or a Boring resource reference.
Disposable virtual workspace
/virtual provides createVirtualWorkspace. Install the exact optional peer just-bash@3.6.0 alongside the declared native peers. Seed absolute paths, acquire a native environment with an absolute cwd, or create a public upstream Bash instance.
import { createVirtualWorkspace } from '@hachej/boring-execution/virtual';
import { BACKGROUND_CONTEXT } from '@earendil-works/chord/context';
const workspace = createVirtualWorkspace({
providerId: 'scratch',
files: { '/repo/note.txt': 'hello\n' },
});
const lease = await workspace.acquire({
operationId: 'open-scratch', input: { cwd: '/repo' },
}, BACKGROUND_CONTEXT);
console.log(await workspace.createBash({ cwd: '/repo' }).exec('cat note.txt'));
await lease.release(BACKGROUND_CONTEXT);
workspace.dispose();
One upstream InMemoryFs stores all bytes. Public mutation adapters resolve aliases consistently for native access, Bash and Git. Leases share namespace identity and have independent cwd and cleanup. Releasing a lease closes only its native facade. Disposing the workspace prevents new acquisitions/Bash instances and closes native facades. Already returned raw filesystem and Bash handles remain trusted host-owned handles; disposal does not revoke them or terminate their commands.
Native read/write/append, directory access, symlinks and exclusive temporary files are exercised by public tests. Native rename, truncate and durable flush return not_supported. The backing refuses move and recursive directory copy. These refusals precede mutation. Hard links refuse with ENOTSUP. Virtual Bash refuses hard-link arguments before stock ln -f can remove an existing destination; symbolic links retain the stock command context. Concurrent structural changes to paths remain unqualified; this disposable adapter is not an authoritative publication provider or a POSIX filesystem qualification.
The native shell runs Pi's stock bash tool with buffered output: onOutput receives the combined stdout and stderr once when the command ends (never as a live stream), spill thresholds are accepted but nothing is spilled to a file, and timeout (seconds) aborts the command and returns timeout. Use public Bash exec for separate buffered stdout/stderr. Host Bash options select upstream limits and explicit network/custom commands. No native executable fallback or network transport is added. Host callbacks are trusted code.
Errors are bounded in one place (boundedMessage in src/bounded-error.ts, also used by the AWS Code Interpreter environment below): every error the native environment, the git command or a fs backing passes on toward a tool result is its message only, with stack-frame lines dropped even when a backing put them in the message, and at most MAX_ERROR_CHARS (2,000, exported from /virtual) characters. The whole error stays on cause for host logs. Command output itself is bounded by Pi's bash tool (its tail, 50 KB or 2,000 lines).
Python (opt-in, Node only)
createVirtualWorkspace({ providerId, python: true }) adds python3 and python to every shell of the workspace (the native exec's included): just-bash's CPython 3.13 compiled to WebAssembly, with the standard library, reading and writing the same files as the shell. It is off by default and is the only way to turn it on (shell options cannot). Limits: Node only, so it throws a clear TypeError in a browser or its workers; the runtime (about 10 MB, shipped inside just-bash) loads on the first call (about a second here; later calls about half a second); its memory is not contained by the shell's execution limits, so a script can grow the host process; there is no pip, package installation or network. A Python traceback is the script's own output and passes through unchanged.
Optional local Git
/virtual-git requires isomorphic-git@1.42.6 and @hachej/boring-files/git. createVirtualGitFs(workspace.filesystem) supplies its public promise filesystem. The host creates one createGitRepository({ fs, directory, author, authorize }), then calls installVirtualGitCommand({ bash, repository }). Installation verifies the actual public bash.fs identity. Each command requires the selected root cwd. Native tools receive the same repository instance.
The command supports local init, matrix status, single-path add, index-only rm --cached, commit -m, bounded log, branch, checkout, and binary-content JSON diff or diff --cached. Other argument forms return exit 126. The files guide owns authorization, serialization and diff semantics. No remote transport, durable recovery or publication transaction is claimed. Raw .git writes remain subject to the selected filesystem's host policy.
Run node fixtures/virtual-workspace.mjs after building for a fictional shared native/Bash/Git example. test/packages/execution.test.mjs exercises public output and actual native ToolTasks. npm run test:virtual-consumer installs the tarball and exact registry dependency closure outside the repository, checks declarations and repeats those tests. Set npm_config_cache to a writable cache containing the pinned archives.
Borrowed remote Shell
/remote-shell exports paired createRemoteShellHandler and createRemoteShellLease Fetch adapters over native Pi Shell. This subpath needs only the pinned native peers. It does not load virtual Bash, Git, Boring files or an agent implementation. The host authenticates each POST, enforces origin/CSRF policy, selects an already acquired workspace, and provides its native Shell, Context, exact identity, revocation signal and command authorization callback. Authorization must return true and runs before execution and terminal disclosure. Abort the revocation signal when access or workspace identity changes, including during silent commands.
The client takes that expected identity, a fixed HTTP(S) endpoint and an explicit authenticated Fetch function. The client sends redirect: 'manual' (the Workers runtime refuses 'error') and refuses any answer that is not 200, a redirect included, so it never follows one to another host with the request's credentials; the transport must not retry command requests. Both ends bind provider, instance, incarnation and selected view. The server checks identity before effects. The client checks identity before delivering output, validates ordered request-bound frames and requires exactly one terminal result followed by EOF. A lost or malformed acknowledgement returns native ExecutionError('unknown'); the client never replays the command. A request identifier correlates frames, not a durable idempotency or recovery record.
Command strings, cwd, environment and native exit/error results pass through (protocol version 2). Output callbacks receive live combined text and the caller's Context. Pi's window option is forwarded to the worker's native Shell, and skipped counts on its output chunks are relayed in the output frames (validated, never invented), The handler also applies the window itself (remote-shell-window.ts): it keeps the retained tail, flushes no faster than minIntervalMs, and reports what it dropped as merged skipped counts, so a worker that ignores the window (Pi's Node environment) still transfers only the tail. Counts a windowing worker already reports are merged, not recomputed. Without window, every chunk is delivered. Exit-only calls do not request output frames. Positive fractional timeout values use native seconds, with the provider responsible for its additional limits. Hosts explicitly qualify timeout and spill support; unsupported requested features refuse before execution. Spill paths remain in the remote workspace and need a separately authorized file capability to retrieve them. No dummy filesystem is supplied.
Transport defaults are 64 KiB per request, 1 MiB per frame and 4 MiB of queued server frames. Oversized output or an overfull queue interrupts observation rather than reporting truncated success. These bounds do not cap native output production or Fetch/provider peak memory. Host native execution limits remain necessary. Local cancellation, callback failure or lease release requests remote cancellation and reports unconfirmed termination; prior effects can remain. Each borrowed lease owns only its active transports, and never calls the shared provider's cleanup.
Run node fixtures/remote-shell.mjs for an actual native command through in-process Request/Response streaming. npm run test:remote-shell-consumer installs only the execution tarball and pinned native registry closure, checks strict declarations and repeats public native tests without the virtual/Git/Boring UI/agent peers. The handler reads request bodies through @hachej/boring-files/request-guard, so install @hachej/boring-files (an optional peer) with this subpath; the consumer installs its archive. This establishes the paired Fetch protocol and selected native behavior. Socket deployment, vendor provisioning/reattachment, durable command admission/recovery, independent file grants, protected builds and process-tree termination remain separate qualifications.
Borrowed remote FileSystem
/remote-files exports createRemoteFileSystemHandler and createRemoteFileSystemLease over native Pi FileSystem. Install the exact optional peer zod@4.6.5 with the declared native peers. This entry does not require a shell, virtual Bash, Git, Boring files, UI or an agent implementation.
The host authenticates each POST and selects an already acquired workspace. Its bindFileSystem(cwd, context) returns a WorkspaceLease<FileSystem> over that namespace with the requested cwd. The adapter checks the actual lease identity, native filesystem ID and cwd before execution and disclosure. Bind distinct facades for concurrent incompatible cwd values. Binding must not provision or silently recreate a workspace. The handler releases each bound lease after its operation, or after closing its native line reader. It never invokes shared provider cleanup.
authorize(call, cwd) receives a discriminated native method/argument tuple and must return literal true. The handler checks authorization before and after each operation and stream read. Abort the host revocation signal when authorization or workspace identity changes, including while a reader is idle. Authentication, origin/CSRF policy, path and symlink confinement, deadlines and provider limits remain host responsibilities. Native temporary-file operations retain provider semantics, which can place files outside cwd. A cwd check alone is not a path grant.
The client captures cwd and arguments for each invocation. Native path, binary, metadata, text and mutation results pass through validated request-bound envelopes. Native errors retain their code, message and optional path. A lost, malformed or post-dispatch cancelled acknowledgement returns FileError('unknown') and can follow prior effects. There is no automatic retry, rollback or durable deduplication. The request ID correlates the response only. Authoritative published resources use their separate conditional publication contract.
openTextLineReader retains one streamed native reader. Frames preserve strict LF splitting and each line's terminated flag. A cancelled readLine wait leaves its pending frame available for the next call. Cancelling the original open context after successful opening does not close the reader. Concurrent reads refuse. Explicit close or lease release cancels local observation; server cleanup closes the reader before releasing its facade. Client close does not wait for a remote cleanup acknowledgement or prove remote termination.
Pi's openBinaryReader and openDirReader keep a handle open, which a stateless request cannot. The client therefore turns each reader call into one request-bound call (binaryInfo, readRange, scanLines, readDirPage) that opens the worker's own native reader, answers a bounded range, line scan or directory page, and closes it. scanLines runs on the worker, so locating lines in a large file does not move the file; read is split into responses that fit the response limit, and a range above the worker's limit is refused. The client records the opened file's size and mtimeMs and sends them with every call; the worker checks them before and after the read and fails with FileError('invalid') when the file changed (Pi's FileInfo has no inode, so a same-size, same-mtime replacement cannot be told apart). Directory pages continue by entry offset over the native reader and are checked against the directory's mtimeMs; a directory that changed between pages fails instead of skipping or repeating entries. Native open errors (not_found, is_directory, not_directory, invalid for noFollow links) keep their codes. These calls pass through authorize like every other method. Only environments without positional reads (the in-memory virtual file system) use snapshotReaders in fs-readers.ts.
Known deviations from Pi's reader contract: a reader holds no handle, so renaming or replacing the file after openBinaryReader makes later calls fail (not_found or invalid) instead of reading the originally opened file; the path is resolved to an absolute path once at open, so a later cwd change does not affect an open reader; concurrent next() calls on one directory reader are refused with invalid; an empty not-done directory page is refused (unknown) rather than looped on; directory paging costs O(offset) per page on the worker.
watch is one streamed request: the worker's native watch feeds a bounded queue (a full queue, or a frame over the limit, becomes Pi's overflow), each change is authorized again before disclosure, and mode comes from the native watcher. A terminal error is kept apart from the bounded event queue (a full queue collapses events to overflow, never the error) and an oversized error has its text bounded; a stream that ends without an error change is reported to the listener as an error change. An error change ends the stream; revocation, a lost stream or lease release deliver one error change; close (or aborting the stream) closes the native watcher, and no change is delivered after close resolves. Establishing the watch fails with the worker's native error, so an environment without native watching reports its own not_supported.
Defaults are 1 MiB per request, 4 MiB per normal JSON response and 1 MiB per stream frame. Binary values travel as canonical base64 text (protocol version 3; older peers are refused, so upgrade both ends together). Server backpressure queues at most one frame and reads on demand, with a read possibly in flight. These limits bound accepted transport data, not native reader allocation, JSON expansion, Fetch allocation or provider production. Oversized data refuses instead of reporting truncated success.
Run node fixtures/remote-files.mjs after building to write and stream a fictional native file without a shell capability. npm run test:remote-files-consumer installs the execution and files tarballs (this subpath reads bodies through @hachej/boring-files/request-guard) and pinned registry dependencies, checks strict declarations and exercises actual native files, a native ToolTask and reader lifetime races. Its pinned buffer fixture dependency keeps undici's bare type import inside the isolated installation when the temporary directory has a parent workspace. In-process Fetch evidence does not qualify deployed sockets, vendor lifecycle, acquisition recovery, protected builds or complete exposure policy.
Virtual repository saved in SQLite