Skip to content

Sandboxing & LLM_AGENT

This page covers isolation for AgentSkill steps. Sandboxed execution of commands lives in CommandStep, ShellSessionStep and CodeStep; they share the runtime backends described below.

AgentSkillStepConfig.runtime defaults to "local". In CARL 0.5.2 this is the only runtime an AgentSkill step can execute scripts with. LocalSkillRuntime starts a host subprocess: the script sees the host filesystem, the host network and, unless extra_pip is set, the full host environment including credentials. It emits a one-time UserWarning that says so.

Setting runtime to docker, e2b or firejail does not sandbox the skill. Every script launch then raises SkillRuntimeError (“AgentSkill script execution on non-local runtimes requires a staged workspace and is not implemented yet”). What that means per mode:

ModeWith a non-local runtime
LLMRuns normally; no script is launched.
SCRIPTStep fails.
HYBRIDScript fails, the step falls back to the LLM (result_data["script_error"], llm_fallback=True).
SUBAGENTScript fails, the LLM runs with an error note in the prompt; the step can succeed.
LLM_AGENTStep fails as soon as the model calls run_script.

extra_pip is installed through the same path, so it also works only on local (with the host’s pip). An unknown runtime name fails the step before anything runs.

Four backends are registered on import: local, docker, e2b, firejail. Each declares a RuntimeCapabilities record. enforced means the backend prevents the violation, advisory means it records or applies the control only after the fact, unsupported means it does nothing.

Controllocaldockerfirejaile2b
isolationnonecontainerprocessmicrovm
wall_timeenforced (POSIX)enforcedenforcedadvisory
output_limitenforcedenforcedenforcedadvisory
cpu_limitunsupportedenforcedunsupportedunsupported
memory_limitunsupportedenforcedadvisoryunsupported
pids_limitunsupportedenforcedadvisoryunsupported
network_noneunsupportedenforcedenforcedenforced
network_allowlistunsupportedunsupportedunsupportedenforced
workspace_filesenforcedenforcedenforcedenforced
persistent_shellunsupportedunsupportedunsupportedunsupported
artifact_output_limitenforcedenforcedenforcedadvisory

Prerequisites: docker needs the Docker CLI and daemon, firejail needs Linux with firejail, e2b needs pip install 'mmar-carl[e2b]' and an API key (read from E2B_API_KEY by default).

from mmar_carl import (
assess_runtime_enforcement, get_runtime_capabilities, get_skill_runtime,
)
runtime = get_skill_runtime("docker")
get_runtime_capabilities(runtime).network_allowlist # "unsupported"
report = assess_runtime_enforcement(
runtime, mode="strict", network="allowlist",
cpu_limit_requested=True, memory_limit_requested=True, pids_limit_requested=False,
)
report.gaps # ("network",)
report.fully_enforced # False
report.as_dict() # runtime, isolation, mode, controls, gaps

get_runtime_capabilities() returns an all-unsupported record with isolation="unknown" for a runtime that declares nothing. assess_runtime_enforcement() builds the EnforcementReport that command steps use: with enforcement_mode="strict" they refuse to start when a requested control has a gap. AgentSkill steps do not produce an enforcement report.

runtime_config["network"] takes one of three values (NetworkPolicy):

PolicyMeaning
none (default)Request no egress.
allowlistRequest egress only to exact hosts from runtime_config["network_allowlist"] plus WebFetch(domain:...) hosts from the skill’s allowed-tools. At least one host is required; CIDRs, wildcards, URLs and ports are rejected.
hostFull host networking; backends emit a UserWarning.

What the backends do with it:

  • local: validates and records the policy (handle.backend["network_enforced"] = False). It cannot block anything.
  • docker / firejail: none maps to --network none / --net=none. allowlist without a host-issued binding also runs with no network at all (fails closed). With a DockerNetworkBinding / FirejailNetworkBinding from a host NetworkEnforcer, the container joins the pre-provisioned network or interface.
  • e2b: passes none and allowlist to the E2B create API.

