feat(ext/ai): add CoW sandbox for Marqdo-only agent trials

Give agents a capability-capped run path that stages workspace edits until commit, so generated .mq.md can be verified without polluting the real tree.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-10-16 11:11:54 +08:00
1 parent 1bb16dd6db
commit 63bcb882a6
24 files changed
+1483 -2

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
---
title: sandbox CoW — write stays upper until commit
description: >
Readable trial: seed on disk, mutate in session, host tree unchanged,
then commit / discard. Prefer link index over json.get.
import sandbox:ext/ai/sandbox.mq.md
import fs:lib/fs.mq.md
---
# main
Prepare a tiny workspace under this test directory (reset leftovers from prior runs).
**had = fs.exists path="_sbx_cow"**
1. `had`
> fs.remove path="_sbx_cow"
2. *
**_ = 0**
> fs.make_dir path="_sbx_cow"
> fs.write_text path="_sbx_cow/seed.txt" text=seed-lower
**sb = sandbox.open root="_sbx_cow"**
**id = [id](sb)**
Session edits (upper / whiteout only).
> sandbox.write id=`id` path="seed.txt" text=seed-upper
> sandbox.write id=`id` path="new.txt" text=brand-new
> sandbox.remove id=`id` path="seed.txt"
**pending = sandbox.diff id=`id`**
**n = len value=`pending`**
> print text=`n`
Host tree must still show the lower seed; `new.txt` must not exist yet.
**lower = fs.read_text path="_sbx_cow/seed.txt"**
> print text=`lower`
**ex_new = fs.exists path="_sbx_cow/new.txt"**
> print text=`ex_new`
Commit applies upper + whiteout.
> sandbox.commit id=`id`
**after = fs.read_text path="_sbx_cow/new.txt"**
> print text=`after`
**seed_gone = fs.exists path="_sbx_cow/seed.txt"**
> print text=`seed_gone`
Discard must not touch the host.
**sb2 = sandbox.open root="_sbx_cow"**
**id2 = [id](sb2)**
> sandbox.write id=`id2` path="new.txt" text=should-discard
> sandbox.discard id=`id2`
**kept = fs.read_text path="_sbx_cow/new.txt"**
> print text=`kept`
+34
View File
@@ -0,0 +1,34 @@
---
title: sandbox.run — plugin.load denied; inspect lists notes
description: >
Guest that loads a native plugin must fail with unavailable in sandbox.
No json.get chains — link index + a small expect table.
import sandbox:ext/ai/sandbox.mq.md
---
# main
**sb = sandbox.open root="sandbox-fixtures"**
**id = [id](sb)**
**ret = sandbox.run id=`id` path="guest-plugin.mq.md"**
**ok = [ok](ret)**
**err = [error](ret)**
> print text=`ok`
**parts = split value=`err` sep="unavailable in sandbox"**
**hits = len value=`parts`**
1. `hits` > 1
> print text=deny-ok
2. *
> print text=`err`
**info = sandbox.inspect id=`id`**
**notes = [notes](info)**
**nn = len value=`notes`**
1. `nn` > 0
> print text=inspect-ok
2. *
> print text=inspect-missing
> sandbox.discard id=`id`
@@ -0,0 +1,9 @@
---
import json:lib/json.mq.md
---
# main
**m = > json.parse text={"a":1}**
**x = > json.get value=`m` key="a"**
> print text=`x`
@@ -0,0 +1,8 @@
---
import plugin:lib/plugin.mq.md
---
# main
**p = > plugin.native_path name="agent"**
> plugin.load path=`p`
+22
View File
@@ -0,0 +1,22 @@
---
title: sandbox.run — core lib/json inside the trial
description: Guest fixture imports lib/json; print ok and guest stdout via link index.
import sandbox:ext/ai/sandbox.mq.md
---
# main
Open a session on the fixture directory (guest programs live here).
**sb = sandbox.open root="sandbox-fixtures"**
**id = [id](sb)**
Run the guest that imports `lib/json` and prints `1`.
**ret = sandbox.run id=`id` path="guest-json.mq.md"**
**ok = [ok](ret)**
**out = [stdout](ret)**
> print text=`ok`
> print text=`out`
> sandbox.discard id=`id`
+35
View File
@@ -2951,6 +2951,41 @@ fn ext_agent_zero_llm() {
);
}
#[test]
fn ext_ai_sandbox_cow() {
ensure_agent_plugin_built();
assert_out(
"tests/ext/sandbox-cow.mq.md",
"2
seed-lower
False
brand-new
False
brand-new",
);
}
#[test]
fn ext_ai_sandbox_run_lib() {
ensure_agent_plugin_built();
assert_out(
"tests/ext/sandbox-run-lib.mq.md",
"True
1",
);
}
#[test]
fn ext_ai_sandbox_deny() {
ensure_agent_plugin_built();
assert_out(
"tests/ext/sandbox-deny.mq.md",
"False
deny-ok
inspect-ok",
);
}
#[test]
fn ext_llm_named_offline() {
let root = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));