# LocalHand

Run Code Mode cells in the host's own JavaScript runtime.

`LocalHand` implements `RuntimeOptions.remote` without a machine. It speaks the SDK's remote Code Mode protocol in process: the model calls `exec` and `wait`, each cell gets the native cell globals (`tools`, `text`, `image`, `notify`, `store`, `load`, `yield_control`, `exit`, `setTimeout` and the rest), and `tools.<name>()` calls the session's host tools through `options.tools.call`. Open the session with `config.code_mode`; without `options.remote` the runtime creates a default `LocalHand`.

```ts title="code-mode.ts"
import { AgentRuntime, LocalHand } from 'nanocode-wasm'

// Scripts fetch through the host's fetch, such as a paying one
const hand = new LocalHand({ fetch: payingFetch })

await runtime.open(
  { ...config, code_mode: true },
  { dispatch, remote: hand, tools: { call } },
)
```

## Options

### fetch

* **Type:** `typeof fetch`
* **Default:** `globalThis.fetch`

The cell's global `fetch`. The hand passes each request's URL, method, headers and buffered body, so a fetch that pays an HTTP 402 and retries, such as mppx's, can send the body again. Ending a cell aborts its requests.

### evaluate

* **Type:** `CellEvaluator`
* **Default:** `inRealm`

Runs one cell. `inRealm` runs it as an `AsyncFunction` in the host's realm, which browsers, Node, Deno and Bun allow. Cloudflare Workers refuse code generation from strings, so `workerLoader(env.LOADER)` from `nanocode-wasm/cloudflare` runs each cell as its own Dynamic Worker, bound with `worker_loaders` in the Wrangler configuration, with no outbound network except the hand's `fetch`.

```ts
import { LocalHand } from 'nanocode-wasm'
import { workerLoader } from 'nanocode-wasm/cloudflare'

// Inside a Durable Object
const hand = new LocalHand({ evaluate: workerLoader(env.LOADER) })
```

### name

* **Type:** `string`
* **Default:** `'local'`

The name the hand's catalog advertises.

## Behavior

A cell cannot be stopped mid-statement. When `wait` terminates a cell, or the turn or runtime ends, the hand aborts the cell's requests, clears its timers, cancels its pending tool calls and drops its later output; the script runs on until its next await.
