Sandbox lifecycle and safety
Configure Vercel Sandbox lifecycle, source, environment, ports, and agent approval policy.
The sandbox package exposes execution mechanics. Your app owns safety policy.
@yolk-sdk/sandbox/vercel is Node/server-only because @vercel/sandbox imports Node built-ins.
Browser and Worker code may use provider-free core types but must call a host execution endpoint
instead of importing the Vercel adapter. Cloudflare Workers can use the
Cloudflare Containers adapter instead.
Vercel layer
import { Layer } from 'effect'
import { makeInMemorySandboxStateStoreLayer } from '@yolk-sdk/sandbox/testing'
import { GitSandboxInitialSource } from '@yolk-sdk/sandbox'
import { makeVercelSandboxLayer } from '@yolk-sdk/sandbox/vercel'
const SandboxLayer = makeVercelSandboxLayer({
sandboxSessionId: 'user_123:session_456',
source: GitSandboxInitialSource.make({
url: 'https://github.com/example/repo.git',
revision: 'main'
}),
env: {
NODE_ENV: 'development'
},
ports: [3000, 5173],
resources: { vcpus: 2 },
runtime: 'node24'
}).pipe(Layer.provide(makeInMemorySandboxStateStoreLayer()))Replace the in-memory state store with durable app storage in production.
Lifecycle defaults
| Setting | Default |
|---|---|
| lifecycle | disposable |
| idle TTL | 30 minutes |
| max lifetime | 45 minutes |
| command timeout | 120 seconds |
| max command timeout | 600 seconds |
| ports | 3000, 5173, 4321, 8000 |
| workspace root | /vercel/sandbox |
Expired disposable state recreates before command execution and returns workspaceReset: true.
Persistent state instead reattaches the stable named sandbox so Vercel can resume the latest
persisted filesystem; it recreates only when the provider no longer has that sandbox.
Source options
| Source | Use for |
|---|---|
EmptySandboxInitialSource | blank workspace |
GitSandboxInitialSource | clone a public or tokenized repository |
SnapshotSandboxInitialSource | restore a provider snapshot |
TarballSandboxInitialSource | hydrate from an archive |
Choose source per trusted server policy, not from raw client input.
Git credentials use optional GitSandboxBasicAuth, so username/password are always supplied
together. The Vercel layer runs on a managed runtime (default node24) or a Vercel Container
Registry image (the project's own, or one another team shares, such as
team/project/repo@sha256:…), never both; either applies to empty, Git, and tarball creation, and
snapshots boot their own saved environment.
Agent tool
import { Effect } from 'effect'
import { makeSandboxToolModule } from '@yolk-sdk/sandbox/agent'
const sandboxTools = await Effect.runPromise(
makeSandboxToolModule({
workspaceDescription: 'Temporary workspace for this coding task.',
lifecycleDescription: 'Disposable sandbox; files may reset after expiry.',
previewPorts: [3000, 5173]
}).pipe(Effect.provide(SandboxLayer))
)The tool is named sandbox and has destructive access.
Safety checklist
- Require approval before enabling the sandbox tool broadly.
- Scope
sandboxSessionIdby user/session/workspace. - Do not inject long-lived secrets into disposable sandboxes.
- Restrict env/secrets to the minimum needed for the task.
- Reject privileged commands in app policy if your product needs it.
- Show diffs and command logs before committing/pushing generated work.
- Clean up expired disposable sandboxes on a schedule.
Result semantics
Command failures are result data:
| Result field | Meaning |
|---|---|
exitCode | null for timeout/unknown, otherwise process exit code |
timedOut | command exceeded timeout and was killed |
workspaceReset | state was recreated before command |
previewUrls | provider preview URLs for configured ports |
backgroundId | long-running background command id |
Provider/state/config failures become safe ToolErrors that the agent loop renders as failed tool results.