# Embedded Bash, JavaScript and Python

An agent should not need a container just to compose tools, search files, or draw a chart. nanocode connects three embedded runtimes: djs for JavaScript cells, psh for Bash-style commands, and RustPython for Python programs.

**The host supplies capabilities. The runtimes supply execution.** A Worker has no ordinary process tree, and a browser has no system shell. Embedding interpreters lets those hosts run useful programs without pretending they provide a full Linux machine.

This essay describes the integration at [core `6ed92be`](https://github.com/nanocodexyz/nanocode/tree/6ed92be87b3a2f704a7af857a2237b3fccafbb27) and [TypeScript SDK `c9e92eb`](https://github.com/nanocodexyz/nanocode-ts/tree/c9e92eb906d19b958553e2ee85f57319579d4976). These are source references, not a claim that every later release or deployed host has identical behavior.

## Three Runtimes

The agent loop and its journal belong to the brain. Code Mode composes tool calls, and a tool can select a local or remote hand. Inside a host without system processes, the shell and Python adapters use embedded interpreters.

```mermaid
flowchart TD
  %% Code Mode composes tools; host adapters select how commands execute.
  A[Agent brain] --> B[JavaScript cell: djs]
  B --> C[Registered tools]
  C --> D[Host adapter]
  D --> E[Embedded shell: psh]
  E --> F[Embedded Python: RustPython]
  D --> G[Remote hand]
```

These are separate execution layers, not one language translated into another. A JavaScript cell can call a shell tool, but its JavaScript engine does not thereby become a system shell.

## JavaScript Cells

Code Mode needs an engine that runs model-written programs and exposes registered tools. nanocode vendors [djs](https://github.com/nanocodexyz/nanocode/tree/6ed92be87b3a2f704a7af857a2237b3fccafbb27/crates/patches/djs), then adapts it to the tool-call boundary. The model receives the values a cell emits, not every intermediate value it computes.

[djs originates at Earendil](https://github.com/earendil-works/djs). Its initial commit names Armin Ronacher. nanocode [imported upstream `0e58f62`](https://github.com/nanocodexyz/nanocode/commit/3a668d9949baaaaedaa18ac6bc3e4a191cb422f2), rather than creating the engine from scratch.

One local change [reuses a decoding buffer and lookup table](https://github.com/nanocodexyz/nanocode/commit/a525631653ea9b99640845aae0dfb41f9be3ddf1) when parsing escaped JSON. Tool results often cross that boundary as JSON. The [supporting report](/experiments/djs) preserves the historical instruction counts and test limits, without equating them to a faster completed agent task.

## Bash in Process

The shell is modified [psh](https://github.com/nanocodexyz/nanocode/tree/6ed92be87b3a2f704a7af857a2237b3fccafbb27/crates/patches/psh), not a bundled GNU Bash executable. The [TypeScript adapter](https://github.com/nanocodexyz/nanocode-ts/blob/c9e92eb906d19b958553e2ee85f57319579d4976/src/bash/Bash.ts) supplies a filesystem, environment, command handlers, and optional Python execution. The shell composes those capabilities using Bash-style syntax.

[psh also originates at Earendil](https://github.com/earendil-works/psh), with an initial research commit by Armin Ronacher. nanocode [imported upstream `e5f136e`](https://github.com/nanocodexyz/nanocode/commit/bd841c6d2bd535830cb3872017a525082012f982). Upstream work remains credited to Earendil and its contributors.

The native [in-process adapter](https://github.com/nanocodexyz/nanocode/blob/6ed92be87b3a2f704a7af857a2237b3fccafbb27/crates/integrations/psh-embedded/src/lib.rs) checks whether psh can contain a command before starting it. Separate [loop-compilation changes](https://github.com/nanocodexyz/nanocode/commit/a951e636dbad00e718d43b01127540422409e171) map integer variables to slots. The [supporting report](/experiments/psh) distinguishes standalone native measurements from the shell shipped in WebAssembly.

## Python Without CPython

The later Python runtime embeds [RustPython](https://github.com/RustPython/RustPython), not CPython or Pyodide. The [integration](https://github.com/nanocodexyz/nanocode/blob/6ed92be87b3a2f704a7af857a2237b3fccafbb27/crates/core/python/src/lib.rs) connects the interpreter to host files, imports, resource limits, and compiled extension support. This is more than renaming a Python command.

RustPython is the work of the RustPython Team and contributors. Its earliest commit names Shing Lyu, not a sole author of the interpreter. Python itself and its standard library have separate origins, including Guido van Rossum's work.

nanocode's [import-recovery and installation-order changes](https://github.com/nanocodexyz/nanocode/commit/db0e3a08b569ac98f1f10648446fbaa56b3f07dc) repair interpreter integration. The SDK's [resolver change](https://github.com/nanocodexyz/nanocode-ts/commit/5d0ec7064a766390ca3f788d1caaff92e83f36dd) adds a compatibility dependency and version constraint. The [package and host report](/experiments/python) retains the actual probes, failures, and later Worker experiments.

## One Command

A registered tool can call this host-side code. In Node, the [Bash API](https://github.com/nanocodexyz/nanocode-ts/blob/c9e92eb906d19b958553e2ee85f57319579d4976/src/bash/Bash.ts) accepts a compiled psh module and workspace files. Its [Python command adapter](https://github.com/nanocodexyz/nanocode-ts/blob/c9e92eb906d19b958553e2ee85f57319579d4976/src/bash/internal/commands/python.ts) loads the packaged RustPython module and data.

```ts title="host.ts"
import * as Fs from 'node:fs/promises'
import { Bash } from 'nanocode-ts/bash'

// Load the embedded shell, not a system Bash process.
const psh = await WebAssembly.compile(
  await Fs.readFile(new URL(import.meta.resolve('nanocode-ts/psh.wasm'))),
)
const shell = await Bash.create({
  files: { '/home/user/values.txt': '2\n3\n5\n' },
  psh,
})
// Python reads the same workspace that the shell exposes.
const result = await shell.exec(
  `python3 -c 'from pathlib import Path; print(sum(map(int, Path("values.txt").read_text().split())))'`,
)
console.log(result.stdout)
```

The result is `10`. JavaScript calls the shell, psh dispatches `python3`, and RustPython reads `values.txt` from the shared workspace. No model call or system Python process is involved. Browser and Worker hosts must supply modules and data through their own loading paths.

## Credit and Licenses

Both djs and psh retain Earendil Inc.'s MIT-or-Apache-2.0 license choice: [djs licenses](/experiments/djs#upstream-credit) and [psh licenses](/experiments/psh#upstream-credit). psh's [NOTICE](https://github.com/nanocodexyz/nanocode/blob/6ed92be87b3a2f704a7af857a2237b3fccafbb27/crates/patches/psh/NOTICE) also credits adapted code from brush, oh-my-pi, Rust, uutils, ripgrep, fd, and GoAWK.

RustPython retains its [MIT license](https://github.com/nanocodexyz/nanocode/blob/6ed92be87b3a2f704a7af857a2237b3fccafbb27/crates/patches/rustpython-vm/LICENSE). Bundled Python library code retains [PSF terms](https://github.com/nanocodexyz/nanocode/blob/6ed92be87b3a2f704a7af857a2237b3fccafbb27/crates/patches/rustpython-pylib/Lib/PSF-LICENSE). Scientific packages retain their own notices. The [license inventory](/experiments/evidence/fork-python.json) links those files rather than attributing those libraries to nanocode.

## The Boundary

Embedding removes a requirement for a separate operating-system process. It does not establish complete Bash or JavaScript conformance, CPython compatibility, or support for every scientific package. Host limits still apply. A Node result is not evidence that the same workload fits a Worker or an iOS app.

The useful boundary is the command interface: a tool can run a small program against the workspace without acquiring a machine first. A hand remains available when the command needs capabilities the embedded runtimes do not provide.

- [Code Mode](/experiments/code-mode-is-necessary): Why the model composes tool calls in a program.

- [djs](/experiments/djs): JavaScript provenance and historical instruction measurements.

- [psh](/experiments/psh): Shell provenance, measurements, and artifact boundaries.

- [Python](/experiments/python): Interpreter provenance, package probes, and host limits.
