Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.declaw.ai/llms.txt

Use this file to discover all available pages before exploring further.

The Go SDK exposes stdio through sandbox.Stdio. Use Stdio.Start() to launch a process with an open stdin pipe, then send data, receive output, and close stdin or kill the process. For conceptual background see the Stdio feature overview.

sandbox.Stdio.Start(ctx, cmd, opts)(*StdioHandle, error)

Start a subprocess with an open stdin pipe.
handle, err := sandbox.Stdio.Start(ctx, "cat", &declaw.StdioStartOpts{
    Envs: map[string]string{"FOO": "bar"},
    User: "user",
    Cwd:  "/workspace",
})

StdioStartOpts

FieldTypeDefaultDescription
Userstring"user"User the process runs as.
Cwdstring""Working directory.
Envsmap[string]stringnilEnvironment variables merged into the process env.
Pass nil for opts to use all defaults.

StdioHandle

Handle for an interactive subprocess with stdin pipe.

Fields

  • handle.CmdID string — server-assigned command identifier.

Methods

handle.SendStdin(ctx, data) error

Send data to the process’s stdin. Data is []byte.
handle.SendStdin(ctx, []byte("hello\n"))

handle.CloseStdin(ctx) error

Close the process’s stdin pipe, sending EOF.

handle.Kill(ctx) error

Terminate the process.

handle.Wait(ctx) (*StdioResult, error)

Block until the process exits. Equivalent to calling Stream with no callbacks.
result, err := handle.Wait(ctx)
fmt.Println(result.ExitCode)

handle.Stream(ctx, opts) (*StdioResult, error)

Connect to the SSE output stream and deliver stdout/stderr chunks via callbacks. Blocks until the process exits or the context is cancelled.
result, err := handle.Stream(ctx, &declaw.StdioStreamOpts{
    OnStdout: func(data []byte) {
        fmt.Print(string(data))
    },
    OnStderr: func(data []byte) {
        fmt.Fprint(os.Stderr, string(data))
    },
})

StdioStreamOpts

FieldTypeDescription
OnStdoutfunc(data []byte)Callback invoked for each stdout chunk.
OnStderrfunc(data []byte)Callback invoked for each stderr chunk.
Pass nil for opts to drain the stream without callbacks (same as Wait).

StdioResult

type StdioResult struct {
    ExitCode int
}
ExitCode is -1 if the stream ended without a clean exit frame.