just-bash 2.13.0 → 2.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +300 -314
  2. package/dist/bin/chunks/{chunk-3YMCKZTY.js → chunk-FBJJY4ZV.js} +1 -1
  3. package/dist/bin/chunks/chunk-LIYVQA3X.js +2 -0
  4. package/dist/bin/chunks/{chunk-N6KA6G3Q.js → chunk-TKTKRRAL.js} +1 -1
  5. package/dist/bin/chunks/curl-SRTMGOVV.js +26 -0
  6. package/dist/bin/chunks/{flag-coverage-IRM4GISL.js → flag-coverage-A4G6STMS.js} +1 -1
  7. package/dist/bin/chunks/{js-exec-YGYYZEEQ.js → js-exec-JORCTVUT.js} +1 -1
  8. package/dist/bin/chunks/js-exec-worker.js +1 -0
  9. package/dist/bin/{shell/chunks/python3-WO3WFGMS.js → chunks/python3-PF7AHNQM.js} +1 -1
  10. package/dist/bin/chunks/time-DDS6JJ23.js +2 -0
  11. package/dist/bin/chunks/worker.js +1 -0
  12. package/dist/bin/just-bash.js +178 -178
  13. package/dist/bin/shell/chunks/{chunk-3YMCKZTY.js → chunk-FBJJY4ZV.js} +1 -1
  14. package/dist/bin/shell/chunks/chunk-LIYVQA3X.js +2 -0
  15. package/dist/bin/shell/chunks/{chunk-N6KA6G3Q.js → chunk-TKTKRRAL.js} +1 -1
  16. package/dist/bin/shell/chunks/curl-SRTMGOVV.js +26 -0
  17. package/dist/bin/shell/chunks/{flag-coverage-IRM4GISL.js → flag-coverage-A4G6STMS.js} +1 -1
  18. package/dist/bin/shell/chunks/{js-exec-VYG74FQ3.js → js-exec-B6QNYHUL.js} +1 -1
  19. package/dist/bin/{chunks/python3-EIXZW3LO.js → shell/chunks/python3-J7DP4JBQ.js} +1 -1
  20. package/dist/bin/shell/chunks/time-DDS6JJ23.js +2 -0
  21. package/dist/bin/shell/shell.js +180 -180
  22. package/dist/bundle/browser.js +485 -485
  23. package/dist/bundle/chunks/chunk-CWQS3NFK.js +1 -0
  24. package/dist/bundle/chunks/{chunk-JCMONG3T.js → chunk-F5CMUULS.js} +1 -1
  25. package/dist/bundle/chunks/{chunk-MJWMXCEJ.js → chunk-H2WXJGD7.js} +1 -1
  26. package/dist/bundle/chunks/curl-COE4TZE6.js +25 -0
  27. package/dist/bundle/chunks/{flag-coverage-SPT2DN2I.js → flag-coverage-G2R7PMYU.js} +1 -1
  28. package/dist/bundle/chunks/{js-exec-R2LSP7M4.js → js-exec-YJSMH5AG.js} +1 -1
  29. package/dist/bundle/chunks/js-exec-worker.js +1 -0
  30. package/dist/bundle/chunks/{python3-DH2SBOI3.js → python3-6HF56IYI.js} +1 -1
  31. package/dist/bundle/chunks/{time-FABCOJJU.js → time-YG5BMRIQ.js} +1 -1
  32. package/dist/bundle/chunks/worker.js +1 -0
  33. package/dist/bundle/index.cjs +657 -657
  34. package/dist/bundle/index.js +118 -118
  35. package/dist/commands/curl/types.d.ts +1 -1
  36. package/dist/index.d.cts +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/network/allow-list.d.ts +5 -3
  39. package/dist/network/fetch.d.ts +1 -1
  40. package/dist/network/index.d.ts +1 -1
  41. package/dist/network/types.d.ts +32 -1
  42. package/package.json +2 -2
  43. package/dist/bin/chunks/chunk-QZNF3Y3J.js +0 -2
  44. package/dist/bin/chunks/curl-B64SIJOD.js +0 -26
  45. package/dist/bin/chunks/time-VSKBXRQH.js +0 -2
  46. package/dist/bin/shell/chunks/chunk-QZNF3Y3J.js +0 -2
  47. package/dist/bin/shell/chunks/curl-B64SIJOD.js +0 -26
  48. package/dist/bin/shell/chunks/time-VSKBXRQH.js +0 -2
  49. package/dist/bundle/chunks/chunk-RH6GWZAJ.js +0 -1
  50. package/dist/bundle/chunks/curl-FCIO57JJ.js +0 -25
package/README.md CHANGED
@@ -1,68 +1,108 @@
1
1
  # just-bash
2
2
 
