Inline-code sandbox exposes __import__, letting code bypass the Restricted Built-ins set entirely (e.g. import os) #107
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Blocks
Depends on
#77 Epic: LLM Agent Runtime Stabilization — reliability, resource enforcement & correctness hardening
cleveragents/cleveractors-core
#108 TDD: Inline-code sandbox exposes __import__, letting code bypass the Restricted Built-ins set entirely (e.g. import os)
cleveragents/cleveractors-core
#118 fix(agents): restrict inline-code sandbox to a json-only __import__
cleveragents/cleveractors-core
Reference
cleveragents/cleveractors-core#107
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Metadata
fix(agents): restrict inline-code sandbox to a json-only __import__bugfix/m1-inline-sandbox-import-restriction(provisional — align the milestone number with the milestone assigned at triage)Background and context
ToolAgent._execute_python_code(cleveractors.agents.tool) builds the inline-code sandbox's__builtins__dict per §13.2.1's "Restricted Built-ins for Inline Code" table. That table is documented as exhaustive (§13.2.1: "the following built-in facilities MUST be available to it, and no other built-in facilities MAY be exposed") and does not list__import__. §13.2.3 additionally prohibits, without qualification, "performing arbitrary I/O against the filesystem, network, or system" and "dynamic import of modules other than those explicitly listed" for both sandboxes defined by the standard.Despite this,
_execute_python_code'ssafe_globals["__builtins__"]dict includes"__import__": __import__— a direct reference to the real, unrestricted import machinery — with the accompanying comment "Allow imports for json." Because__import__is the actual mechanism Python'simportstatement invokes, an inline-code body can writeimport os,import subprocess,import socket, etc. and reach exactly the facilities (os,io,pathlib, filesystem, network, process control) that §13.2.1's table and §13.2.3's prohibitions were written to keep out.This predates ADR-2035 (issue #93) and was flagged during that PR's review (#103) as pre-existing and explicitly out of scope for that change (ADR-2035 D-1 fixes the built-in table as unchanged), but it is a live security gap: while
__import__remains, the inline-code sandbox is not a real security boundary — it is advisory at best. The new ADR-2035read_file/write_filehelpers' sandbox-root confinement is consequently only a convenience / defense-in-depth control today, not a hard limit, since any inline body can bypass it entirely viaimport os; os.open(...)or equivalent.Current behavior
Inline code (a
type: toolagent'scode:body, or thepython_execbuilt-in tool, which shares the same sandbox construction) can executeimport os(or any other module) successfully, then use that module's full API — including arbitrary filesystem access, network access, and subprocess execution — with no restriction. Only the namejsonis meant to be reachable via import per the spec's intent, but nothing currently stops any other module name.Expected behavior
Only
json(the one module §13.2.1 names) is importable via animportstatement inside inline code; importing any other module raises the same category of error inline code already gets for referencing any other undefined/prohibited name. Per §13.2.1, this MUST hold for the inline-code sandbox; §13.2.2 (the expression sandbox) is unaffected since it never exposed__import__to begin with.Acceptance criteria
import json(and the pre-boundjsonlocal name already relied on by the §4.5.2 canonical example) continues to work unchanged inside inline code.import os(and any other non-jsonmodule) inside inline code raises an error — a category consistent with how_execute_python_codealready reports prohibited-name access (see itsNameError→ExecutionErrortranslation), not a bare Python traceback.__builtins__table beyond what §13.2.1 already lists (jsonstays the only module-shaped facility).python_exec(theexec_python-gated built-in tool, which shares_execute_python_code) is restricted identically — no separate bypass path.transform.fn, bridge predicates) is unaffected — it already has no__import__and gains none.import jsoninside inline code regresses.Supporting information
src/cleveractors/agents/tool.py,ToolAgent._execute_python_code,safe_globals["__builtins__"]["__import__"].docs/index.md§13.2.1 (exhaustive built-in table), §13.2.3 (prohibited capabilities — "dynamic import of modules other than those explicitly listed").read_file/write_filesandbox-root confinement (issue #93) is undermined as a hard boundary while this gap remains open — closing this issue is what turns that confinement from defense-in-depth into an actual limit.Subtasks
__import__shim (e.g. one that permitsimport jsonand raises for every other module name) and wire it into_execute_python_code's__builtins__dict in place of the raw__import__reference.python_exec(shares the same sandbox construction) is covered by the same restriction.import jsonstill succeeds;import os(and at least one or two other representative modules) raises; the raised error is in the same category as other prohibited-name errors.import.docs/index.md§21).nox -s coverage_report.nox(all default sessions), fix any errors.Definition of Done
This issue is complete when:
master, reviewed, and merged.