E0-3/E0-4 groundwork: provider options, pinned docs, Track A/B in the protocol
- providers: per-model request extras (e.g. reasoning_effort), key_env, token_param (max_completion_tokens on api.openai.com); recorded - docs pinned to the toolchain being run: Rust offline docs from the sysroot, Zig langref and std source of the same installation; several mounts under a read-only /docs; hashes recorded (cached for big trees) - protocol: neutral model labels and calibration before classes (§2); smoke gates, fixed Aji commit, fixed per-model reasoning mode, slope of degradation (§39a); Track A controlled vs Track B native agents (§39b) - plan: E-C calibration, E-G gates, E-N native-agent run
This commit is contained in:
1 parent
b49003bdb9
commit
d7bb9273f3
14 files changed
+250
-60
No files matched your search
@@ -75,11 +75,20 @@ class Agent:
|
||||
if not self.docs:
|
||||
raise ToolError("no documentation is mounted")
|
||||
rel = p[len("/docs"):].lstrip("/")
|
||||
if os.path.isfile(self.docs):
|
||||
if rel not in ("", os.path.basename(self.docs)):
|
||||
if len(self.docs) == 1 and self.docs[0][0] == "":
|
||||
base, kind = self.docs[0][1], "documentation"
|
||||
else:
|
||||
if rel == "":
|
||||
raise ToolError("/docs is a directory")
|
||||
head, _, rest = rel.partition("/")
|
||||
match = [m for m in self.docs if m[0] == head]
|
||||
if not match:
|
||||
raise ToolError(f"no such file: {p}")
|
||||
return self.docs, "documentation"
|
||||
base, kind = self.docs, "documentation"
|
||||
if os.path.isfile(match[0][1]):
|
||||
if rest:
|
||||
raise ToolError(f"no such file: {p}")
|
||||
return match[0][1], "documentation"
|
||||
base, rel, kind = match[0][1], rest, "documentation"
|
||||
else:
|
||||
raise ToolError("paths must be under /work or /docs")
|
||||
full = os.path.realpath(os.path.join(base, rel))
|
||||
@@ -90,11 +99,17 @@ class Agent:
|
||||
# ---------------------------------------------------------------- tools
|
||||
|
||||
def tool_list_files(self, inp):
|
||||
path = os.path.normpath(inp.get("path") or "/work")
|
||||
if path == "/docs" and self.docs and not (len(self.docs) == 1 and self.docs[0][0] == ""):
|
||||
return "\n".join("/docs/" + n for n, _ in self.docs)
|
||||
full, kind = self.host_path(inp.get("path"))
|
||||
if os.path.isfile(full):
|
||||
return os.path.basename(full)
|
||||
root_virtual = "/docs" if kind == "documentation" else "/work"
|
||||
base = self.docs if kind == "documentation" else self.workspace
|
||||
root_virtual, base = "/work", self.workspace
|
||||
if kind == "documentation":
|
||||
for n, p in self.docs:
|
||||
if full == p or full.startswith(p + os.sep):
|
||||
root_virtual, base = ("/docs/" + n if n else "/docs"), p
|
||||
out = []
|
||||
for root, dirs, files in os.walk(full):
|
||||
dirs[:] = sorted(d for d in dirs if d not in (".git", "target", "zig-cache", ".zig-cache", "zig-out"))
|
||||
|
||||
@@ -30,7 +30,8 @@ def cmd_run(a):
|
||||
run_dir, rec = record.run_one(
|
||||
a.task, a.language, a.provider, a.model, a.out, model_class=a.model_class, seed=a.seed, sandbox_kind=a.sandbox,
|
||||
evaluator=shlex.split(a.evaluator) if a.evaluator else None, evaluator_hash_path=a.evaluator_hash_path,
|
||||
pricing=load_pricing(a.pricing), base_url=a.base_url, max_tokens=a.max_tokens, temperature=a.temperature)
|
||||
pricing=load_pricing(a.pricing), base_url=a.base_url, max_tokens=a.max_tokens, temperature=a.temperature,
|
||||
provider_options={k: v for k, v in {"extra": json.loads(a.extra) if a.extra else None, "key_env": a.key_env, "token_param": a.token_param}.items() if v})
|
||||
m = rec["metrics"]
|
||||
print(json.dumps({"run": run_dir, "termination": m["termination"], "accepted": rec["accepted"], "tool_calls": m["tool_calls"],
|
||||
"input_tokens": m["input_tokens"], "output_tokens": m["output_tokens"], "cost_usd": rec["cost_usd"]}))
|
||||
@@ -64,7 +65,8 @@ def cmd_matrix(a):
|
||||
tpath, lang, mdl["provider"], mdl["model"], out, model_class=mdl.get("class"), seed=seed,
|
||||
sandbox_kind=plan.get("sandbox", "bwrap"), evaluator=evaluator, evaluator_hash_path=hash_path,
|
||||
pricing=pricing, base_url=mdl.get("base_url"), max_tokens=mdl.get("max_tokens", 8192), temperature=mdl.get("temperature"),
|
||||
limits=plan.get("limits"))
|
||||
limits=plan.get("limits"),
|
||||
provider_options={k: mdl[k] for k in ("extra", "key_env", "token_param") if k in mdl})
|
||||
print(f" -> {rec['metrics']['termination']}, accepted={rec['accepted']}", file=sys.stderr)
|
||||
report.print_report([out])
|
||||
|
||||
@@ -96,6 +98,9 @@ def main(argv=None):
|
||||
r.add_argument("--base-url")
|
||||
r.add_argument("--max-tokens", type=int, default=8192)
|
||||
r.add_argument("--temperature", type=float)
|
||||
r.add_argument("--extra", help='JSON merged into every request body, e.g. {"reasoning_effort": "medium"}')
|
||||
r.add_argument("--key-env", help="name of the environment variable holding the API key (openai provider)")
|
||||
r.add_argument("--token-param", help="max_tokens or max_completion_tokens (openai provider)")
|
||||
r.set_defaults(fn=cmd_run)
|
||||
|
||||
m = sub.add_parser("matrix", help="run every cell of a plan file (resumable)")
|
||||
|
||||
@@ -87,11 +87,32 @@ def versions(prof, env=None):
|
||||
return out
|
||||
|
||||
|
||||
def docs_path(prof):
|
||||
def docs_mounts(prof):
|
||||
"""Documentation mounted under /docs, as [(name, host path)]; name ""
|
||||
means the directory is /docs itself. The environment variable wins;
|
||||
otherwise `default`, or `from_toolchain` (paths relative to the bound
|
||||
toolchain directory, so the documentation always matches the compiler
|
||||
being run; each is mounted as /docs/<last path component>)."""
|
||||
d = prof.get("docs") or {}
|
||||
path = os.environ.get(d.get("env", ""), "") or d.get("default", "")
|
||||
path = expand(path) if path else ""
|
||||
return path if path and os.path.exists(path) else None
|
||||
path = os.environ.get(d.get("env", ""), "") or (expand(d["default"]) if d.get("default") else "")
|
||||
if path:
|
||||
if not os.path.exists(path):
|
||||
return []
|
||||
return [("", path)] if os.path.isdir(path) else [(os.path.basename(path), path)]
|
||||
rels = d.get("from_toolchain") or []
|
||||
if isinstance(rels, str):
|
||||
rels = [rels]
|
||||
if not rels:
|
||||
return []
|
||||
_, binds = resolve_binaries(prof)
|
||||
out = []
|
||||
for rel in rels:
|
||||
for b in binds:
|
||||
cand = os.path.join(b, rel)
|
||||
if os.path.exists(cand):
|
||||
out.append((os.path.basename(rel.rstrip("/")), cand))
|
||||
break
|
||||
return out
|
||||
|
||||
|
||||
def classify(prof, command):
|
||||
|
||||
@@ -50,15 +50,16 @@ def _post(url, headers, body, timeout, retries=4):
|
||||
class Anthropic:
|
||||
name = "anthropic"
|
||||
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600):
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600, extra=None, **_):
|
||||
self.model, self.max_tokens, self.temperature, self.timeout = model, max_tokens, temperature, timeout
|
||||
self.extra = dict(extra or {})
|
||||
self.url = (base_url or "https://api.anthropic.com") + "/v1/messages"
|
||||
self.key = os.environ.get("ANTHROPIC_API_KEY")
|
||||
if not self.key:
|
||||
raise SystemExit("ANTHROPIC_API_KEY is not set")
|
||||
|
||||
def params(self):
|
||||
return {"max_tokens": self.max_tokens, "temperature": self.temperature}
|
||||
return {"max_tokens": self.max_tokens, "temperature": self.temperature, "extra": self.extra}
|
||||
|
||||
def complete(self, system, messages, tools):
|
||||
msgs = []
|
||||
@@ -81,6 +82,7 @@ class Anthropic:
|
||||
}
|
||||
if self.temperature is not None:
|
||||
body["temperature"] = self.temperature
|
||||
body.update(self.extra)
|
||||
r = _post(self.url, {"x-api-key": self.key, "anthropic-version": "2023-06-01"}, body, self.timeout)
|
||||
content = []
|
||||
for b in r.get("content", []):
|
||||
@@ -104,15 +106,25 @@ class Anthropic:
|
||||
|
||||
|
||||
class OpenAICompatible:
|
||||
"""`extra` is merged into every request body (for example
|
||||
{"reasoning_effort": "medium"}) and recorded. OpenAI's own endpoint takes
|
||||
`max_completion_tokens`; other servers take `max_tokens` unless
|
||||
`token_param` says otherwise. The API key is read from the environment
|
||||
variable named by `key_env` (default OPENAI_API_KEY)."""
|
||||
|
||||
name = "openai"
|
||||
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600):
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=600, extra=None, key_env=None, token_param=None, **_):
|
||||
self.model, self.max_tokens, self.temperature, self.timeout = model, max_tokens, temperature, timeout
|
||||
self.url = (base_url or "https://api.openai.com/v1").rstrip("/") + "/chat/completions"
|
||||
self.key = os.environ.get("OPENAI_API_KEY", "")
|
||||
self.base = (base_url or "https://api.openai.com/v1").rstrip("/")
|
||||
self.url = self.base + "/chat/completions"
|
||||
self.key_env = key_env or "OPENAI_API_KEY"
|
||||
self.secret = os.environ.get(self.key_env, "")
|
||||
self.extra = dict(extra or {})
|
||||
self.token_param = token_param or ("max_completion_tokens" if "api.openai.com" in self.base else "max_tokens")
|
||||
|
||||
def params(self):
|
||||
return {"max_tokens": self.max_tokens, "temperature": self.temperature}
|
||||
return {"max_tokens": self.max_tokens, "token_param": self.token_param, "temperature": self.temperature, "extra": self.extra, "key_env": self.key_env}
|
||||
|
||||
def complete(self, system, messages, tools):
|
||||
msgs = [{"role": "system", "content": system}]
|
||||
@@ -132,13 +144,14 @@ class OpenAICompatible:
|
||||
msgs.append({"role": "user", "content": "\n".join(texts)})
|
||||
body = {
|
||||
"model": self.model,
|
||||
"max_tokens": self.max_tokens,
|
||||
self.token_param: self.max_tokens,
|
||||
"messages": msgs,
|
||||
"tools": [{"type": "function", "function": {"name": t["name"], "description": t["description"], "parameters": t["parameters"]}} for t in tools],
|
||||
}
|
||||
if self.temperature is not None:
|
||||
body["temperature"] = self.temperature
|
||||
headers = {"authorization": f"Bearer {self.key}"} if self.key else {}
|
||||
body.update(self.extra)
|
||||
headers = {"authorization": "Bearer " + self.secret} if self.secret else {}
|
||||
r = _post(self.url, headers, body, self.timeout)
|
||||
choice = r["choices"][0]
|
||||
msg = choice["message"]
|
||||
@@ -170,7 +183,7 @@ class Scripted:
|
||||
|
||||
name = "scripted"
|
||||
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=0):
|
||||
def __init__(self, model, max_tokens=8192, temperature=None, base_url=None, timeout=0, **_):
|
||||
self.model = model
|
||||
with open(model) as f:
|
||||
self.turns = json.load(f)
|
||||
|
||||
@@ -71,7 +71,8 @@ def cost(pricing, model, m):
|
||||
|
||||
|
||||
def run_one(task_dir, lang_name, provider_name, model, out_dir, model_class=None, seed=0, sandbox_kind="bwrap",
|
||||
evaluator=None, evaluator_hash_path=None, pricing=None, base_url=None, max_tokens=8192, temperature=None, limits=None):
|
||||
evaluator=None, evaluator_hash_path=None, pricing=None, base_url=None, max_tokens=8192, temperature=None, limits=None,
|
||||
provider_options=None):
|
||||
task = task_mod.Task(task_dir)
|
||||
profile = languages.load(lang_name)
|
||||
lang = task.language(lang_name)
|
||||
@@ -85,19 +86,11 @@ def run_one(task_dir, lang_name, provider_name, model, out_dir, model_class=None
|
||||
agent.copy_workspace(lang["workspace"], workspace)
|
||||
|
||||
_, binds = languages.resolve_binaries(profile)
|
||||
docs = languages.docs_path(profile)
|
||||
docs_src = docs
|
||||
if docs is None:
|
||||
docs = languages.docs_mounts(profile)
|
||||
if not docs:
|
||||
print(f"warning: no local documentation for {lang_name} (set {profile.get('docs', {}).get('env')}); protocol §4 requires pinned docs", file=sys.stderr)
|
||||
if docs and os.path.isfile(docs):
|
||||
# A single documentation file is staged into a directory so that
|
||||
# /docs is a read-only mount as a whole.
|
||||
staged = os.path.join(run_dir, "docs")
|
||||
os.makedirs(staged)
|
||||
shutil.copy(docs, staged)
|
||||
docs = staged
|
||||
sb = sandbox.Sandbox(sandbox_kind, workspace, binds, languages.sandbox_path(binds), docs, profile.get("env"))
|
||||
kw = {"max_tokens": max_tokens, "temperature": temperature, "base_url": base_url}
|
||||
kw = {"max_tokens": max_tokens, "temperature": temperature, "base_url": base_url, **(provider_options or {})}
|
||||
prov = providers.make(provider_name, model, **kw)
|
||||
|
||||
rec = Recorder(run_dir)
|
||||
@@ -126,7 +119,7 @@ def run_one(task_dir, lang_name, provider_name, model, out_dir, model_class=None
|
||||
"started": started,
|
||||
"task": {"id": task.id, "version": task.version, "set": task.set, "family": task.spec.get("family"), "hash": task.hash(), "concurrency": bool(task.spec.get("concurrency"))},
|
||||
"evaluator": None if not evaluator else {"command": evaluator, "hash": util.sha256_path(evaluator_hash_path or evaluator[0])},
|
||||
"language": {"name": lang_name, "profile_hash": profile["profile_hash"], "toolchain": languages.versions(profile), "docs": docs_src, "docs_hash": util.sha256_path(docs) if docs else None},
|
||||
"language": {"name": lang_name, "profile_hash": profile["profile_hash"], "toolchain": languages.versions(profile), "docs": [{"mount": "/docs/" + n, "path": p, "hash": util.sha256_path_cached(p)} for n, p in docs]},
|
||||
"model": {"provider": provider_name, "id": model, "class": model_class, "params": prov.params(), "base_url": base_url},
|
||||
"scaffold": {"version": __version__, "commit": util.git_commit(), "sandbox": sb.describe()},
|
||||
"system_prompt_hash": util.sha256_text(a.system),
|
||||
|
||||
@@ -16,18 +16,18 @@ LINKS = [("usr/lib", "/lib"), ("usr/lib64", "/lib64"), ("usr/bin", "/bin"), ("us
|
||||
|
||||
|
||||
class Sandbox:
|
||||
def __init__(self, kind, workspace, toolchain_binds, path_dirs, docs=None, env=None):
|
||||
def __init__(self, kind, workspace, toolchain_binds, path_dirs, docs=(), env=None):
|
||||
if kind == "bwrap" and shutil.which("bwrap") is None:
|
||||
raise SystemExit("sandbox bwrap requested but bubblewrap is not installed")
|
||||
self.kind = kind
|
||||
self.workspace = os.path.realpath(workspace)
|
||||
self.binds = toolchain_binds
|
||||
self.path = ":".join(path_dirs + ["/usr/bin", "/bin"])
|
||||
self.docs = os.path.realpath(docs) if docs else None
|
||||
self.docs = [(name, os.path.realpath(p)) for name, p in docs]
|
||||
self.env = dict(env or {})
|
||||
|
||||
def describe(self):
|
||||
return {"kind": self.kind, "network": self.kind != "bwrap", "toolchain_binds": self.binds, "docs": self.docs}
|
||||
return {"kind": self.kind, "network": self.kind != "bwrap", "toolchain_binds": self.binds, "docs": [{"mount": "/docs/" + n, "path": p} for n, p in self.docs]}
|
||||
|
||||
def argv(self, command):
|
||||
if self.kind == "none":
|
||||
@@ -43,8 +43,12 @@ class Sandbox:
|
||||
for d in self.binds:
|
||||
a += ["--ro-bind", d, d]
|
||||
if self.docs:
|
||||
target = "/docs" if os.path.isdir(self.docs) else "/docs/" + os.path.basename(self.docs)
|
||||
a += ["--ro-bind", self.docs, target]
|
||||
# A tmpfs mount point, remounted read-only after the binds, keeps
|
||||
# /docs read-only as a whole.
|
||||
a += ["--tmpfs", "/docs"]
|
||||
for name, p in self.docs:
|
||||
a += ["--ro-bind", p, "/docs/" + name if name else "/docs"]
|
||||
a += ["--remount-ro", "/docs"]
|
||||
a += ["--bind", self.workspace, "/work", "--chdir", "/work", "--clearenv"]
|
||||
env = {"PATH": self.path, "HOME": "/tmp", "TMPDIR": "/tmp", "LANG": "C.UTF-8"}
|
||||
env.update(self.env)
|
||||
|
||||
@@ -36,6 +36,28 @@ def sha256_path(path):
|
||||
return "sha256:" + h.hexdigest()
|
||||
|
||||
|
||||
def sha256_path_cached(path):
|
||||
"""`sha256_path` for large documentation trees, cached on disk by the
|
||||
tree's path, file count, total size and newest modification time."""
|
||||
count, size, newest = 0, 0, 0.0
|
||||
for root, dirs, files in os.walk(path) if os.path.isdir(path) else [(os.path.dirname(path), [], [os.path.basename(path)])]:
|
||||
dirs[:] = [d for d in dirs if d not in (".git", "__pycache__")]
|
||||
for name in files:
|
||||
st = os.stat(os.path.join(root, name))
|
||||
count, size, newest = count + 1, size + st.st_size, max(newest, st.st_mtime)
|
||||
key = f"{os.path.realpath(path)}|{count}|{size}|{newest}"
|
||||
cache_file = os.path.join(os.path.expanduser("~"), ".cache", "ajieval", "hashes.json")
|
||||
try:
|
||||
cache = read_json(cache_file)
|
||||
except (OSError, ValueError):
|
||||
cache = {}
|
||||
if key not in cache:
|
||||
cache[key] = sha256_path(path)
|
||||
os.makedirs(os.path.dirname(cache_file), exist_ok=True)
|
||||
write_json(cache_file, cache)
|
||||
return cache[key]
|
||||
|
||||
|
||||
def git_commit(path=REPO):
|
||||
"""`<commit>` or `<commit>+dirty` for the repository containing `path`."""
|
||||
try:
|
||||
|
||||
@@ -2,12 +2,46 @@
|
||||
"name": "rust",
|
||||
"display": "Rust",
|
||||
"toolchain": {
|
||||
"bind_command": ["rustc", "--print", "sysroot"],
|
||||
"version": [["rustc", "--version"], ["cargo", "--version"]]
|
||||
"bind_command": [
|
||||
"rustc",
|
||||
"--print",
|
||||
"sysroot"
|
||||
],
|
||||
"version": [
|
||||
[
|
||||
"rustc",
|
||||
"--version"
|
||||
],
|
||||
[
|
||||
"cargo",
|
||||
"--version"
|
||||
]
|
||||
]
|
||||
},
|
||||
"docs": {"env": "AJI_EVAL_RUST_DOCS", "default": ""},
|
||||
"source_extensions": [".rs"],
|
||||
"instructions": "Language: Rust (stable toolchain, standard library only; no network, so no crates.io dependencies).\nToolchain: `cargo build`, `cargo test`, `cargo run`, `rustc`. Cargo works offline (`--offline` is implied by the environment).\nDocumentation: pinned local Rust documentation is in /docs (read-only), if present.",
|
||||
"env": {"CARGO_NET_OFFLINE": "true"},
|
||||
"classify": {"check": ["cargo check"], "build": ["cargo build", "rustc"], "test": ["cargo test", "cargo run"]}
|
||||
"docs": {
|
||||
"env": "AJI_EVAL_RUST_DOCS",
|
||||
"from_toolchain": [
|
||||
"share/doc/rust/html"
|
||||
]
|
||||
},
|
||||
"source_extensions": [
|
||||
".rs"
|
||||
],
|
||||
"instructions": "Language: Rust (stable toolchain, standard library only; no network, so no crates.io dependencies).\nToolchain: `cargo build`, `cargo test`, `cargo run`, `rustc`. Cargo works offline (`--offline` is implied by the environment).\nDocumentation: the offline documentation of this toolchain (standard library API, the Reference, the Book) is in /docs (read-only).",
|
||||
"env": {
|
||||
"CARGO_NET_OFFLINE": "true"
|
||||
},
|
||||
"classify": {
|
||||
"check": [
|
||||
"cargo check"
|
||||
],
|
||||
"build": [
|
||||
"cargo build",
|
||||
"rustc"
|
||||
],
|
||||
"test": [
|
||||
"cargo test",
|
||||
"cargo run"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,40 @@
|
||||
"name": "zig",
|
||||
"display": "Zig",
|
||||
"toolchain": {
|
||||
"binaries": ["zig"],
|
||||
"version": [["zig", "version"]]
|
||||
"binaries": [
|
||||
"zig"
|
||||
],
|
||||
"version": [
|
||||
[
|
||||
"zig",
|
||||
"version"
|
||||
]
|
||||
]
|
||||
},
|
||||
"docs": {"env": "AJI_EVAL_ZIG_DOCS", "default": ""},
|
||||
"source_extensions": [".zig"],
|
||||
"instructions": "Language: Zig (the pinned toolchain below; standard library only; no network).\nToolchain: `zig build`, `zig build test`, `zig build run`, `zig run FILE.zig`, `zig test FILE.zig`.\nDocumentation: pinned local Zig documentation is in /docs (read-only), if present.",
|
||||
"classify": {"check": ["zig ast-check"], "build": ["zig build-exe", "zig build"], "test": ["zig build test", "zig test", "zig build run", "zig run"]}
|
||||
"docs": {
|
||||
"env": "AJI_EVAL_ZIG_DOCS",
|
||||
"from_toolchain": [
|
||||
"doc",
|
||||
"lib/std"
|
||||
]
|
||||
},
|
||||
"source_extensions": [
|
||||
".zig"
|
||||
],
|
||||
"instructions": "Language: Zig (the pinned toolchain below; standard library only; no network).\nToolchain: `zig build`, `zig build test`, `zig build run`, `zig run FILE.zig`, `zig test FILE.zig`.\nDocumentation: the language reference matching this compiler is in /docs/doc and the matching standard library source in /docs/std (read-only).",
|
||||
"classify": {
|
||||
"check": [
|
||||
"zig ast-check"
|
||||
],
|
||||
"build": [
|
||||
"zig build-exe",
|
||||
"zig build"
|
||||
],
|
||||
"test": [
|
||||
"zig build test",
|
||||
"zig test",
|
||||
"zig build run",
|
||||
"zig run"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -37,13 +37,15 @@ class SandboxTest(unittest.TestCase):
|
||||
@unittest.skipUnless(SANDBOX == "bwrap", "bubblewrap unavailable")
|
||||
def test_isolation(self):
|
||||
ws = tempfile.mkdtemp()
|
||||
sb = sandbox.Sandbox("bwrap", ws, [], [], docs=TASK)
|
||||
sb = sandbox.Sandbox("bwrap", ws, [], [], docs=[("", TASK), ("prompt.md", os.path.join(TASK, "prompt.md"))])
|
||||
code, out, _ = sb.run("echo hi > f && cat f", 30, 1000)
|
||||
self.assertEqual((code, out.strip()), (0, "hi"))
|
||||
code, out, _ = sb.run("getent hosts example.com || echo NO_NET", 30, 1000)
|
||||
self.assertIn("NO_NET", out)
|
||||
code, _, _ = sb.run("touch /docs/x", 30, 1000)
|
||||
self.assertNotEqual(code, 0)
|
||||
code, out, _ = sb.run("cat /docs/prompt.md/../task.json >/dev/null 2>&1; head -c 6 /docs/prompt.md", 30, 1000)
|
||||
self.assertIn("# Task", out)
|
||||
code, out, _ = sb.run("ls " + os.path.expanduser("~") + " 2>&1 || echo NO_HOME", 30, 1000)
|
||||
self.assertIn("NO_HOME", out)
|
||||
self.assertTrue(os.path.exists(os.path.join(ws, "f")))
|
||||
@@ -60,7 +62,7 @@ class SandboxTest(unittest.TestCase):
|
||||
class PathTest(unittest.TestCase):
|
||||
def test_confinement(self):
|
||||
ws = tempfile.mkdtemp()
|
||||
a = agent.Agent(None, {"instructions": ""}, None, {}, None, ws, None, None, {"tool_calls": 1, "total_tokens": 1, "output_chars": 100})
|
||||
a = agent.Agent(None, {"instructions": ""}, None, {}, None, ws, [], None, {"tool_calls": 1, "total_tokens": 1, "output_chars": 100})
|
||||
for bad in ["/etc/passwd", "../x", "/work/../etc/passwd", "/docs/x"]:
|
||||
with self.assertRaises(agent.ToolError):
|
||||
a.host_path(bad)
|
||||
|
||||
Reference in new issue
Block a user