CodeAgent generates, executes, reviews, and refactors code, and only runs code when you name an explicit executor.
Quick Start
1
Run code with an explicit executor
2
Generate, review and refactor
Why an explicit executor?
Execution is granted by naming a runner, never by flipping a boolean. Withoutcode.executor, execute() returns { success: false, error: 'No code executor is configured...' }. This is deliberate, so model-generated code cannot silently run in-process.
How It Works
CodeConfig
createSubprocessExecutor()
createSubprocessExecutor() is a ready-made out-of-process runner.
- Runs a detached child on non-Windows so the timeout kills the whole process group.
- Truncates output live during streaming, not after close.
- An unregistered language returns
{ success: false, error: "No interpreter is registered for '<lang>'. Known: ..." }.
Set
PRAISONAI_PYTHON to override the interpreter used for python / python3.Writing your own executor
Supply aCodeExecutor to target a container, microVM, e2b, or a remote sandbox service.
CodeExecutor signature:
CodeExecutorContext carries sandbox, timeout, workingDirectory, environment, and maxOutputLength.
Best Practices
Name an executor explicitly
Name an executor explicitly
Never rely on a boolean to enable execution. Pass
createSubprocessExecutor() or your own runner so execution is a visible decision.Restrict allowed languages
Restrict allowed languages
Set
allowedLanguages to only the languages you expect. execute() rejects any other language before the executor runs.Isolate untrusted code
Isolate untrusted code
Supply a container or microVM executor for model-generated or user-supplied code. The subprocess runner shares the host.
Bound output and time
Bound output and time
Keep
maxOutputLength and timeout sensible. Output is capped as it streams and the timeout kills the whole process tree.Related
Sandbox
The generic Agent
executeCode() sandbox (separate API)Agent
Agent configuration and capabilities
Placement
Where agents run

