Run a trusted command while streaming its output, give generated JavaScript a bounded host API,
or capture a rendered page. The sandbox package defines a separate contract for each job:
Need
Use
Result
Run a known command with arguments, working directory, and bounded output
Sandbox
A stream of process events
Run generated JavaScript that can call an allowlisted host API
Sandbox is for command-shaped work. It keeps the executable, arguments, current directory,
environment names, network request, and resource limits in a Schema-defined request. The host can
call it directly or wrap it in an application Tool. Process execution has no durable recovery;
a process that may have changed an external system has an uncertain outcome after a crash.
CodeExecutor is a different port for one generated JavaScript async function. The only host
authority it receives is the scoped CodeExecutionHost callback. Code Mode adds
the agent-facing Tool, validation, broker, and accounting. Do not use a command process when the
work needs that narrow callback boundary.
Browser services also have their own contracts because rendering and navigation are egress
operations. Use browser services for Cloudflare adapter setup, network policy, and
browser session lifetime.
@yielded/agent-sandbox-local runs a child process on the current machine. It is useful for local
development and trusted automation. Every event identifies it as unisolated.
The local adapter accepts only the unisolated-process runtime with the local-process identity.
The request must name every environment variable the child may receive. It starts with an empty
environment, then copies only those names. LocalSandbox.layer supplies the Node process services.
import{
importNodeRuntime
NodeRuntime }from"@effect/platform-node";
import{
classNetworkDisabled
Explicitly denies all workload network access.
NetworkDisabled,
classSandbox
Scoped command/code execution capability. Implementations must identify their isolation posture
in every emitted event; an unisolated implementation is never a security sandbox.
Sandbox,
classSandboxRequest
Schema-first command execution request. Command and arguments are intentionally separate.
SandboxRequest }from"@yielded/agent/sandbox";
import{
importLocalSandbox
LocalSandbox }from"@yielded/agent-sandbox-local";
import{
importConsole
Console,
importDuration
Duration,
importEffect
Effect,
importStream
Stream }from"effect";
const
constrequest:SandboxRequest
request=
classSandboxRequest
Schema-first command execution request. Command and arguments are intentionally separate.
Constructs a value from the make input representation synchronously.
When to use
Use when constructor input is trusted or when validation failure
should abort with a thrown Error.
Details
Applies constructor defaults and type-side validation according to
MakeOptions.
Gotchas
Throws an Error with the schema issue in its cause when validation
fails. Schema validation failures use the generic message
"Schema validation failed"; format the cause explicitly with
SchemaIssue.makeFormatterDefault() when human-readable details are needed.
Causes that contain defects, interruptions, or other non-schema reasons
throw with the underlying Cause attached instead.
@see ― BottomWithoutNew.makeOption — construct synchronously and discard validation details
@see ― BottomWithoutNew.makeEffect — construct through Effect when validation failure should stay in the error channel
Constructs a value from the make input representation synchronously.
When to use
Use when constructor input is trusted or when validation failure
should abort with a thrown Error.
Details
Applies constructor defaults and type-side validation according to
MakeOptions.
Gotchas
Throws an Error with the schema issue in its cause when validation
fails. Schema validation failures use the generic message
"Schema validation failed"; format the cause explicitly with
SchemaIssue.makeFormatterDefault() when human-readable details are needed.
Causes that contain defects, interruptions, or other non-schema reasons
throw with the underlying Cause attached instead.
@see ― BottomWithoutNew.makeOption — construct synchronously and discard validation details
@see ― BottomWithoutNew.makeEffect — construct through Effect when validation failure should stay in the error channel
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Scoped command/code execution capability. Implementations must identify their isolation posture
in every emitted event; an unisolated implementation is never a security sandbox.
Provides dependencies to an effect using layers or a context. Use options.local
to build the layer every time; by default, layers are shared between provide
calls.
Helps you run a main effect with built-in error handling, logging, and signal management.
When to use
Use to run a Node.js application's main Effect with structured error
handling, log management, interrupt support, or advanced teardown
capabilities.
Details
This function launches an Effect as the main entry point, setting exit codes
based on success or failure, handling interrupts (e.g., Ctrl+C), and optionally
logging errors. By default, it logs errors and uses a "pretty" format, but both
behaviors can be turned off. You can also provide custom teardown logic to
finalize resources or produce different exit codes.
The optional configuration object can include:
disableErrorReporting: Turn off automatic error logging.
Sandbox.execute emits SandboxStarted, zero or more SandboxOutput events, then
SandboxExited when the process reaches an exit status. Stdout and stderr events may interleave.
The local adapter counts their combined bytes against maxOutputBytes.
A zero exit code completes the stream. A nonzero exit still emits SandboxExited first, then
fails with SandboxExitError. NodeRuntime.runMain reports the failure and exits unsuccessfully.
A spawn failure has no started or exited event. SandboxOutputLimitError and SandboxTimeoutError
also remain in the typed error channel. Use Effect.catchTag when your application has a recovery
action for one of these failures.
Interrupting the consumer preserves Effect interruption. The adapter does not turn it into an exit
record or a SandboxError. Keep the call in a Scope, as above, so stream finalization owns child
process cleanup.
The local adapter enforces one wall-clock limit across environment loading, process startup, and
stream consumption. Output activity does not reset this deadline. It also enforces the combined
stdout and stderr byte limit. It does not enforce process isolation, mount access, CPU limits,
memory limits, secret-handle resolution, or artifact collection. Requests that ask for those features fail as
SandboxUnsupportedRequestError before the process starts.
NetworkDisabled is required by the local adapter because it rejects allowlists. It is only a
request marker there. The adapter does not configure the operating system or a network namespace,
so it does not prevent the child process from opening a connection. Do not run untrusted commands,
model-generated commands, or sensitive credentials through this adapter.
The local adapter also rejects any runtime identity other than local-process. It passes no
environment values unless they appear in environment.allow, and it never resolves
secretHandles into environment variables. Put secrets behind a real isolated runtime or an
application-owned host API.
CodeExecutor accepts only JavaScript source that evaluates to one async function. It has bounded
source, logs, result, wall-clock time, CPU time when supported, host calls, and host-call payloads.
An implementation must enforce each requested limit or return a typed unsupported error. Use Code
Mode when an agent should write that program and call explicitly allowed application Tools.
PageCapture returns one rendered content, Markdown, links, structured extraction, or selector
scrape result. Its output is untrusted input. PageCrawl returns a scoped stream of rendered
Markdown from one exact HTTPS host. InteractiveBrowser returns a scoped handle that cannot be
persisted or transferred. Its actions can have uncertain outcomes, especially after a click or
fill request.
The Cloudflare adapters provide page capture, crawl, screenshots, and interactive browser passes.
They do not make local command execution isolated. Keep browser and process capabilities behind
the host policy that authenticates callers and authorizes the resources they may reach.