nexo_ai 0.13.0 → 0.15.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +129 -0
- data/docs/durable-workflows.md +15 -5
- data/docs/loops.md +5 -0
- data/docs/mcp.md +75 -0
- data/docs/permissions.md +2 -2
- data/docs/sandboxes.md +83 -7
- data/docs/tools.md +100 -0
- data/lib/nexo/agent.rb +269 -38
- data/lib/nexo/configuration.rb +25 -0
- data/lib/nexo/gated_tool.rb +93 -0
- data/lib/nexo/mcp/credential_store.rb +86 -0
- data/lib/nexo/mcp/gated_tool.rb +10 -58
- data/lib/nexo/mcp.rb +51 -3
- data/lib/nexo/permissions.rb +85 -26
- data/lib/nexo/sandbox.rb +28 -0
- data/lib/nexo/sandbox_file_store.rb +87 -0
- data/lib/nexo/sandboxes/container.rb +1 -1
- data/lib/nexo/sandboxes/container_runner.rb +140 -0
- data/lib/nexo/sandboxes/local.rb +151 -18
- data/lib/nexo/sandboxes/subprocess.rb +62 -0
- data/lib/nexo/sandboxes/virtual.rb +7 -0
- data/lib/nexo/sandboxes.rb +3 -2
- data/lib/nexo/tools/fetch.rb +34 -4
- data/lib/nexo/tools/shell.rb +5 -2
- data/lib/nexo/version.rb +1 -1
- data/lib/nexo/workflow.rb +57 -25
- data/lib/nexo.rb +36 -0
- data/sig/nexo/agent.rbs +6 -1
- data/sig/nexo/permissions.rbs +13 -1
- data/sig/nexo/sandbox.rbs +1 -0
- data/sig/nexo/sandboxes/local.rbs +6 -1
- metadata +6 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d4e02e6148838d856eb464d7105863702c3b004a83b040ad9939d487eb2523d9
|
|
4
|
+
data.tar.gz: d0ed856bdf72315f79335e42ea6e037ca969c97fbc13035109ec81d986f32a81
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 50c7cdcc744e4b47e93816a88dfea4d7b1bcfe6fb7d538d1dc0eac01894b2299b0c06dbb19a0ed5acb4c569f377cc7816c3e74100599a67a3e086cf04e8f6b15
|
|
7
|
+
data.tar.gz: 49e9977881f2ca3fe49a3afbb45e253d945f34da81d624b29a65ab6789d1b22851270dc532f9d59a605aae9eb30d3e9d63cf94b446ba00465399e807f3635b3c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,134 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.15.0] - 2026-11-26
|
|
4
|
+
|
|
5
|
+
Six things taken from ruby_llm 2.2, each behind Nexo's permission gate. Everything new is
|
|
6
|
+
opt-in except one default: a cap on tool calls per round.
|
|
7
|
+
|
|
8
|
+
**Upgrading:** one default changed. A model response may now run at most 20 tool calls;
|
|
9
|
+
the rest are answered with an error and the model can ask again. Raise or remove it with
|
|
10
|
+
`Nexo.config.tool_calls_per_round`. A custom sandbox class is unaffected unless you turn
|
|
11
|
+
on `file_tools :core`, which needs `#files`.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **`Nexo.config.tool_calls_per_round`** (default `20`). `max_turns` counts model responses,
|
|
16
|
+
and one response may hold any number of tool calls, so a round was unbounded. Passed to
|
|
17
|
+
ruby_llm as `with_tool_options(calls:)`.
|
|
18
|
+
- **`context_budget` macro on `Nexo::Agent`**, a per-agent `Chat#with_context_budget`. It
|
|
19
|
+
bounds what any tool returns as a share of the model's context window. Off unless declared.
|
|
20
|
+
- **OAuth for MCP servers.** `mcp ..., oauth: true` (or a Hash of options) hands the server to
|
|
21
|
+
ruby_llm's MCP OAuth. `Agent.new(mcp_owner:)` says whose credentials to use,
|
|
22
|
+
`Agent#mcp_server(name)` exposes the server so a host can drive `authorization_url` /
|
|
23
|
+
`authorize` / `deauthorize`, and `Nexo::AuthorizationRequired` is raised before an
|
|
24
|
+
unauthorized server is used. `Nexo::MCP::CredentialStore` keeps tokens on disk for hosts
|
|
25
|
+
without ActiveRecord (plain JSON, `0600`, not encrypted).
|
|
26
|
+
- **`file_tools :core`.** Attaches ruby_llm's `list_files`, `read_file`, `search_files`,
|
|
27
|
+
`write_file` and `edit_file` over the agent's sandbox through the new
|
|
28
|
+
`Nexo::SandboxFileStore`, each wrapped in `Nexo::GatedTool`. Adds editing part of a file,
|
|
29
|
+
searching contents, and a read-before-write guard that works on every sandbox. Nexo's own
|
|
30
|
+
three tools remain the default until 1.0.
|
|
31
|
+
- **`Sandbox#files` and `#file_size`** on every sandbox (a container or remote sandbox lists
|
|
32
|
+
through its shell).
|
|
33
|
+
- **`Nexo::Sandboxes::ContainerRunner`** answers ruby_llm's sandbox contract with a throwaway,
|
|
34
|
+
hardened container per command. It works as `Sandboxes::Local`'s `isolation:` and as
|
|
35
|
+
`RubyLLM.config.sandbox`.
|
|
36
|
+
- `Nexo::GatedTool` takes `detail:`, a callable naming what a call acts on.
|
|
37
|
+
|
|
38
|
+
### Fixed
|
|
39
|
+
|
|
40
|
+
- **Container reconnect compared a short id with a full one.** The lookup now asks for the
|
|
41
|
+
full id (`ps -aq --no-trunc`). Found by running the reconnect smoke test against Docker for
|
|
42
|
+
the first time.
|
|
43
|
+
|
|
44
|
+
### Verified
|
|
45
|
+
|
|
46
|
+
- The container sandbox and its reconnect path, live against Docker 29 (through OrbStack).
|
|
47
|
+
Both were recorded as unverified since they shipped. Apple `container` parity is still not
|
|
48
|
+
verified.
|
|
49
|
+
- The confined local shell on Linux (Bubblewrap), in CI: a write and a read outside the
|
|
50
|
+
workspace and a network connection are refused.
|
|
51
|
+
- OAuth is tested against ruby_llm's real MCP class but not against a live authorization
|
|
52
|
+
server.
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- `Sandboxes::Local#shell` and `ContainerRunner` share `Sandboxes::Subprocess`, the
|
|
57
|
+
kill-on-timeout runner introduced in 0.14.
|
|
58
|
+
|
|
59
|
+
## [0.14.0] - 2026-11-26
|
|
60
|
+
|
|
61
|
+
A security release. Three guarantees Nexo documented did not hold and now do, and a tool
|
|
62
|
+
you wrote yourself can be gated like Nexo's own.
|
|
63
|
+
|
|
64
|
+
**Upgrading:** four changes can affect a host.
|
|
65
|
+
|
|
66
|
+
1. **The local shell no longer inherits your environment.** If a command an agent runs on
|
|
67
|
+
`sandbox :local` relied on an inherited variable, pass it with `env:`.
|
|
68
|
+
2. **`resume(approved:)` answers one call.** A workflow whose agent makes several gated calls
|
|
69
|
+
now suspends once per distinct call. A host that drove an agent directly with
|
|
70
|
+
`Agent.new(decision:)` is unaffected.
|
|
71
|
+
3. **Under `:read_only`, MCP tools outside `mcp_allow` are no longer attached.** They were
|
|
72
|
+
always denied when called; the model just stops seeing them.
|
|
73
|
+
4. **Tools added by overriding `#chat` now warn once.** Move them to the `tools` macro.
|
|
74
|
+
|
|
75
|
+
### Fixed
|
|
76
|
+
|
|
77
|
+
- **`Sandboxes::Local#shell` leaked the whole process environment.** The documented narrowing
|
|
78
|
+
to `PATH`/`HOME`/`LANG` never happened: those were added on top of an inherited environment,
|
|
79
|
+
so any secret in the host's `ENV` was readable by a model-run command. The child process now
|
|
80
|
+
gets only the narrowed set plus explicit `env:` entries.
|
|
81
|
+
- **A shell timeout did not stop the command.** `Timeout::Error` was raised only after the
|
|
82
|
+
command finished by itself. The command now runs in its own process group, which is killed
|
|
83
|
+
when the timeout fires. `Tools::Shell` returns the timeout to the model as `{error:}` instead
|
|
84
|
+
of failing the run.
|
|
85
|
+
- **One approval approved everything after it.** `Workflow.resume(id, approved: true)` handed
|
|
86
|
+
the re-driven agent a single global decision, so every later `:approve`-gated call in that
|
|
87
|
+
prompt ran without asking; the guide said it would suspend again. Answers are now filed per
|
|
88
|
+
call under the reserved `__approvals__` state key, keyed by capability and detail (and a
|
|
89
|
+
digest of the arguments for MCP tools). A call with no answer suspends.
|
|
90
|
+
- **`sandbox :local, env: {...}`** dropped `env:` in the Hash form. Every option now reaches
|
|
91
|
+
`Sandboxes::Local`.
|
|
92
|
+
- **`Tools::Fetch` failed on hosts whose first address was unreachable.** Only the first
|
|
93
|
+
resolved address was tried, so a host with an IPv6 record failed on a machine with no IPv6
|
|
94
|
+
route. Each vetted address is now tried in turn (up to four), and only on connect errors.
|
|
95
|
+
|
|
96
|
+
### Added
|
|
97
|
+
|
|
98
|
+
- **`tools` macro on `Nexo::Agent`** for tools of your own, with an optional `capability:`.
|
|
99
|
+
A tool declared with one is wrapped in the new `Nexo::GatedTool`, so the agent's permissions
|
|
100
|
+
decide every call, and it is left out of the schema when the mode could never allow it.
|
|
101
|
+
- **`Nexo.config.strict_tools`.** One `around_tool_call` block catches calls to tools Nexo did
|
|
102
|
+
not attach. Default `false`: the call runs and Nexo warns once per tool. `true` refuses it.
|
|
103
|
+
This becomes the default in 1.0.
|
|
104
|
+
- **`isolation: :confined` on `Sandboxes::Local`** runs shell commands in an OS sandbox through
|
|
105
|
+
`ruby_llm`'s sandbox contract (the `mxc` gem, a soft dependency): writes only inside `cwd`,
|
|
106
|
+
no home directory, no network. `readable:` grants extra paths; `isolation:` also accepts an
|
|
107
|
+
`MXC::Sandbox` or any object answering the contract. Verified on macOS; opt-in.
|
|
108
|
+
- **`Sandbox#hardening_gaps`** on every sandbox. `Local` reports an unconfined shell.
|
|
109
|
+
- **`Permissions#decisions`, `#with_decisions`, `::approval_key`, `#never_allows_mcp?`** and
|
|
110
|
+
`Nexo::ApprovalRequired#key`.
|
|
111
|
+
- **Runs execute inside `RubyLLM.workflow`**, so `ruby_llm`'s instrumentation and usage records
|
|
112
|
+
carry the Nexo run id. `checkpoint` and `run_agent` are steps of it. No outcome changes.
|
|
113
|
+
|
|
114
|
+
### Deprecated
|
|
115
|
+
|
|
116
|
+
- `Permissions#decision`, `#with_decision` and `Agent.new(decision:)`: one answer for every
|
|
117
|
+
gated call. `Workflow#run_agent` no longer uses them. Use `decisions:`.
|
|
118
|
+
|
|
119
|
+
### Decided against, for now
|
|
120
|
+
|
|
121
|
+
Recorded so they are not re-litigated without new facts (all read from ruby_llm 2.2.3):
|
|
122
|
+
|
|
123
|
+
- **The permission check did not move into `around_tool_call`.** A skipped call can only give
|
|
124
|
+
the model `"The <name> call did not run."`; the block's return value is ignored. Nexo's
|
|
125
|
+
denial messages cannot travel through it, so the hook is the backstop, not the gate.
|
|
126
|
+
- **`:approve` was not rebuilt on ruby_llm's tool approvals.** Those are durable only with
|
|
127
|
+
`acts_as_chat`; without ActiveRecord the pending state lives in memory. Nexo's approvals
|
|
128
|
+
work with any run store.
|
|
129
|
+
- **`Nexo::Agent` is not a `RubyLLM::Agent` subclass**, and `Session`, `WebSearch`,
|
|
130
|
+
`ReadTracker` and `OutputTruncator` stay: ruby_llm has no plain-Ruby equivalent of them.
|
|
131
|
+
|
|
3
132
|
## [0.13.0] - 2026-11-26
|
|
4
133
|
|
|
5
134
|
Nexo now runs on ruby_llm 2.2. MCP comes from ruby_llm itself, skills need no extra gem,
|
data/docs/durable-workflows.md
CHANGED
|
@@ -132,7 +132,7 @@ class ApprovedWrite < Nexo::Workflow
|
|
|
132
132
|
end
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
The loop is: **`:approve` gate
|
|
135
|
+
The loop is: **`:approve` gate reaches a call nobody has decided → `Nexo::ApprovalRequired` → `run_agent`
|
|
136
136
|
suspends → host renders the pending call → `resume(approved:)` threads the decision back
|
|
137
137
|
through the gate.**
|
|
138
138
|
|
|
@@ -176,10 +176,20 @@ resumed.status # => "done" (the gate allowed the
|
|
|
176
176
|
non-idempotent tool call *before* the approval gate re-runs on resume (agent tool calls
|
|
177
177
|
generally aren't checkpointable). Put approval gates **early**, or after the expensive
|
|
178
178
|
work is already `checkpoint`ed by the workflow.
|
|
179
|
-
- **One
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
in
|
|
179
|
+
- **One answer decides one call.** `resume(approved:)` answers the call recorded under
|
|
180
|
+
`run.state["__approval__"]`, and nothing else. The answer is filed in
|
|
181
|
+
`run.state["__approvals__"]` under that call's key (capability plus path, command or URL; for
|
|
182
|
+
an MCP tool, its name plus a digest of the arguments). A *different* gated call later in the
|
|
183
|
+
same prompt **suspends again**, and the next resume decides it. Before 0.14 the first answer
|
|
184
|
+
silently applied to every later call.
|
|
185
|
+
- **A re-driven model may ask for something else.** Resume runs the prompt again, and nothing
|
|
186
|
+
forces the model to repeat the call you approved. If it writes `b.txt` where it asked for
|
|
187
|
+
`a.txt`, that is a new call and the run suspends for it. This is the safe direction.
|
|
188
|
+
- **`approved:` with nothing pending approves nothing.** An answer is recorded only when a call
|
|
189
|
+
is waiting.
|
|
190
|
+
- **A catch-all tool handler breaks it.** `RubyLLM::Tool.rescue_from StandardError` in the host
|
|
191
|
+
swallows the approval signal, and the call is reported to the model as an error instead of
|
|
192
|
+
suspending the run. Rescue specific classes.
|
|
183
193
|
- **Cross-process approval needs the ActiveRecord store + ActiveJob** (like all durable resume).
|
|
184
194
|
In-process `resume` works with the Memory store; a Memory run does not survive the process.
|
|
185
195
|
- **Branch depends on upstream `ruby_llm`.** This works because `ruby_llm`'s tool loop lets a
|
data/docs/loops.md
CHANGED
|
@@ -49,6 +49,11 @@ end
|
|
|
49
49
|
Inside a workflow the error fails the run like any other (`status: "failed"`, re-raised),
|
|
50
50
|
so a runaway agent cannot keep spending.
|
|
51
51
|
|
|
52
|
+
`max_turns` counts model responses, and one response may ask for any number of tool calls.
|
|
53
|
+
`Nexo.config.tool_calls_per_round` (default `20`) caps how many of them run: calls past the
|
|
54
|
+
cap are answered with an error straight away and never execute. With the defaults a prompt
|
|
55
|
+
is bounded at 25 rounds of 20 calls. Set it to `nil` for no cap.
|
|
56
|
+
|
|
52
57
|
Things to know:
|
|
53
58
|
|
|
54
59
|
- **Upgrading from 0.12:** `max_turns` used to be telemetry only — a run that passed it
|
data/docs/mcp.md
CHANGED
|
@@ -40,6 +40,11 @@ exact-match allow-list threaded into the agent's permissions:
|
|
|
40
40
|
| `:read_only` (default) | allow **only** tool names listed in `mcp_allow`; everything else is denied |
|
|
41
41
|
| `:ask` | call `on_ask.call(:mcp, {tool:, args:})`; a truthy return allows, else deny |
|
|
42
42
|
| `:approve` | names in `mcp_allow` are pre-approved; any other tool needs a human decision — undecided **suspends the run** (`Nexo::ApprovalRequired`), `approved: true` allows, `approved: false` denies (the durable sibling of `:ask`) |
|
|
43
|
+
|
|
44
|
+
Under `:read_only` an MCP tool that is not in `mcp_allow` is not attached at all (0.14): the
|
|
45
|
+
model never sees a tool it could not call. Under `:approve` each call is decided on its own —
|
|
46
|
+
the tool name and its arguments identify it — so approving one `send_email` does not approve
|
|
47
|
+
the next.
|
|
43
48
|
| `:auto` | allow every MCP tool |
|
|
44
49
|
|
|
45
50
|
`mcp_allow` defaults to `[]`, so attaching a powerful server under `:read_only` with no
|
|
@@ -147,6 +152,76 @@ not police `ruby_llm`'s own debug logging (`RUBYLLM_DEBUG`) — that boundary is
|
|
|
147
152
|
> The `mcp` macro and `mcp_allow` are unchanged.
|
|
148
153
|
|
|
149
154
|
|
|
155
|
+
## HTTP servers + OAuth
|
|
156
|
+
|
|
157
|
+
For a server that signs users in — Linear, Slack, Google, your own — pass `oauth:` in place
|
|
158
|
+
of `token:`. `ruby_llm` runs the whole flow (discovery, client registration, PKCE, token
|
|
159
|
+
refresh, DPoP). Nexo adds three things: whose credentials are used, a clear stop before an
|
|
160
|
+
unauthorized server is touched, and somewhere to keep the tokens outside Rails.
|
|
161
|
+
|
|
162
|
+
```ruby
|
|
163
|
+
class Assistant < Nexo::Agent
|
|
164
|
+
model ENV.fetch("NEXO_MODEL")
|
|
165
|
+
mcp :linear, transport: :http, url: "https://mcp.linear.app/mcp", oauth: true
|
|
166
|
+
mcp :slack, transport: :http, url: "https://mcp.slack.com/mcp",
|
|
167
|
+
oauth: {client_id: ENV["SLACK_CLIENT_ID"], client_secret: ENV["SLACK_CLIENT_SECRET"]}
|
|
168
|
+
mcp_allow "list_issues", "search_messages"
|
|
169
|
+
end
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`oauth:` is `true` or a Hash of the options `RubyLLM::MCP.oauth` takes: `client_id:`,
|
|
173
|
+
`client_secret:`, `scopes:`, `grant:`, `private_key:`, `assertion:`, `identity_provider:`,
|
|
174
|
+
`authorization_params:`.
|
|
175
|
+
|
|
176
|
+
**Whose credentials.** Pass the owner when you build the agent:
|
|
177
|
+
|
|
178
|
+
```ruby
|
|
179
|
+
agent = Assistant.new(mcp_owner: current_user)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Credentials are stored per owner and server. The owner must be a record with a GlobalID, or a
|
|
183
|
+
String, Symbol or Integer you keep stable. Anything else is refused, because it would be
|
|
184
|
+
filed under a name that changes every run.
|
|
185
|
+
|
|
186
|
+
**Authorizing.** `agent.mcp_server(name)` is the `ruby_llm` server object. Send the user
|
|
187
|
+
to its authorization URL and hand the callback's parameters back:
|
|
188
|
+
|
|
189
|
+
```ruby
|
|
190
|
+
linear = agent.mcp_server(:linear)
|
|
191
|
+
redirect_to linear.authorization_url(redirect_uri: mcp_callback_url), allow_other_host: true unless linear.authorized?
|
|
192
|
+
|
|
193
|
+
# in the callback action
|
|
194
|
+
Assistant.new(mcp_owner: current_user).mcp_server(:linear).authorize(params)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
`#deauthorize` forgets the owner's credentials.
|
|
198
|
+
|
|
199
|
+
**Before it is authorized.** Building the chat raises `Nexo::AuthorizationRequired`, whose
|
|
200
|
+
`#server` names the one to authorize. It is raised before any request is made, from the
|
|
201
|
+
credential store alone. Servers on the `client_credentials` or JWT-bearer grant need no
|
|
202
|
+
person and fetch their own token on first use.
|
|
203
|
+
|
|
204
|
+
**Where the tokens live.** `ruby_llm` keeps them in memory by default and in an encrypted
|
|
205
|
+
table under Rails (`rails g ruby_llm:install`). For a host with neither, Nexo ships a store
|
|
206
|
+
on disk:
|
|
207
|
+
|
|
208
|
+
```ruby
|
|
209
|
+
RubyLLM.configure do |config|
|
|
210
|
+
config.mcp_credential_store = Nexo::MCP::CredentialStore.new(dir: "~/.local/state/my-app/mcp")
|
|
211
|
+
end
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
⚠️ These files hold live access and refresh tokens as plain JSON. They are not encrypted.
|
|
215
|
+
The directory is created `0700` and each file `0600`, which is the protection an SSH key
|
|
216
|
+
has and no more. Do not put the directory anywhere shared or synced.
|
|
217
|
+
|
|
218
|
+
The permission gate is unchanged by any of this: an OAuth server's tools are still denied
|
|
219
|
+
unless `mcp_allow` lists them, and under `:approve` each call still asks.
|
|
220
|
+
|
|
221
|
+
> Not verified end to end. The settings, the owner key, the authorization check and the
|
|
222
|
+
> store are tested against `ruby_llm`'s real MCP class; a full sign-in against a live
|
|
223
|
+
> authorization server has not been run from Nexo.
|
|
224
|
+
|
|
150
225
|
## Decorating MCP tools
|
|
151
226
|
|
|
152
227
|
`wrap_mcp_tool` is called once per MCP tool, after it is wrapped in a permission-gating
|
data/docs/permissions.md
CHANGED
|
@@ -11,9 +11,9 @@ and the agent loop continues — it does not raise. A path that escapes the work
|
|
|
11
11
|
| `:read_only` (default) | ✅ | ✅ | ❌ not attached ‡ | ❌ not attached ‡ | ❌ not attached ‡ | ❌ not attached ‡ |
|
|
12
12
|
| `:auto` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
13
13
|
| `:ask` | ✅ | ✅ | per `on_ask` | per `on_ask` | per `on_ask` | per `on_ask` |
|
|
14
|
-
| `:approve` | ✅ | ✅ | per
|
|
14
|
+
| `:approve` | ✅ | ✅ | per call | per call | per call | per call |
|
|
15
15
|
| `Virtual` sandbox | ✅ | ✅ | ✅ (in-memory) | ❌ `NotImplementedError`→`{error}` | ✅ † | ✅ † |
|
|
16
|
-
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV)
|
|
16
|
+
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV, unconfined ⚠) | ✅ † | ✅ † |
|
|
17
17
|
| `Container` sandbox | ✅ (guarded) | ✅ | ✅ (guarded, scratch) | ✅ (in container) | ✅ † | ✅ † |
|
|
18
18
|
|
|
19
19
|
`:read`/`:glob` are auto-allowed under **every** mode (they sit in the default
|
data/docs/sandboxes.md
CHANGED
|
@@ -11,9 +11,9 @@ and the agent loop continues — it does not raise. A path that escapes the work
|
|
|
11
11
|
| `:read_only` (default) | ✅ | ✅ | ❌ `{error}` | ❌ `{error}` | ❌ `{error}` | ❌ `{error}` |
|
|
12
12
|
| `:auto` | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
13
13
|
| `:ask` | ✅ | ✅ | per `on_ask` | per `on_ask` | per `on_ask` | per `on_ask` |
|
|
14
|
-
| `:approve` | ✅ | ✅ | per
|
|
14
|
+
| `:approve` | ✅ | ✅ | per call | per call | per call | per call |
|
|
15
15
|
| `Virtual` sandbox | ✅ | ✅ | ✅ (in-memory) | ❌ `NotImplementedError`→`{error}` | ✅ † | ✅ † |
|
|
16
|
-
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV)
|
|
16
|
+
| `Local` sandbox | ✅ (guarded) | ✅ | ✅ (guarded) | ✅ (narrowed ENV, unconfined ⚠) | ✅ † | ✅ † |
|
|
17
17
|
| `Container` sandbox | ✅ (guarded) | ✅ | ✅ (guarded, scratch) | ✅ (in container) | ✅ † | ✅ † |
|
|
18
18
|
|
|
19
19
|
`:read`/`:glob` are auto-allowed under **every** mode (they sit in the default
|
|
@@ -26,10 +26,11 @@ only by the capability gate above plus `fetch_allow` / the injected backend.
|
|
|
26
26
|
- **`Virtual`** (default) — in-memory, zero host access. `#shell` raises
|
|
27
27
|
`NotImplementedError` on purpose: in-memory means no command execution. That is the
|
|
28
28
|
safety property, not a gap.
|
|
29
|
-
- **`Local`** — host filesystem + shell, for trusted dev/CI.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
- **`Local`** — host filesystem + shell, for trusted dev/CI. Every file path is expanded
|
|
30
|
+
against `cwd` and must stay inside it (else `SecurityError`). The shell sees only `PATH`,
|
|
31
|
+
`HOME`, `LANG` (plus explicit `env:` additions), and a command that outlives its timeout is
|
|
32
|
+
killed with everything it started. ⚠ The path guard does not cover what a shell command
|
|
33
|
+
touches: see [Confining the local shell](#confining-the-local-shell).
|
|
33
34
|
- **`Container`** — run the tools inside a throwaway local container via the `docker`
|
|
34
35
|
(default) or Apple `container` CLI. Shell-out only, no client gem. **Hardened by default**
|
|
35
36
|
(no network, dropped caps, read-only rootfs + ephemeral scratch, read-only host binds);
|
|
@@ -38,6 +39,81 @@ only by the capability gate above plus `fetch_allow` / the injected backend.
|
|
|
38
39
|
your own) by injecting a client. Escalating to `:remote` is always an explicit choice in
|
|
39
40
|
your code — the default stays `:virtual`.
|
|
40
41
|
|
|
42
|
+
## Confining the local shell
|
|
43
|
+
|
|
44
|
+
On `:local`, `read`/`write`/`glob` are guarded to `cwd`. A shell command is not: it is a host
|
|
45
|
+
process that can read and write wherever your user can, and reach the network. `#hardening_gaps`
|
|
46
|
+
says so, so a host can show it before trusting the sandbox with a model:
|
|
47
|
+
|
|
48
|
+
```ruby
|
|
49
|
+
Nexo::Sandboxes::Local.new(cwd: dir).hardening_gaps
|
|
50
|
+
# => ["shell commands are not confined: they can read and write outside /path and reach the network …"]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`isolation: :confined` runs every command inside an OS sandbox — Seatbelt on macOS, Bubblewrap
|
|
54
|
+
on Linux — through `ruby_llm`'s sandbox contract. A confined command can write only inside
|
|
55
|
+
`cwd`, cannot read your home directory, and has no network:
|
|
56
|
+
|
|
57
|
+
```ruby
|
|
58
|
+
# Gemfile
|
|
59
|
+
gem "mxc" # a soft dependency: Nexo loads it only for a confined shell
|
|
60
|
+
|
|
61
|
+
class Builder < Nexo::Agent
|
|
62
|
+
sandbox :local, isolation: :confined, readable: [RbConfig::CONFIG["prefix"]]
|
|
63
|
+
permissions Nexo::Permissions.new(mode: :read_only, allow: %i[read glob write shell])
|
|
64
|
+
end
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Things to know:
|
|
68
|
+
|
|
69
|
+
- **A confined command cannot read outside `cwd` either.** That includes a Ruby, Node or Python
|
|
70
|
+
installed under your home directory: `ruby` starts but cannot load its gems. Grant the
|
|
71
|
+
toolchain with `readable:`. Tools that link Homebrew libraries need those paths too.
|
|
72
|
+
- **It never falls back.** If the sandbox cannot run on the machine, the first `shell` raises
|
|
73
|
+
`Nexo::ConfigurationError` with the reason. A missing `mxc` gem raises
|
|
74
|
+
`Nexo::MissingDependencyError`.
|
|
75
|
+
- **Bring your own policy.** `isolation:` also takes an `MXC::Sandbox` class or instance, or any
|
|
76
|
+
object answering `supported?` and `run(*command, timeout:, readable:, writable:, directory:,
|
|
77
|
+
env:, network:)`.
|
|
78
|
+
- **Verified on macOS (Seatbelt) and on Linux (Bubblewrap, in CI), `mxc` 0.4.1:** a write
|
|
79
|
+
outside `cwd`, a read of a file outside it and a network connection were all refused. A
|
|
80
|
+
Linux host must allow unprivileged user namespaces for Bubblewrap; GitHub's Ubuntu runners
|
|
81
|
+
do.
|
|
82
|
+
- Unconfined remains the default in 0.14. Use a [container](#container-sandbox--docker--apple-container)
|
|
83
|
+
when you need a different filesystem, not only a fence.
|
|
84
|
+
|
|
85
|
+
### A container per command — `ContainerRunner`
|
|
86
|
+
|
|
87
|
+
`Nexo::Sandboxes::ContainerRunner` answers the same contract with a throwaway container
|
|
88
|
+
for each command, hardened like the container sandbox (no network, capabilities dropped,
|
|
89
|
+
read-only root). Use it where a process sandbox is not available or not enough:
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
runner = Nexo::Sandboxes::ContainerRunner.new(image: "ruby:3.3-slim")
|
|
93
|
+
|
|
94
|
+
class Builder < Nexo::Agent
|
|
95
|
+
sandbox :local, isolation: runner # files on the host, commands in a container
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
RubyLLM.configure { |config| config.sandbox = runner } # or for ruby_llm's own run_code
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The working directory is bound into the container at its own path, read-write, and nothing
|
|
102
|
+
else of the host is visible. Each command pays a container start. It cannot honour a host
|
|
103
|
+
allow-list: every run has the network the runner was built with, none by default. Verified
|
|
104
|
+
on Docker 29: a command wrote inside the workspace, could not read a file outside it, had
|
|
105
|
+
no network, and was killed at its timeout.
|
|
106
|
+
|
|
107
|
+
### Two fixes in 0.14 that change behaviour
|
|
108
|
+
|
|
109
|
+
- **The narrowed environment is now real.** Before 0.14 the shell inherited the whole process
|
|
110
|
+
environment, API keys included; the `PATH`/`HOME`/`LANG` list was only added on top. A command
|
|
111
|
+
that relied on an inherited variable now needs it passed with `env:`
|
|
112
|
+
(`sandbox :local, env: {"BUNDLE_GEMFILE" => "..."}`).
|
|
113
|
+
- **A timeout now stops the command.** Before 0.14 `Timeout::Error` was raised only after the
|
|
114
|
+
command had finished on its own. Now the command's whole process group is killed, and the
|
|
115
|
+
`Shell` tool reports the timeout to the model as `{error: ...}` instead of failing the run.
|
|
116
|
+
|
|
41
117
|
## Safety refinements — safer, more legible real-FS sandboxes
|
|
42
118
|
|
|
43
119
|
Five small refinements tighten the real-filesystem sandboxes (`Local`, `Container`) and make
|
|
@@ -364,7 +440,7 @@ The container starts **lazily** on first tool use and its id is memoized.
|
|
|
364
440
|
`Workflow.execute`'s `ensure` (on done, suspended, or failed), never per `run_agent` call.
|
|
365
441
|
- **Reconnect (`name:` + `reconnect: true`):** every container is tagged at `run` with an
|
|
366
442
|
**exact identity label** — `--label nexo.sandbox.id=<name>`. On start the sandbox looks up
|
|
367
|
-
that container by the **exact label filter** (`docker ps -
|
|
443
|
+
that container by the **exact label filter** (`docker ps -aq --no-trunc -f label=nexo.sandbox.id=<name>`),
|
|
368
444
|
**not** a name substring, and reuses/restarts it instead of creating a new one; `close`
|
|
369
445
|
leaves it running/stopped so a later sandbox with the same name reattaches. The default
|
|
370
446
|
container name is `nexo-<run-id>`.
|
data/docs/tools.md
CHANGED
|
@@ -15,9 +15,26 @@ ever allow:
|
|
|
15
15
|
neither `WriteFile` nor `Shell` is attached. `:auto`, `:ask` and `:approve` decide per call
|
|
16
16
|
and always attach — `:approve` in particular *must* reach the gate so it can suspend the run.
|
|
17
17
|
|
|
18
|
+
The same rule covers a host tool declared with `capability:` and, since 0.14, an MCP tool:
|
|
19
|
+
under `:read_only` one that is not in `mcp_allow` is not attached.
|
|
20
|
+
|
|
18
21
|
`ReadFile` and `Glob` are always attached. This is a cost and description-accuracy measure, not
|
|
19
22
|
a security boundary: `Permissions#authorize!` remains the gate and still denies at call time.
|
|
20
23
|
|
|
24
|
+
To bound what **any** tool returns — an MCP tool, one of your own — declare a context
|
|
25
|
+
budget. It is `ruby_llm`'s `with_context_budget`, per agent:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
class Researcher < Nexo::Agent
|
|
29
|
+
context_budget per_result: 0.25, per_request: 0.7
|
|
30
|
+
end
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`per_result:` cuts a single result longer than that share of the model's context window;
|
|
34
|
+
`per_request:` leaves the oldest results out of a request that would exceed its share. Both
|
|
35
|
+
need the window, which `ruby_llm` knows only for models in its registry: for a local or
|
|
36
|
+
unregistered model add `window: 128_000`, or the budget does nothing.
|
|
37
|
+
|
|
21
38
|
`Shell` truncates unbounded command output before it reaches the model:
|
|
22
39
|
|
|
23
40
|
- **Shell output truncation (`Nexo::OutputTruncator`).** Unbounded command output (`npm install`,
|
|
@@ -41,6 +58,89 @@ ever allow:
|
|
|
41
58
|
the stale check (read-before-write is the primary guard). Clobber-safety within a session only —
|
|
42
59
|
no versioning, locking, or VCS semantics.
|
|
43
60
|
|
|
61
|
+
## `file_tools :core` — `ruby_llm`'s file tools over your sandbox
|
|
62
|
+
|
|
63
|
+
`ruby_llm` 2.2 has its own file tools. Nexo can attach those in place of its own three,
|
|
64
|
+
over the same sandbox and behind the same permission gate:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
class Editor < Nexo::Agent
|
|
68
|
+
sandbox :local
|
|
69
|
+
file_tools :core
|
|
70
|
+
permissions Nexo::Permissions.new(mode: :read_only, allow: %i[read glob write])
|
|
71
|
+
end
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
| | `:nexo` (default) | `:core` |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| Tools | `read_file`, `write_file`, `glob` (as `nexo--tools--…`) | `list_files`, `read_file`, `search_files`, `write_file`, `edit_file` |
|
|
77
|
+
| Change part of a file | no, rewrite the whole file | yes, `edit_file` |
|
|
78
|
+
| Search file contents | no | yes, `search_files` |
|
|
79
|
+
| Read-before-write guard | by modification time, real filesystems only | by content digest, on every sandbox including `:virtual` |
|
|
80
|
+
| Large files | whole file, capped at 200 KB | paged: 1,000 lines or 20,000 characters a call |
|
|
81
|
+
| Dotfiles | listed | hidden |
|
|
82
|
+
|
|
83
|
+
Reading, listing and searching are `:read`; writing and editing are `:write`, and under
|
|
84
|
+
`:read_only` the two writing tools are not attached. Under `:approve`, a write suspends the
|
|
85
|
+
run with the file's path as the detail.
|
|
86
|
+
|
|
87
|
+
Things to know before switching:
|
|
88
|
+
|
|
89
|
+
- **The tool names and result shapes differ.** A skill that names `nexo--tools--write_file`,
|
|
90
|
+
or a host that reads tool events, needs updating.
|
|
91
|
+
- **Listing goes through the sandbox.** `:virtual` and `:local` answer directly. A container
|
|
92
|
+
or remote sandbox runs one `find`, and reads each file to report its size.
|
|
93
|
+
- **There is no delete**, because a sandbox has none.
|
|
94
|
+
- The tool classes are internal to `ruby_llm`; Nexo's tests drive them through the real
|
|
95
|
+
loop, which is what will catch a change there.
|
|
96
|
+
|
|
97
|
+
Set `Nexo.config.file_tools = :core` to switch every agent. `:core` is planned as the
|
|
98
|
+
default in 1.0.
|
|
99
|
+
|
|
100
|
+
## Tools of your own — the `tools` macro
|
|
101
|
+
|
|
102
|
+
Declare a `RubyLLM::Tool` you wrote on the agent, and say what it does in Nexo's terms:
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
class Archivist < Nexo::Agent
|
|
106
|
+
model ENV.fetch("NEXO_MODEL")
|
|
107
|
+
|
|
108
|
+
tools Today, SumPayments # no side effects: no gate
|
|
109
|
+
tools ArchiveRun, capability: :write # gated exactly like WriteFile
|
|
110
|
+
tools ->(agent) { Lookup.new(root: agent.cwd) }
|
|
111
|
+
end
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Each entry is a tool class (built with no arguments), an instance, or a lambda that takes the
|
|
115
|
+
agent and returns a tool or an Array of tools. The macro accumulates and is inherited.
|
|
116
|
+
|
|
117
|
+
With `capability:` (`:read`, `:write`, `:shell`, `:fetch` or `:search`) the tool is wrapped in
|
|
118
|
+
`Nexo::GatedTool`, and the agent's permissions decide every call the same way they do for Nexo's
|
|
119
|
+
own tools: refused under `:read_only`, put to `on_ask` under `:ask`, suspended under `:approve`.
|
|
120
|
+
A denied call returns `{error: ...}` and the tool body never runs. A gated tool the mode can never
|
|
121
|
+
allow is left out of the schema. The detail your `on_ask`/`ask_when` hook receives is the tool
|
|
122
|
+
name followed by its arguments as JSON.
|
|
123
|
+
|
|
124
|
+
Without `capability:` the tool runs ungated. That is right only for a tool with no side effects.
|
|
125
|
+
|
|
126
|
+
### `strict_tools` — refuse what was never declared
|
|
127
|
+
|
|
128
|
+
A tool added to the chat any other way — typically by overriding `#chat` and calling
|
|
129
|
+
`with_tools` — is one no permission gate ever saw. Nexo catches those calls with a single
|
|
130
|
+
`around_tool_call` block:
|
|
131
|
+
|
|
132
|
+
- By default the call runs and Nexo warns once per tool name.
|
|
133
|
+
- With `Nexo.config.strict_tools = true` the call is refused, and the model is told the call did
|
|
134
|
+
not run.
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
Nexo.configure { |config| config.strict_tools = true }
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Declare your tools with the macro and turn this on. It becomes the default in 1.0. The block is a
|
|
141
|
+
backstop, not the gate: a refused call can only carry `ruby_llm`'s fixed "did not run" text, so
|
|
142
|
+
the gate that explains itself stays with the tool.
|
|
143
|
+
|
|
44
144
|
These are sandbox refinements as much as tool behavior — see [Sandboxes](sandboxes.md) for the
|
|
45
145
|
guard details behind each capability. The `fetch` tool for reading the web lives in
|
|
46
146
|
[Web](web.md), gated by its own `:fetch` capability plus a host allow-list.
|