zidane/ contexts/ sandbox
The generic remote sandbox context and the provider interface that E2B and Daytona implement.
import { … } from 'zidane/contexts/sandbox'src/contexts/sandbox.ts
Use createSandboxContext when you want an ExecutionContext backed by a remote sandbox. It takes a SandboxProvider, a small interface that creates, attaches to and destroys sandboxes. Pass the E2B or Daytona provider, or implement the interface for your own backend.
import { createSandboxContext } from 'zidane/contexts/sandbox'
import { createE2BProvider } from 'zidane/contexts/e2b'
const context = createSandboxContext(createE2BProvider({ cwd: '/home/user/project' }))
const handle = await context.spawn()
const result = await context.exec(handle, 'uname -a')
console.log(result.stdout)
await context.destroy(handle)Functions#
createSandboxContextFunction#
Creates an execution context that runs commands and file operations in a remote sandbox through provider.
function createSandboxContext(provider: SandboxProvider): ExecutionContextParameters
| Name | Type | Description |
|---|---|---|
| provider | SandboxProvider | Sandbox backend that creates and drives sandboxes. |
Returns
Example
import { createAgent } from 'zidane'
import { createE2BProvider } from 'zidane/contexts/e2b'
import { createSandboxContext } from 'zidane/contexts/sandbox'
import { basic } from 'zidane/presets'
import { anthropic } from 'zidane/providers/anthropic'
const agent = createAgent({
...basic,
provider: anthropic(),
execution: createSandboxContext(createE2BProvider()),
})Interfaces#
SandboxProviderInterface#
Backend of a remote sandbox. Implement it to plug a sandbox service into createSandboxContext.
interface SandboxProviderProperties
| Name | Type | Description |
|---|---|---|
| destroy | (sandboxId: string) => Promise<void> | Destroys the sandbox and releases its resources. |
| exec | (sandboxId: string, command: string, options?: { cwd?: string; env?: Record<string, string>; timeout?: number }) => Promise<ExecResult> | Runs a command in the sandbox and returns its buffered output. |
| execStream? | (sandboxId: string, command: string, options?: { cwd?: string; env?: Record<string, string>; signal?: AbortSignal }) => Promise<StreamHandle> | Optional live bidirectional stream — see |
| listFiles | (sandboxId: string, path: string, options?: ListFilesOptions) => Promise<string[]> | Lists files under a path, or glob matches when |
| name | string | Provider name, such as |
| openTerminal? | (sandboxId: string, options: TerminalOptions) => Promise<TerminalProcess> | Optional interactive terminal — see |
| readFile | (sandboxId: string, path: string) => Promise<string> | Reads a text file from the sandbox. |
| reconnectTerminal? | (sandboxId: string, id: string, options: TerminalOptions) => Promise<TerminalProcess | null> | Re-attach to a terminal by id — see |
| spawn | (config: SpawnConfig) => Promise<{ cwd: string; id: string }> | Creates a sandbox and returns its id and working directory. |
| writeFile | (sandboxId: string, path: string, content: string | Buffer<ArrayBufferLike>, encoding?: BufferEncoding) => Promise<void> | Writes a file into the sandbox. |