Skip to content

StartCodeInterpreterSession

Source: src/AWS/BedrockAgentCore/StartCodeInterpreterSession.ts

Starts an isolated code-execution session on a code interpreter.

Bind a CodeInterpreter inside a function runtime to open sandboxed sessions; pair with InvokeCodeInterpreter to run code in the session and StopCodeInterpreterSession to end it. Provide AgentCore.StartCodeInterpreterSessionHttp on the Function effect to implement the binding.

// init
const startSession = yield* AgentCore.StartCodeInterpreterSession(interpreter);
const invoke = yield* AgentCore.InvokeCodeInterpreter(interpreter);
const stopSession = yield* AgentCore.StopCodeInterpreterSession(interpreter);
return {
fetch: Effect.gen(function* () {
// runtime
const session = yield* startSession({ sessionTimeout: "5 minutes" });
const result = yield* invoke({
sessionId: session.sessionId,
name: "executeCode",
arguments: { language: "python", code: "print(21 * 2)" },
});
const chunks = yield* Stream.runCollect(result.stream);
yield* stopSession({ sessionId: session.sessionId });
return HttpServerResponse.json({ chunks: Array.from(chunks) });
}),
};