For an AgentSkill step only the first case applies: the policy string is validated (an unknown value fails the step) and then ignored by local.

from mmar_carl import resolve_network_policy, parse_network_allowlist_from_allowed_tools
policy, hosts = resolve_network_policy(
{"network": "allowlist", "network_allowlist": ["api.example.com"]},
manifest_allowed_tools="Read WebFetch(domain:docs.example.com)",
)
# ("allowlist", ["api.example.com", "docs.example.com"])
parse_network_allowlist_from_allowed_tools("Bash(git:*) WebFetch(domain:api.x.com)")
# ["api.x.com"]; a bare WebFetch with no domain is ignored

A hostname list in chain JSON is not proof that a filter exists. Managed egress is a host-side contract in mmar_carl.network_enforcement: a NetworkEnforcer plans, acquires and releases a lease for a ManagedNetworkProfile. PreconfiguredNetworkEnforcer is the shipped implementation. It is an attestation adapter: it creates no Docker networks, configures no interfaces and installs no firewall rules; the operator vouches that each binding enforces the exact allowlist. The enforcer sits on ReasoningContext.network_enforcer, is runtime-only and never serialized. Command steps use it; AgentSkill steps do not.

LLM_AGENT creates a temporary directory carl_skill_* with in/ and out/ and runs a tool-calling loop with five fixed tools:

ToolWhat it does
list_resources()Lists the skill’s scripts, references and assets.
read_resource(resource_path)Reads a file under the skill dir (first 8000 chars).
read_file(path)Reads a file (first 10000 chars). /workspace/in and /workspace/out are mapped to the temp dirs; relative paths are relative to the skill dir.
write_file(filename, content)Writes out/<basename>.
run_script(script_path, args)Runs a .py (with python_executable) or .sh (with /bin/sh) script through the local runtime, cwd = working_dir or skill dir.
  • input_mapping values that are paths to existing host files are copied into in/; other values are passed through as text.
  • Files in out/ matching output_files_glob go to result_data["output_files"] as {path, name, size}.
  • output_capture picks the step result: "stdout" (final answer), "files" (JSON list of files) or "both" (answer plus file names).
  • The loop stops on a reply with no tool calls or after llm_max_iterations (default 8). Cancellation is checked before every round.
  • Each call emits llm_agent.tool_call and llm_agent.tool_result step events.
  • The workspace is deleted afterwards unless persist_workspace=True.

You can register your own backend. It becomes available to command steps and to get_skill_runtime(). AgentSkill steps still reject any runtime whose name is not "local".

from typing import ClassVar
from mmar_carl import RuntimeCapabilities, register_skill_runtime, list_skill_runtimes
class MySandbox:
name: ClassVar[str] = "mysandbox"
capabilities: ClassVar[RuntimeCapabilities] = RuntimeCapabilities(
isolation="container", wall_time="enforced", network_none="enforced",
)
async def prepare(self, skill, workspace, config): ... # -> SkillRuntimeHandle
async def run(self, handle, cmd, *, env=None, stdin=None, timeout=None, cwd=None): ...
async def read_file(self, handle, path): ...
async def read_file_bounded(self, handle, path, max_bytes, timeout=None): ...
async def write_file(self, handle, path, data): ...
async def cleanup(self, handle): ... # idempotent
register_skill_runtime(MySandbox.name, MySandbox)
list_skill_runtimes() # ['docker', 'e2b', 'firejail', 'local', 'mysandbox']

The SkillRuntime protocol requires name, capabilities and the six async methods above. run returns a RuntimeRunResult (stdout, stderr, exit_code, duration_s, truncation flags). A runtime that declares no capabilities is treated as unsupported for every control. register_skill_runtime overwrites an existing name; get_skill_runtime raises SkillRuntimeError for an unknown one.