Yolk SDK
Sandbox

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

SettingDefault
lifecycledisposable
idle TTL30 minutes
max lifetime45 minutes
command timeout120 seconds
max command timeout600 seconds
ports3000, 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

SourceUse for
EmptySandboxInitialSourceblank workspace
GitSandboxInitialSourceclone a public or tokenized repository
SnapshotSandboxInitialSourcerestore a provider snapshot
TarballSandboxInitialSourcehydrate 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 sandboxSessionId by 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 fieldMeaning
exitCodenull for timeout/unknown, otherwise process exit code
timedOutcommand exceeded timeout and was killed
workspaceResetstate was recreated before command
previewUrlsprovider preview URLs for configured ports
backgroundIdlong-running background command id

Provider/state/config failures become safe ToolErrors that the agent loop renders as failed tool results.

On this page