@strands-agents/shell 0.1.0
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.
- package/LICENSE +175 -0
- package/NOTICE +1 -0
- package/README.md +239 -0
- package/index.d.ts +100 -0
- package/index.js +218 -0
- package/native.d.ts +111 -0
- package/native.js +591 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<div>
|
|
3
|
+
<a href="https://strandsagents.com">
|
|
4
|
+
<img src="https://strandsagents.com/latest/assets/logo-github.svg" alt="Strands Agents" width="55px" height="105px">
|
|
5
|
+
</a>
|
|
6
|
+
</div>
|
|
7
|
+
|
|
8
|
+
<h1>
|
|
9
|
+
Strands Shell
|
|
10
|
+
</h1>
|
|
11
|
+
|
|
12
|
+
<h2>
|
|
13
|
+
Give your agent a shell without giving it the keys to your machine.
|
|
14
|
+
</h2>
|
|
15
|
+
|
|
16
|
+
<div align="center">
|
|
17
|
+
<a href="https://pypi.org/project/strands-shell/"><img alt="Python" src="https://img.shields.io/badge/Python-3.10%2B-blue?logo=python"/></a>
|
|
18
|
+
<a href="https://www.npmjs.com/package/@strands-agents/shell"><img alt="Node" src="https://img.shields.io/badge/Node-18%2B-green?logo=nodedotjs"/></a>
|
|
19
|
+
<a href="#license"><img alt="License" src="https://img.shields.io/badge/License-Apache_2.0-blue"/></a>
|
|
20
|
+
<a href="https://discord.gg/strands"><img alt="Strands Discord" src="https://img.shields.io/badge/Discord-Strands-5865F2?logo=discord&logoColor=white"/></a>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<p>
|
|
24
|
+
<a href="https://strandsagents.com/">Documentation</a>
|
|
25
|
+
◆ <a href="#mcp-server">MCP Server</a>
|
|
26
|
+
◆ <a href="#python">Python</a>
|
|
27
|
+
◆ <a href="#nodejs">Node.js</a>
|
|
28
|
+
</p>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
Agents run shell commands in tight loops: Install deps, run tests, grep for errors, iterate. Those loops need speed and isolation.
|
|
34
|
+
|
|
35
|
+
Strands Shell is a Bourne-compatible shell that runs in-process. `grep`, `sed`, `jq`, `curl`, `find`, 50+ commands and it does this without fork, exec, syscalls, or cold starts. You declare what the agent can reach (files, URLs, credentials) and everything else doesn't exist to the agent.
|
|
36
|
+
|
|
37
|
+
| | Docker | Cloud sandbox | Strands Shell |
|
|
38
|
+
|---|---|---|---|
|
|
39
|
+
| **Cold start** | ~200ms | ~1s (network) | <1ms |
|
|
40
|
+
| **Isolation** | Container namespace | MicroVM | In-process VFS |
|
|
41
|
+
| **Network** | iptables / sidecar | Platform policy | URL allowlist + SSRF guard |
|
|
42
|
+
| **Secrets** | Env vars (agent can read them) | Platform-specific | Injected per-request, agent never sees them |
|
|
43
|
+
| **Setup** | Docker daemon | API key + network | `pip install strands-shell` |
|
|
44
|
+
| **Platforms** | Linux | Cloud-only | macOS, Linux, WASM |
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
### MCP (works with any agent framework)
|
|
49
|
+
|
|
50
|
+
Drop this into your MCP client config:
|
|
51
|
+
|
|
52
|
+
```json
|
|
53
|
+
{
|
|
54
|
+
"mcpServers": {
|
|
55
|
+
"shell": {
|
|
56
|
+
"command": "uvx",
|
|
57
|
+
"args": ["strands-shell", "--mcp"]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
That's it and your agent gets `shell`, `read_file`, `write_file`, `list_dir`. All mediated through the Kernel.
|
|
64
|
+
|
|
65
|
+
### Python
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install strands-shell
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
import strands_shell
|
|
73
|
+
|
|
74
|
+
shell = strands_shell.Shell(
|
|
75
|
+
binds=[strands_shell.Bind("/my/project", "/workspace", mode="copy")],
|
|
76
|
+
credentials=[strands_shell.Cred("https://api.example.com/", env_var="API_TOKEN")],
|
|
77
|
+
allowed_urls=["https://api.example.com/"],
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
out = shell.run("grep -rn TODO /workspace")
|
|
81
|
+
print(out.stdout)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Node.js
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm install @strands-agents/shell
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
import { Shell } from '@strands-agents/shell'
|
|
92
|
+
|
|
93
|
+
const shell = await Shell.create({
|
|
94
|
+
binds: [{ source: '/my/project', destination: '/workspace', mode: 'copy' }],
|
|
95
|
+
})
|
|
96
|
+
const out = await shell.run('grep -rn TODO /workspace')
|
|
97
|
+
console.log(out.stdout)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## How It Works
|
|
101
|
+
|
|
102
|
+
```mermaid
|
|
103
|
+
flowchart TB
|
|
104
|
+
agent["Your agent code\n(Strands, LangGraph, Pydantic AI, etc)"]
|
|
105
|
+
agent -->|"MCP / Python / Node.js"| shell
|
|
106
|
+
|
|
107
|
+
subgraph shell ["Strands Shell"]
|
|
108
|
+
direction TB
|
|
109
|
+
subgraph kernel ["Kernel (mediation boundary)"]
|
|
110
|
+
vfs["VFS: isolated filesystem"]
|
|
111
|
+
net["Network: SSRF guard + allowlist"]
|
|
112
|
+
creds["Credentials: injected per-URL"]
|
|
113
|
+
limits["Limits: timeout, output, fds"]
|
|
114
|
+
end
|
|
115
|
+
engine["Shell engine: parser, 25 builtins, 33 commands, Lua 5.4"]
|
|
116
|
+
end
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Written in Rust, with native bindings for Python (PyO3) and Node.js (napi-rs). State persists across `run()` calls (env vars, working directory, functions). The filesystem is shared.
|
|
120
|
+
|
|
121
|
+
## Configuration
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
shell = strands_shell.Shell(
|
|
125
|
+
binds=[
|
|
126
|
+
strands_shell.Bind("/host/project", "/workspace", mode="copy"),
|
|
127
|
+
strands_shell.Bind("/tmp/output", "/output", mode="direct"),
|
|
128
|
+
],
|
|
129
|
+
credentials=[
|
|
130
|
+
strands_shell.Cred("https://api.example.com/", env_var="API_TOKEN"),
|
|
131
|
+
],
|
|
132
|
+
allowed_urls=["https://api.example.com/", "https://pypi.org/"],
|
|
133
|
+
timeout=30.0,
|
|
134
|
+
env={"PROJECT": "demo"},
|
|
135
|
+
limits=strands_shell.Limits(
|
|
136
|
+
max_output=1 << 20,
|
|
137
|
+
max_file_size=10 << 20,
|
|
138
|
+
),
|
|
139
|
+
)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
> ⚠️ **`mode: "direct"` mounts are live.** The agent can read and modify host files in real time. Use only for designated output directories. Never direct-bind directories containing secrets, credentials, or configuration you don't want the agent to modify.
|
|
143
|
+
|
|
144
|
+
### TOML
|
|
145
|
+
|
|
146
|
+
You can load all of this from a config file instead:
|
|
147
|
+
|
|
148
|
+
```toml
|
|
149
|
+
[[bind]]
|
|
150
|
+
mode = "copy"
|
|
151
|
+
source = "/host/project"
|
|
152
|
+
destination = "/workspace"
|
|
153
|
+
|
|
154
|
+
[[cred]]
|
|
155
|
+
url = "https://api.openai.com/v1/"
|
|
156
|
+
methods = ["POST"]
|
|
157
|
+
kind = "bearer"
|
|
158
|
+
api_key_env = "OPENAI_API_KEY"
|
|
159
|
+
|
|
160
|
+
[[mcp]]
|
|
161
|
+
name = "my-tools"
|
|
162
|
+
command = "/path/to/mcp-server"
|
|
163
|
+
args = ["--stdio"]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## MCP Server
|
|
167
|
+
|
|
168
|
+
The built-in [MCP](https://modelcontextprotocol.io/) server exposes the shell over JSON-RPC on stdio, working with anything that speaks MCP.
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
uvx strands-shell --mcp # bare in-memory sandbox
|
|
172
|
+
uvx strands-shell --config sandbox.toml --mcp # with mounts + credentials
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
If you declare `[[mcp]]` servers in your TOML config, they show up as Lua modules inside the shell. Call `require("my_tools")` and you get a table of the server's tools.
|
|
176
|
+
|
|
177
|
+
## Security Model
|
|
178
|
+
|
|
179
|
+
> **Strands Shell is a mediation layer, not a security sandbox.** It enforces what the agent *should* access via Kernel-mediated deny-by-default. It does NOT protect against: memory-safety exploits in the shell engine itself, timing side-channels, or an attacker who controls the host process. For multi-tenant or adversarial workloads, run each Shell instance inside a container or microVM.
|
|
180
|
+
|
|
181
|
+
The Kernel mediates everything; it runs in the same process as your code, not in a VM. If your threat model is "untrusted tenant running arbitrary code," put Strands Shell inside a container too. For "my agent shouldn't access things I haven't explicitly allowed," the Kernel handles it.
|
|
182
|
+
|
|
183
|
+
**Default-deny. You allowlist what the agent can reach:**
|
|
184
|
+
|
|
185
|
+
- Files: only bound paths exist, everything else is hidden.
|
|
186
|
+
- Network: `curl` blocks private ranges (RFC1918, link-local, loopback, IMDS) by default while letting public URLs pass through. Use `allowed_urls` to permit specific internal hosts.
|
|
187
|
+
- Secrets: the Kernel injects credentials per-URL at request time, ensuring the agent never holds them. The Kernel never re-injects on redirects, even back to the same host.
|
|
188
|
+
- Syscalls: there are none; no `fork`, no `exec` because the shell is pure userspace.
|
|
189
|
+
|
|
190
|
+
If you bypass any of these, report it. See [SECURITY.md](SECURITY.md).
|
|
191
|
+
|
|
192
|
+
**Limits (best-effort):** timeouts, output caps, fd limits, inode limits. These catch runaway agents but won't stop someone actively trying to break out. OS-level isolation for that.
|
|
193
|
+
|
|
194
|
+
**Multi-tenant:** a Shell instance is single-owner. If you're serving multiple agents, create one Shell per session. Construction is cheap (no containers, no VMs, just an in-memory VFS), so spinning up per-request is the intended pattern.
|
|
195
|
+
|
|
196
|
+
### Secure Defaults
|
|
197
|
+
|
|
198
|
+
Out of the box, the shell is an empty sandbox — no files, no network, no credentials. When you grant access, follow least privilege:
|
|
199
|
+
|
|
200
|
+
- **Prefer `mode: "copy"` over `mode: "direct"` for source code.** Copy-on-create isolates the agent from your live files. Use `direct` only for output directories where the agent needs to persist results.
|
|
201
|
+
- **Scope binds narrowly.** Bind `/my/project/src` rather than `/my/project` or `/`. The agent doesn't need your `.git/`, `.env`, or `node_modules/`.
|
|
202
|
+
- **Allowlist URLs explicitly.** Don't use `allowed_urls: ["https://"]` — this disables SSRF protection entirely. List the specific API endpoints the agent needs.
|
|
203
|
+
- **Set timeouts.** The default has no per-command timeout. Set `timeout` to bound runaway commands (30s is reasonable for most agent loops).
|
|
204
|
+
- **Use limits.** Set `max_output` to prevent agents from filling memory with unbounded command output (1MB is a good default).
|
|
205
|
+
|
|
206
|
+
## Commands
|
|
207
|
+
|
|
208
|
+
25 builtins, 33 commands, and a Bourne-compatible shell with pipes, loops, functions, and subshells.
|
|
209
|
+
|
|
210
|
+
The commands agents use constantly: `grep`, `find`, `cat`, `head`, `tail`, `jq` for reading and searching. `sed`, `sort`, `tr`, `cut` for transforming output. `cp`, `mv`, `rm`, `mkdir` for managing files. `curl` for HTTP (SSRF-guarded, credentials auto-injected). `lua` for scripting when shell gets awkward.
|
|
211
|
+
|
|
212
|
+
[COMMANDS.md](COMMANDS.md) has the full inventory with implementation status, supported flags, and known gaps vs GNU coreutils.
|
|
213
|
+
|
|
214
|
+
## File Operations API
|
|
215
|
+
|
|
216
|
+
Read and write files without going through a shell command:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
shell.write_file("/workspace/note.txt", b"hello")
|
|
220
|
+
data = shell.read_file("/workspace/note.txt")
|
|
221
|
+
entries = shell.list_files("/workspace")
|
|
222
|
+
shell.remove_file("/workspace/note.txt")
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Contributing
|
|
226
|
+
|
|
227
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Bug reports and design questions are just as useful as PRs.
|
|
228
|
+
|
|
229
|
+
## Community
|
|
230
|
+
|
|
231
|
+
[Discord](https://discord.com/invite/strands) if you want to talk about it.
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
Apache-2.0
|
|
236
|
+
|
|
237
|
+
## Security
|
|
238
|
+
|
|
239
|
+
If you find a security issue, report it privately instead of opening a public issue. Bypasses of filesystem mediation, SSRF protection, or credential injection qualify. See [SECURITY.md](SECURITY.md).
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @strands-agents/shell — public TypeScript declarations.
|
|
2
|
+
//
|
|
3
|
+
// Hand-authored wrapper types over the napi-generated native binding
|
|
4
|
+
// (see native.d.ts). The customer-facing surface is the config-driven
|
|
5
|
+
// `Shell.create()` plus the typed `ShellError` hierarchy; the fluent
|
|
6
|
+
// builder in native.d.ts is internal.
|
|
7
|
+
|
|
8
|
+
/** Output from a shell command execution. */
|
|
9
|
+
export interface Output {
|
|
10
|
+
status: number
|
|
11
|
+
stdout: string
|
|
12
|
+
stderr: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Metadata about a file or directory in the VFS. */
|
|
16
|
+
export interface FileInfo {
|
|
17
|
+
readonly name: string
|
|
18
|
+
readonly isDir?: boolean
|
|
19
|
+
readonly size?: number
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A bind-mount entry mapping a host path into the VFS. */
|
|
23
|
+
export interface BindConfig {
|
|
24
|
+
source: string
|
|
25
|
+
destination: string
|
|
26
|
+
/** `'direct'` passthrough (default) or `'copy'` build-time snapshot. */
|
|
27
|
+
mode?: 'direct' | 'copy'
|
|
28
|
+
/** Reject writes through this mount. Default false. */
|
|
29
|
+
readonly?: boolean
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A credential injection rule. Exactly one of `token` / `envVar` must be set. */
|
|
33
|
+
export interface CredConfig {
|
|
34
|
+
url: string
|
|
35
|
+
token?: string
|
|
36
|
+
envVar?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Resource caps. Every field is optional and independently defaulted. */
|
|
40
|
+
export interface ShellLimits {
|
|
41
|
+
maxOutput?: number
|
|
42
|
+
maxFileSize?: number
|
|
43
|
+
maxFds?: number
|
|
44
|
+
maxBgJobs?: number
|
|
45
|
+
maxPipeline?: number
|
|
46
|
+
maxInput?: number
|
|
47
|
+
maxInodes?: number
|
|
48
|
+
maxDepth?: number
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Options accepted by `Shell.create()`. All fields optional. */
|
|
52
|
+
export interface ShellConfig {
|
|
53
|
+
binds?: BindConfig[]
|
|
54
|
+
credentials?: CredConfig[]
|
|
55
|
+
allowedUrls?: string[]
|
|
56
|
+
env?: Record<string, string>
|
|
57
|
+
/** File-creation umask. Default 0o022. */
|
|
58
|
+
umask?: number
|
|
59
|
+
/** Per-command wall-clock timeout in seconds. Default 30. */
|
|
60
|
+
timeout?: number
|
|
61
|
+
limits?: ShellLimits
|
|
62
|
+
/** Path to a TOML config file; merges in. */
|
|
63
|
+
configFile?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** errno-style discriminator carried on every {@link ShellError}. */
|
|
67
|
+
export type ShellErrorCode = 'ENOENT' | 'EACCES' | 'EFBIG' | 'EOTHER'
|
|
68
|
+
|
|
69
|
+
/** Base error for file operations. Carries `.path` and `.code`. */
|
|
70
|
+
export declare class ShellError extends Error {
|
|
71
|
+
readonly path: string
|
|
72
|
+
readonly code: ShellErrorCode
|
|
73
|
+
}
|
|
74
|
+
/** A path did not exist. `code === 'ENOENT'`. */
|
|
75
|
+
export declare class NotFoundError extends ShellError {}
|
|
76
|
+
/** A write/remove was blocked — read-only mount or policy. `code === 'EACCES'`. */
|
|
77
|
+
export declare class PermissionDeniedError extends ShellError {}
|
|
78
|
+
/** `maxFileSize` / `maxInodes` exceeded. `code === 'EFBIG'`. */
|
|
79
|
+
export declare class FileTooLargeError extends ShellError {}
|
|
80
|
+
|
|
81
|
+
/** A sandboxed shell environment. */
|
|
82
|
+
export declare class Shell {
|
|
83
|
+
private constructor()
|
|
84
|
+
/** Create a sandboxed shell from a config object. */
|
|
85
|
+
static create(config?: ShellConfig): Promise<Shell>
|
|
86
|
+
/** Run a command and capture output. Resolves even on non-zero exit. */
|
|
87
|
+
run(command: string): Promise<Output>
|
|
88
|
+
/** Set an environment variable (in-process state). */
|
|
89
|
+
setEnv(key: string, value: string): Promise<void>
|
|
90
|
+
/** Get an environment variable. */
|
|
91
|
+
getEnv(key: string): Promise<string | null>
|
|
92
|
+
/** Read a file as raw bytes. Rejects with {@link NotFoundError} if missing. */
|
|
93
|
+
readFile(path: string): Promise<Uint8Array>
|
|
94
|
+
/** Write raw bytes; creates parent dirs (mkdir -p) and truncates. */
|
|
95
|
+
writeFile(path: string, content: Uint8Array): Promise<void>
|
|
96
|
+
/** Remove a file. Rejects with {@link NotFoundError} if missing. */
|
|
97
|
+
removeFile(path: string): Promise<void>
|
|
98
|
+
/** List directory entries as {@link FileInfo} (basenames only). */
|
|
99
|
+
listFiles(path: string): Promise<FileInfo[]>
|
|
100
|
+
}
|