CodeRunner
Runs code for environments that run programs, injected by the host.
@internote/canvas-sdkimport { CodeRunner } from '@internote/canvas-sdk';The shape is an event stream rather than a result: runs are long relative to a frame, output interleaves stdout and stderr, and the reader can stop one mid-flight.
#Fields
availabilityReturns whether running is possible right now. A method rather than a value, since a host answers live as sign-in settles.
CodeRunAvailabilitynotifyUnavailableCalled when the reader presses Run while running is unavailable. The button stays pressable on purpose, since a disabled control cannot explain itself, and this is where the host raises its own prompt. Absent means the press is ignored.
voidrunRuns a program, calling
onEvent for each frame. Resolves when the stream is fully consumed or aborted, and rejects on transport failure.Promise<void>#Example
const runner = ctx.runner;
if (!runner || !runner.availability().ok) return;
await runner.run(
{ identity: ctx.identity, language: 'python', code, fileName: 'exercise.py', signal },
(event) => { if (event.type === 'stdout') append(event.text); },
);Declared in packages/canvas-sdk/src/runner/index.ts:85.