3
- A simulated bash environment with an in-memory virtual filesystem, written in TypeScript.
4
-
5
- Designed for AI agents that need a secure, sandboxed bash environment.
6
-
7
- Supports optional network access via `curl` with secure-by-default URL filtering.
8
-
9
- **Note**: This is beta software. Use at your own risk and please provide feedback.
10
-
11
- ## Table of Contents
12
-
13
- - [Security model](#security-model)
14
- - [Installation](#installation)
15
- - [Usage](#usage)
16
- - [Basic API](#basic-api)
17
- - [Configuration](#configuration)
18
- - [Custom Commands](#custom-commands)
19
- - [Filesystem Options](#filesystem-options)
20
- - [AI SDK Tool](#ai-sdk-tool)
21
- - [Vercel Sandbox Compatible API](#vercel-sandbox-compatible-api)
22
- - [CLI Binary](#cli-binary)
23
- - [Interactive Shell](#interactive-shell)
24
- - [Supported Commands](#supported-commands)
25
- - [Shell Features](#shell-features)
26
- - [Default Layout](#default-layout)
27
- - [Network Access](#network-access)
28
- - [JavaScript Support](#javascript-support)
29
- - [Execution Protection](#execution-protection)
30
- - [AST Transform Plugins](#ast-transform-plugins)
31
- - [Development](#development)
32
-
33
- ## Security model
34
-
35
- - The shell only has access to the provided file system.
36
- - Execution is protected against infinite loops or recursion. However, Bash is not fully robust against DOS from input. If you need to be robust against this, use process isolation at the OS level.
37
- - Binaries or even WASM are inherently unsupported (Use [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox) or a similar product if a full VM is needed).
38
- - There is no network access by default.
39
- - Network access can be enabled, but requests are checked against URL prefix allow-lists and HTTP-method allow-lists. See [network access](#network-access) for details.
40
- - Python and JS execution are off by default as they may represent additional security surface.
41
-
42
- ## Installation
3
+ A virtual bash environment with an in-memory filesystem, written in TypeScript and designed for AI agents.
4
+
5
+ Broad support for standard unix commands and bash syntax with optional curl, Python, JS/TS, and sqlite support.
6
+
7
+ **Note**: This is beta software. Use at your own risk and please provide feedback. See [security model](#security-model).
8
+
9
+ ## Quick Start
43
10
 
44
11
  ```bash
45
12
  npm install just-bash
46
13
  ```
47
14
 
48
- ## Usage
49
-
50
- ### Basic API
51
-
52
15
  ```typescript
53
16
  import { Bash } from "just-bash";
54
17
 
55
- const env = new Bash();
56
- await env.exec('echo "Hello" > greeting.txt');
57
- const result = await env.exec("cat greeting.txt");
18
+ const bash = new Bash();
19
+ await bash.exec('echo "Hello" > greeting.txt');
20
+ const result = await bash.exec("cat greeting.txt");
58
21
  console.log(result.stdout); // "Hello\n"
59
22
  console.log(result.exitCode); // 0
60
- console.log(result.env); // Final environment after execution
61
23
  ```
62
24
 
63
- Each `exec()` is isolated—env vars, functions, and cwd don't persist across calls (filesystem does).
25
+ Each `exec()` call gets its own isolated shell state environment variables, functions, and working directory reset between calls. The **filesystem is shared** across calls, so files written in one `exec()` are visible in the next.
64
26
 
65
- ### Configuration
27
+ ## Custom Commands
28
+
29
+ Extend just-bash with your own TypeScript commands using `defineCommand`:
30
+
31
+ ```typescript
32
+ import { Bash, defineCommand } from "just-bash";
33
+
34
+ const hello = defineCommand("hello", async (args, ctx) => {
35
+ const name = args[0] || "world";
36
+ return { stdout: `Hello, ${name}!\n`, stderr: "", exitCode: 0 };
37
+ });
38
+
39
+ const upper = defineCommand("upper", async (args, ctx) => {
40
+ return { stdout: ctx.stdin.toUpperCase(), stderr: "", exitCode: 0 };
41
+ });
42
+
43
+ const bash = new Bash({ customCommands: [hello, upper] });
44
+
45
+ await bash.exec("hello Alice"); // "Hello, Alice!\n"
46
+ await bash.exec("echo 'test' | upper"); // "TEST\n"
47
+ ```
48
+
49
+ Custom commands receive a `CommandContext` with `fs`, `cwd`, `env`, `stdin`, and `exec` (for subcommands), and work with pipes, redirections, and all shell features.
50
+
51
+ <details>
52
+ <summary><h2>Supported Commands</h2></summary>
53
+
54
+ ### File Operations
55
+
56
+ `cat`, `cp`, `file`, `ln`, `ls`, `mkdir`, `mv`, `readlink`, `rm`, `rmdir`, `split`, `stat`, `touch`, `tree`
57
+
58
+ ### Text Processing
59
+
60
+ `awk`, `base64`, `column`, `comm`, `cut`, `diff`, `expand`, `fold`, `grep` (+ `egrep`, `fgrep`), `head`, `join`, `md5sum`, `nl`, `od`, `paste`, `printf`, `rev`, `rg`, `sed`, `sha1sum`, `sha256sum`, `sort`, `strings`, `tac`, `tail`, `tr`, `unexpand`, `uniq`, `wc`, `xargs`
61
+
62
+ ### Data Processing
63
+
64
+ `jq` (JSON), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
65
+
66
+ ### Optional Runtimes
67
+
68
+ `js-exec` (JavaScript/TypeScript via QuickJS; requires `javascript: true`), `python3`/`python` (Python via CPython; requires `python: true`)
69
+
70
+ ### Compression & Archives
71
+
72
+ `gzip` (+ `gunzip`, `zcat`), `tar`
73
+
74
+ ### Navigation & Environment
75
+
76
+ `basename`, `cd`, `dirname`, `du`, `echo`, `env`, `export`, `find`, `hostname`, `printenv`, `pwd`, `tee`
77
+
78
+ ### Shell Utilities
79
+
80
+ `alias`, `bash`, `chmod`, `clear`, `date`, `expr`, `false`, `help`, `history`, `seq`, `sh`, `sleep`, `time`, `timeout`, `true`, `unalias`, `which`, `whoami`
81
+
82
+ ### Network
83
+
84
+ `curl`, `html-to-markdown` (require [network configuration](#network-access))
85
+
86
+ All commands support `--help` for usage information.
87
+
88
+ ### Shell Features
89
+
90
+ - **Pipes**: `cmd1 | cmd2`
91
+ - **Redirections**: `>`, `>>`, `2>`, `2>&1`, `<`
92
+ - **Command chaining**: `&&`, `||`, `;`
93
+ - **Variables**: `$VAR`, `${VAR}`, `${VAR:-default}`
94
+ - **Positional parameters**: `$1`, `$2`, `$@`, `$#`
95
+ - **Glob patterns**: `*`, `?`, `[...]`
96
+ - **If statements**: `if COND; then CMD; elif COND; then CMD; else CMD; fi`
97
+ - **Functions**: `function name { ... }` or `name() { ... }`
98
+ - **Local variables**: `local VAR=value`
99
+ - **Loops**: `for`, `while`, `until`
100
+ - **Symbolic links**: `ln -s target link`
101
+ - **Hard links**: `ln target link`
102
+
103
+ </details>
104
+
105
+ ## Configuration
66
106
 
67
107
  ```typescript
68
108
  const env = new Bash({
@@ -108,57 +148,25 @@ await env.exec("cat <<EOF\n indented\nEOF", { rawScript: true });
108
148
  | `signal` | `AbortSignal` | Cooperative cancellation; stops at next statement boundary |
109
149
  | `rawScript` | `boolean` | Skip leading-whitespace normalization (default: `false`) |
110
150
 
111
- #### Lazy Files
151
+ ## Filesystem Options
112
152
 
113
- File values can be functions (sync or async). The function is called on first read and the result is cached — if the file is written to before being read, the function is never called:
153
+ Four filesystem implementations:
154
+
155
+ **InMemoryFs** (default) - Pure in-memory filesystem, no disk access:
114
156
 
115
157
  ```typescript
158
+ import { Bash } from "just-bash";
159
+
116
160
  const env = new Bash({
117
161
  files: {
118
- "/data/config.json": () => JSON.stringify({ key: "value" }),
162
+ "/data/config.json": '{"key": "value"}',
163
+ // Lazy: called on first read, cached. Never called if written before read.
164
+ "/data/large.csv": () => "col1,col2\na,b\n",
119
165
  "/data/remote.txt": async () => (await fetch("https://example.com")).text(),
120
- "/data/static.txt": "always loaded",
121
166
  },
122
167
  });
123
168
  ```
124
169
 
125
- This is useful for large or expensive-to-compute content that may not be needed.
126
-
127
- ### Custom Commands
128
-
129
- Extend just-bash with your own TypeScript commands using `defineCommand`:
130
-
131
- ```typescript
132
- import { Bash, defineCommand } from "just-bash";
133
-
134
- const hello = defineCommand("hello", async (args, ctx) => {
135
- const name = args[0] || "world";
136
- return { stdout: `Hello, ${name}!\n`, stderr: "", exitCode: 0 };
137
- });
138
-
139
- const upper = defineCommand("upper", async (args, ctx) => {
140
- return { stdout: ctx.stdin.toUpperCase(), stderr: "", exitCode: 0 };
141
- });
142
-
143
- const bash = new Bash({ customCommands: [hello, upper] });
144
-
145
- await bash.exec("hello Alice"); // "Hello, Alice!\n"
146
- await bash.exec("echo 'test' | upper"); // "TEST\n"
147
- ```
148
-
149
- Custom commands receive the full `CommandContext` with access to `fs`, `cwd`, `env`, `stdin`, and `exec` for running subcommands.
150
-
151
- ### Filesystem Options
152
-
153
- Four filesystem implementations are available:
154
-
155
- **InMemoryFs** (default) - Pure in-memory filesystem, no disk access:
156
-
157
- ```typescript
158
- import { Bash } from "just-bash";
159
- const env = new Bash(); // Uses InMemoryFs by default
160
- ```
161
-
162
170
  **OverlayFs** - Copy-on-write over a real directory. Reads come from disk, writes stay in memory:
163
171
 
164
172
  ```typescript
@@ -172,7 +180,7 @@ await env.exec("cat package.json"); // reads from disk
172
180
  await env.exec('echo "modified" > package.json'); // stays in memory
173
181
  ```
174
182
 
175
- **ReadWriteFs** - Direct read-write access to a real directory. Use this if you want the agent to be agle to write to your disk:
183
+ **ReadWriteFs** - Direct read-write access to a real directory. Use this if you want the agent to be able to write to your disk:
176
184
 
177
185
  ```typescript
178
186
  import { Bash } from "just-bash";
@@ -222,167 +230,11 @@ const fs = new MountableFs({
222
230
  });
223
231
  ```
224
232
 
225
- ### AI SDK Tool
226
-
227
- For AI agents, use [`bash-tool`](https://github.com/vercel-labs/bash-tool) which is optimized for just-bash and provides a ready-to-use [AI SDK](https://ai-sdk.dev/) tool:
228
-
229
- ```bash
230
- npm install bash-tool
231
- ```
232
-
233
- ```typescript
234
- import { createBashTool } from "bash-tool";
235
- import { generateText } from "ai";
236
-
237
- const bashTool = createBashTool({
238
- files: { "/data/users.json": '[{"name": "Alice"}, {"name": "Bob"}]' },
239
- });
240
-
241
- const result = await generateText({
242
- model: "anthropic/claude-sonnet-4",
243
- tools: { bash: bashTool },
244
- prompt: "Count the users in /data/users.json",
245
- });
246
- ```
247
-
248
- See the [bash-tool documentation](https://github.com/vercel-labs/bash-tool) for more details and examples.
249
-
250
- ### Vercel Sandbox Compatible API
251
-
252
- Bash provides a `Sandbox` class that's API-compatible with [`@vercel/sandbox`](https://vercel.com/docs/vercel-sandbox), making it easy to swap implementations. You can start with Bash and switch to a real sandbox when you need the power of a full VM (e.g. to run node, python, or custom binaries).
253
-
254
- ```typescript
255
- import { Sandbox } from "just-bash";
256
-
257
- // Create a sandbox instance
258
- const sandbox = await Sandbox.create({ cwd: "/app" });
259
-
260
- // Write files to the virtual filesystem
261
- await sandbox.writeFiles({
262
- "/app/script.sh": 'echo "Hello World"',
263
- "/app/data.json": '{"key": "value"}',
264
- });
265
-
266
- // Run commands and get results
267
- const cmd = await sandbox.runCommand("bash /app/script.sh");
268
- const output = await cmd.stdout(); // "Hello World\n"
269
- const exitCode = (await cmd.wait()).exitCode; // 0
270
-
271
- // Read files back
272
- const content = await sandbox.readFile("/app/data.json");
273
-
274
- // Create directories
275
- await sandbox.mkDir("/app/logs", { recursive: true });
276
-
277
- // Clean up (no-op for Bash, but API-compatible)
278
- await sandbox.stop();
279
- ```
280
-
281
- ### CLI Binary
282
-
283
- After installing globally (`npm install -g just-bash`), use the `just-bash` command as a secure alternative to `bash` for AI agents:
284
-
285
- ```bash
286
- # Execute inline script
287
- just-bash -c 'ls -la && cat package.json | head -5'
288
-
289
- # Execute with specific project root
290
- just-bash -c 'grep -r "TODO" src/' --root /path/to/project
291
-
292
- # Pipe script from stdin
293
- echo 'find . -name "*.ts" | wc -l' | just-bash
294
-
295
- # Execute a script file
296
- just-bash ./scripts/deploy.sh
297
-
298
- # Get JSON output for programmatic use
299
- just-bash -c 'echo hello' --json
300
- # Output: {"stdout":"hello\n","stderr":"","exitCode":0}
301
- ```
302
-
303
- The CLI uses OverlayFS - reads come from the real filesystem, but all writes stay in memory and are discarded after execution. The project root is mounted at `/home/user/project`.
304
-
305
- Options:
306
-
307
- - `-c <script>` - Execute script from argument
308
- - `--root <path>` - Root directory (default: current directory)
309
- - `--cwd <path>` - Working directory in sandbox
310
- - `-e, --errexit` - Exit on first error
311
- - `--json` - Output as JSON
312
-
313
- ### Interactive Shell
314
-
315
- ```bash
316
- pnpm shell
317
- ```
318
-
319
- The interactive shell has full internet access enabled by default, allowing you to use `curl` to fetch data from any URL. Use `--no-network` to disable this:
320
-
321
- ```bash
322
- pnpm shell --no-network
323
- ```
324
-
325
- ## Supported Commands
326
-
327
- ### File Operations
328
-
329
- `cat`, `cp`, `file`, `ln`, `ls`, `mkdir`, `mv`, `readlink`, `rm`, `rmdir`, `split`, `stat`, `touch`, `tree`
330
-
331
- ### Text Processing
332
-
333
- `awk`, `base64`, `column`, `comm`, `cut`, `diff`, `expand`, `fold`, `grep` (+ `egrep`, `fgrep`), `head`, `join`, `md5sum`, `nl`, `od`, `paste`, `printf`, `rev`, `rg`, `sed`, `sha1sum`, `sha256sum`, `sort`, `strings`, `tac`, `tail`, `tr`, `unexpand`, `uniq`, `wc`, `xargs`
334
-
335
- ### Data Processing
336
-
337
- `jq` (JSON), `js-exec` (JavaScript/TypeScript via QuickJS; requires opt-in), `python3`/`python` (Python via WASM/CPython; requires opt-in), `sqlite3` (SQLite), `xan` (CSV), `yq` (YAML/XML/TOML/CSV)
338
-
339
- ### Compression & Archives
340
-
341
- `gzip` (+ `gunzip`, `zcat`), `tar`
342
-
343
- ### Navigation & Environment
344
-
345
- `basename`, `cd`, `dirname`, `du`, `echo`, `env`, `export`, `find`, `hostname`, `printenv`, `pwd`, `tee`
346
-
347
- ### Shell Utilities
348
-
349
- `alias`, `bash`, `chmod`, `clear`, `date`, `expr`, `false`, `help`, `history`, `seq`, `sh`, `sleep`, `time`, `timeout`, `true`, `unalias`, `which`, `whoami`
350
-
351
- ### Network Commands
352
-
353
- `curl`, `html-to-markdown`
354
-
355
- All commands support `--help` for usage information.
356
-
357
- ## Shell Features
358
-
359
- - **Pipes**: `cmd1 | cmd2`
360
- - **Redirections**: `>`, `>>`, `2>`, `2>&1`, `<`
361
- - **Command chaining**: `&&`, `||`, `;`
362
- - **Variables**: `$VAR`, `${VAR}`, `${VAR:-default}`
363
- - **Positional parameters**: `$1`, `$2`, `$@`, `$#`
364
- - **Glob patterns**: `*`, `?`, `[...]`
365
- - **If statements**: `if COND; then CMD; elif COND; then CMD; else CMD; fi`
366
- - **Functions**: `function name { ... }` or `name() { ... }`
367
- - **Local variables**: `local VAR=value`
368
- - **Loops**: `for`, `while`, `until`
369
- - **Symbolic links**: `ln -s target link`
370
- - **Hard links**: `ln target link`
371
-
372
- ## Default Layout
373
-
374
- When created without options, Bash provides a Unix-like directory structure:
375
-
376
- - `/home/user` - Default working directory (and `$HOME`)
377
- - `/bin` - Contains stubs for all built-in commands
378
- - `/usr/bin` - Additional binary directory
379
- - `/tmp` - Temporary files directory
380
-
381
- Commands can be invoked by path (e.g., `/bin/ls`) or by name.
233
+ ## Optional Capabilities
382
234
 
383
- ## Network Access
235
+ ### Network Access
384
236
 
385
- Network access (and the `curl` command) is disabled by default for security. To enable it, configure the `network` option:
237
+ Network access is disabled by default. Enable it with the `network` option:
386
238
 
387
239
  ```typescript
388
240
  // Allow specific URLs with GET/HEAD only (safest)
@@ -403,6 +255,19 @@ const env = new Bash({
403
255
  },
404
256
  });
405
257
 
258
+ // Inject credentials via header transforms (secrets never enter the sandbox)
259
+ const env = new Bash({
260
+ network: {
261
+ allowedUrlPrefixes: [
262
+ "https://public-api.com", // plain string — no transforms
263
+ {
264
+ url: "https://ai-gateway.vercel.sh",
265
+ transform: [{ headers: { Authorization: "Bearer secret" } }],
266
+ },
267
+ ],
268
+ },
269
+ });
270
+
406
271
  // Allow all URLs and methods (use with caution)
407
272
  const env = new Bash({
408
273
  network: { dangerouslyAllowFullInternetAccess: true },
@@ -411,27 +276,33 @@ const env = new Bash({
411
276
 
412
277
  **Note:** The `curl` command only exists when network is configured. Without network configuration, `curl` returns "command not found".
413
278
 
414
- ## Python Support
279
+ #### Allow-List Security
415
280
 
416
- Python support via WASM/CPython is opt-in due to additional security surface. Enable it explicitly, but be aware of the risk:
281
+ The allow-list enforces:
417
282
 
418
- ```typescript
419
- const env = new Bash({
420
- python: true,
421
- });
283
+ - **Origin matching**: URLs must match the exact origin (scheme + host + port)
284
+ - **Path prefix**: Only paths starting with the specified prefix are allowed
285
+ - **HTTP method restrictions**: Only GET and HEAD by default (configure `allowedMethods` for more)
286
+ - **Redirect protection**: Redirects to non-allowed URLs are blocked
287
+ - **Header transforms**: Firewall headers are injected at the fetch boundary and override any user-supplied headers with the same name, preventing credential substitution from inside the sandbox. Headers are re-evaluated on each redirect so credentials are never leaked to non-transform hosts
422
288
 
423
- // Execute Python code
424
- await env.exec('python3 -c "print(1 + 2)"');
289
+ #### Using curl
425
290
 
426
- // Run Python scripts
427
- await env.exec('python3 script.py');
428
- ```
291
+ ```bash
292
+ # Fetch and process data
293
+ curl -s https://api.example.com/data | grep pattern
429
294
 
430
- **Note:** The `python3` and `python` commands only exist when `python: true` is configured. Python is not available in browser environments.
295
+ # Download and convert HTML to Markdown
296
+ curl -s https://example.com | html-to-markdown
431
297
 
432
- ## JavaScript Support
298
+ # POST JSON data
299
+ curl -X POST -H "Content-Type: application/json" \
300
+ -d '{"key":"value"}' https://api.example.com/endpoint
301
+ ```
302
+
303
+ ### JavaScript Support
433
304
 
434
- JavaScript and TypeScript execution via QuickJS is opt-in due to additional security surface. Enable it with the `javascript` option:
305
+ JavaScript and TypeScript execution via QuickJS is opt-in due to additional security surface. Enable with `javascript: true`:
435
306
 
436
307
  ```typescript
437
308
  const env = new Bash({
@@ -448,9 +319,9 @@ await env.exec('js-exec script.js');
448
319
  await env.exec('js-exec -m -c "import fs from \'fs\'; console.log(fs.readFileSync(\'/data/file.txt\', \'utf8\'))"');
449
320
  ```
450
321
 
451
- ### Bootstrap Code
322
+ #### Bootstrap Code
452
323
 
453
- You can run setup code before every `js-exec` invocation using the `bootstrap` option. This is useful for injecting polyfills, global utilities, or environment setup:
324
+ Run setup code before every `js-exec` invocation with the `bootstrap` option:
454
325
 
455
326
  ```typescript
456
327
  const env = new Bash({
@@ -466,9 +337,9 @@ await env.exec('js-exec -c "console.log(API_BASE)"');
466
337
  // Output: https://api.example.com
467
338
  ```
468
339
 
469
- ### Node.js Compatibility
340
+ #### Node.js Compatibility
470
341
 
471
- `js-exec` provides broad Node.js compatibility. Both `require()` and `import` are supported:
342
+ `js-exec` supports `require()` and `import` with these Node.js modules:
472
343
 
473
344
  - **fs**: `readFileSync`, `writeFileSync`, `readdirSync`, `statSync`, `existsSync`, `mkdirSync`, `rmSync`, `fs.promises.*`
474
345
  - **path**: `join`, `resolve`, `dirname`, `basename`, `extname`, `relative`, `normalize`
@@ -479,11 +350,29 @@ await env.exec('js-exec -c "console.log(API_BASE)"');
479
350
 
480
351
  `fs.readFileSync()` returns a `Buffer` by default (matching Node.js). Pass an encoding like `'utf8'` to get a string.
481
352
 
482
- **Note:** The `js-exec` command only exists when `javascript` is configured. It is not available in browser environments. Execution runs in a QuickJS WASM sandbox with a 64 MB memory limit and configurable timeout (default: 10s, 60s with network). Requires Node.js >= 22.6 (uses `stripTypeScriptTypes` from `node:module`).
353
+ **Note:** The `js-exec` command only exists when `javascript` is configured. It is not available in browser environments. Execution runs in a QuickJS WASM sandbox with a 64 MB memory limit and configurable timeout (default: 10s, 60s with network).
354
+
355
+ ### Python Support
356
+
357
+ Python (CPython compiled to WASM) is opt-in due to additional security surface. Enable with `python: true`:
358
+
359
+ ```typescript
360
+ const env = new Bash({
361
+ python: true,
362
+ });
363
+
364
+ // Execute Python code
365
+ await env.exec('python3 -c "print(1 + 2)"');
366
+
367
+ // Run Python scripts
368
+ await env.exec('python3 script.py');
369
+ ```
483
370
 
484
- ## SQLite Support
371
+ **Note:** The `python3` and `python` commands only exist when `python: true` is configured. Python is not available in browser environments.
372
+
373
+ ### SQLite Support
485
374
 
486
- The `sqlite3` command uses sql.js (WASM-based SQLite) which is fully sandboxed and cannot access the real filesystem:
375
+ `sqlite3` uses sql.js (SQLite compiled to WASM), sandboxed from the real filesystem:
487
376
 
488
377
  ```typescript
489
378
  const env = new Bash();
@@ -497,27 +386,134 @@ await env.exec('sqlite3 data.db "SELECT * FROM users"');
497
386
 
498
387
  **Note:** SQLite is not available in browser environments. Queries run in a worker thread with a configurable timeout (default: 5 seconds) to prevent runaway queries from blocking execution.
499
388
 
500
- ### Allow-List Security
389
+ ## AST Transform Plugins
501
390
 
502
- The allow-list enforces:
391
+ Parse bash scripts into an AST, transform them, and serialize back to bash. Good for instrumenting scripts (e.g., capturing per-command stdout/stderr) or extracting metadata before execution.
503
392
 
504
- - **Origin matching**: URLs must match the exact origin (scheme + host + port)
505
- - **Path prefix**: Only paths starting with the specified prefix are allowed
506
- - **HTTP method restrictions**: Only GET and HEAD by default (configure `allowedMethods` for more)
507
- - **Redirect protection**: Redirects to non-allowed URLs are blocked
393
+ ```typescript
394
+ import { Bash, BashTransformPipeline, TeePlugin, CommandCollectorPlugin } from "just-bash";
508
395
 
509
- ### Using curl
396
+ // Standalone pipeline — output can be run by any shell
397
+ const pipeline = new BashTransformPipeline()
398
+ .use(new TeePlugin({ outputDir: "/tmp/logs" }))
399
+ .use(new CommandCollectorPlugin());
400
+ const result = pipeline.transform("echo hello | grep hello");
401
+ result.script; // transformed bash string
402
+ result.metadata.commands; // ["echo", "grep", "tee"]
403
+
404
+ // Integrated API — exec() auto-applies transforms and returns metadata
405
+ const bash = new Bash();
406
+ bash.registerTransformPlugin(new CommandCollectorPlugin());
407
+ const execResult = await bash.exec("echo hello | grep hello");
408
+ execResult.metadata?.commands; // ["echo", "grep"]
409
+ ```
410
+
411
+ See [src/transform/README.md](src/transform/README.md) for the full API, built-in plugins, and how to write custom plugins.
412
+
413
+ ## Integrations
414
+
415
+ ### AI SDK Tool
416
+
417
+ [`bash-tool`](https://github.com/vercel-labs/bash-tool) wraps just-bash as an [AI SDK](https://ai-sdk.dev/) tool:
510
418
 
511
419
  ```bash
512
- # Fetch and process data
513
- curl -s https://api.example.com/data | grep pattern
420
+ npm install bash-tool
421
+ ```
514
422
 
515
- # Download and convert HTML to Markdown
516
- curl -s https://example.com | html-to-markdown
423
+ ```typescript
424
+ import { createBashTool } from "bash-tool";
425
+ import { generateText } from "ai";
517
426
 
518
- # POST JSON data
519
- curl -X POST -H "Content-Type: application/json" \
520
- -d '{"key":"value"}' https://api.example.com/endpoint
427
+ const bashTool = createBashTool({
428
+ files: { "/data/users.json": '[{"name": "Alice"}, {"name": "Bob"}]' },
429
+ });
430
+
431
+ const result = await generateText({
432
+ model: "anthropic/claude-sonnet-4",
433
+ tools: { bash: bashTool },
434
+ prompt: "Count the users in /data/users.json",
435
+ });
436
+ ```
437
+
438
+ See [bash-tool](https://github.com/vercel-labs/bash-tool) for more.
439
+
440
+ ### Vercel Sandbox Compatible API
441
+
442
+ `Sandbox` is a drop-in replacement for [`@vercel/sandbox`](https://vercel.com/docs/vercel-sandbox) — same API, but runs entirely in-process with the virtual filesystem. Start with just-bash for development and testing, swap in a real sandbox when you need a full VM.
443
+
444
+ ```typescript
445
+ import { Sandbox } from "just-bash";
446
+
447
+ // Create a sandbox instance
448
+ const sandbox = await Sandbox.create({ cwd: "/app" });
449
+
450
+ // Write files to the virtual filesystem
451
+ await sandbox.writeFiles({
452
+ "/app/script.sh": 'echo "Hello World"',
453
+ "/app/data.json": '{"key": "value"}',
454
+ });
455
+
456
+ // Run commands and get results
457
+ const cmd = await sandbox.runCommand("bash /app/script.sh");
458
+ const output = await cmd.stdout(); // "Hello World\n"
459
+ const exitCode = (await cmd.wait()).exitCode; // 0
460
+
461
+ // Read files back
462
+ const content = await sandbox.readFile("/app/data.json");
463
+
464
+ // Create directories
465
+ await sandbox.mkDir("/app/logs", { recursive: true });
466
+
467
+ // Clean up (no-op for Bash, but API-compatible)
468
+ await sandbox.stop();
469
+ ```
470
+
471
+ ## CLI
472
+
473
+ ### CLI Binary
474
+
475
+ Install globally (`npm install -g just-bash`) for a sandboxed CLI:
476
+
477
+ ```bash
478
+ # Execute inline script
479
+ just-bash -c 'ls -la && cat package.json | head -5'
480
+
481
+ # Execute with specific project root
482
+ just-bash -c 'grep -r "TODO" src/' --root /path/to/project
483
+
484
+ # Pipe script from stdin
485
+ echo 'find . -name "*.ts" | wc -l' | just-bash
486
+
487
+ # Execute a script file
488
+ just-bash ./scripts/deploy.sh
489
+
490
+ # Get JSON output for programmatic use
491
+ just-bash -c 'echo hello' --json
492
+ # Output: {"stdout":"hello\n","stderr":"","exitCode":0}
493
+ ```
494
+
495
+ The CLI uses OverlayFS — reads come from the real filesystem, but all writes stay in memory and are discarded after execution.
496
+
497
+ **Important**: The project root is mounted at `/home/user/project`. Use this path (or relative paths from the default cwd) to access your files inside the sandbox.
498
+
499
+ Options:
500
+
501
+ - `-c <script>` - Execute script from argument
502
+ - `--root <path>` - Root directory (default: current directory)
503
+ - `--cwd <path>` - Working directory in sandbox
504
+ - `-e, --errexit` - Exit on first error
505
+ - `--json` - Output as JSON
506
+
507
+ ### Interactive Shell
508
+
509
+ ```bash
510
+ pnpm shell
511
+ ```
512
+
513
+ The interactive shell has full internet access by default. Disable with `--no-network`:
514
+
515
+ ```bash
516
+ pnpm shell --no-network
521
517
  ```
522
518
 
523
519
  ## Execution Protection
@@ -536,45 +532,35 @@ const env = new Bash({
536
532
  });
537
533
  ```
538
534
 
539
- All limits have sensible defaults. Error messages include hints on which limit to increase. Feel free to increase if your scripts intentionally go beyond them.
535
+ All limits have defaults. Error messages tell you which limit was hit. Increase as needed for your workload.
540
536
 
541
- ## AST Transform Plugins
537
+ ## Security Model
542
538
 
543
- Parse bash scripts into an AST, run transform plugins, and serialize back to executable bash. Useful for instrumenting scripts (e.g., capturing per-command stdout/stderr) or analyzing them (e.g., extracting command names) before execution.
539
+ - The shell only has access to the provided filesystem.
540
+ - All execution happens without VM isolation. This does introduce additional risk. The code base was designed to be robust against prototype-pollution attacks and other break outs to the host JS engine and filesystem.
541
+ - There is no network access by default. When enabled, requests are checked against URL prefix allow-lists and HTTP-method allow-lists.
542
+ - Python and JavaScript execution are off by default as they represent additional security surface.
543
+ - Execution is protected against infinite loops and deep recursion with configurable limits.
544
+ - Use [Vercel Sandbox](https://vercel.com/docs/vercel-sandbox) if you need a full VM with arbitrary binary execution.
544
545
 
545
- ```typescript
546
- import { Bash, BashTransformPipeline, TeePlugin, CommandCollectorPlugin } from "just-bash";
546
+ ## Browser Support
547
547
 
548
- // Standalone pipeline output can be run by any shell
549
- const pipeline = new BashTransformPipeline()
550
- .use(new TeePlugin({ outputDir: "/tmp/logs" }))
551
- .use(new CommandCollectorPlugin());
552
- const result = pipeline.transform("echo hello | grep hello");
553
- result.script; // transformed bash string
554
- result.metadata.commands; // ["echo", "grep", "tee"]
548
+ The core shell (parsing, execution, filesystem, and all built-in commands) works in browser environments. The following features require Node.js and are unavailable in browsers: `python3`/`python`, `sqlite3`, `js-exec`, and `OverlayFs`/`ReadWriteFs` (which access the real filesystem).
555
549
 
556
- // Integrated API — exec() auto-applies transforms and returns metadata
557
- const bash = new Bash();
558
- bash.registerTransformPlugin(new CommandCollectorPlugin());
559
- const execResult = await bash.exec("echo hello | grep hello");
560
- execResult.metadata?.commands; // ["echo", "grep"]
561
- ```
550
+ ## Default Layout
562
551
 
563
- See [src/transform/README.md](src/transform/README.md) for the full API, built-in plugins, and how to write custom plugins.
552
+ When created without options, Bash provides a Unix-like directory structure:
564
553
 
565
- ## Development
554
+ - `/home/user` - Default working directory (and `$HOME`)
555
+ - `/bin` - Contains stubs for all built-in commands
556
+ - `/usr/bin` - Additional binary directory
557
+ - `/tmp` - Temporary files directory
566
558
 
567
- ```bash
568
- pnpm test # Run tests in watch mode
569
- pnpm test:run # Run tests once
570
- pnpm typecheck # Type check without emitting
571
- pnpm build # Build TypeScript
572
- pnpm shell # Run interactive shell
573
- ```
559
+ Commands can be invoked by path (e.g., `/bin/ls`) or by name.
574
560
 
575
561
  ## AI Agent Instructions
576
562
 
577
- For AI agents, we recommend using [`bash-tool`](https://github.com/vercel-labs/bash-tool) which is optimized for just-bash and provides additional guidance in its `AGENTS.md`:
563
+ For AI agents, [`bash-tool`](https://github.com/vercel-labs/bash-tool) provides additional guidance in its `AGENTS.md`:
578
564
 
579
565
  ```bash
580
566
  cat node_modules/bash-tool/dist/AGENTS.md