Flows category icon
Harness Engineering
Advanced

Sandbox Untrusted Code Execution

Contain what your agent runs: isolated execution environments with resource limits, network policy, and workspace mounting done right.

4 steps12 verify checks120-180 minutesWorks with: emergent · chatgpt · claude · cursor
Start Guided Walkthrough

The Route

0/4 verified

Context Pack

Paste this first. It briefs the AI on requirements, constraints, and the Definition of Done before your first build prompt.

Context Pack
PROJECT CONTEXT:
My agent executes model-written code and shell commands on the host - one hallucinated command from disaster. The platforms that run agents at scale execute everything inside sandboxes with explicit resource, filesystem, and network policies.

GOAL:
Move agent code/command execution into a sandbox: container-based isolation, scoped workspace mounts, resource and network limits, and a recovery story.

REQUIREMENTS:
- All run_command/code execution inside an isolated environment (container or equivalent)
- Workspace mounting: the project directory available, everything else invisible
- Resource limits: CPU, memory, processes, disk, and execution time
- Network policy: default-deny with an explicit allowlist where needed
- Ergonomics preserved: results, exit codes, and files behave as the agent expects

CONSTRAINTS:
- The sandbox boundary is the host's protection - convenience never punches holes in it silently
- Sandbox escapes and limit hits must be logged as security events

DEFINITION OF DONE:
- A destructive command (rm -rf /) executes harmlessly inside the sandbox
- The sandbox cannot read host files outside the mounted workspace
- A fork bomb or memory hog is killed by limits, and the agent is told why
- Network calls to non-allowlisted destinations fail with a policy error

COMMON FAILURES TO AVOID:
- Running as root with the host filesystem mounted - a sandbox in name only
- No resource limits, so the host dies from a while-true the model wrote
- Unrestricted network, letting exfiltration or cryptomining ride along
- Sandbox friction so high that developers quietly disable it

Paste this into your AI builder first. It teaches the AI what you want before you give it the build prompt.

Related routes

More Harness Engineering flows that share ground with this one.

Flows category icon
Harness Engineering

Assemble Tool Prompts Dynamically per Environment

Stop shipping one static mega-prompt: generate tool prompts from environment conditions, inject blocks only when features are on, and dedupe config to save tokens.

01Identify conditional blocks
02Build the prompt generator
03Dedupe and budget every block

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-120 minutesAdvanced
Flows category icon
Harness Engineering

Cost Control: Model Routing and Effort Tiers

Route work to the cheapest model that can do it and match reasoning effort to task difficulty - with quality guardrails.

01Profile spend by call class
02Build the routing table and wire it
03Add escalation on failure

+1 more steps to Done

Best forproduction-grade builds with strict verification

4 steps90-120 minutesAdvanced
Flows category icon
Harness Engineering

Design Layered Tool Prompts with Preference Chains

Structure your tool prompts the way the leading harness does: preference chains up front, usage constraints in the middle, NEVER-guarded safety protocols at the end.

01Audit the current tool prompt
02Write the preference chain
03Write usage constraints and safety protocols

+1 more steps to Done

Best forbuilders who have shipped a basic app before

4 steps60-90 minutesIntermediate

Made with Emergent