Add sandbox execution
Let an agent run commands inside a scoped sandbox session.
Use sandbox execution for coding agents, file generation, test runs, and previews.
Run a command
import { Effect, Layer } from 'effect'
import { Sandbox } from '@yolk-sdk/sandbox'
import { makeInMemorySandboxStateStoreLayer } from '@yolk-sdk/sandbox/testing'
import { makeVercelSandboxLayer } from '@yolk-sdk/sandbox/vercel'
const SandboxLayer = makeVercelSandboxLayer({
sandboxSessionId: 'user-session-123',
ports: [3000]
}).pipe(Layer.provide(makeInMemorySandboxStateStoreLayer()))
const result = await Effect.runPromise(
Effect.gen(function* () {
const sandbox = yield* Sandbox
return yield* sandbox.run({ command: 'pnpm test' })
}).pipe(Effect.provide(SandboxLayer))
)On Cloudflare Workers, use makeCloudflareSandboxLayer from @yolk-sdk/sandbox/cloudflare
instead; see Cloudflare Containers.
Add the agent tool
import { Effect } from 'effect'
import { makeSandboxToolModule } from '@yolk-sdk/sandbox/agent'
const sandboxToolModule = await Effect.runPromise(
makeSandboxToolModule({
workspaceDescription: 'Temporary workspace for this run.',
previewPorts: [3000]
}).pipe(Effect.provide(SandboxLayer))
)The sandbox tool is destructive. Add approvals and audit logs before enabling it for broad use.
The tool declares SandboxToolOutput as its output: structuredContent carries exitCode,
durationMs, timedOut, truncated, workspaceReset, optional backgroundId, the same bounded
stdout and stderr slices as the text, previewUrls, and state. A non-zero exit or timeout is
still an error result.
Move files in and out
The Vercel and Cloudflare layers implement the optional writeFile/readFile on Sandbox for workspace-relative
paths. To let the agent copy files between tools and the workspace, pass the sandbox to
makeFileToolModule from @yolk-sdk/files; see Move files between tools.