Skip to main content
curator.CodeExecutor runs code for each row of a dataset and collects the output. This helps in cases like these.
  • You want only code that runs without errors in your training data. Open Thoughts used this method.
  • An LLM wrote code that draws a chart or renders a video, and you want the result.
  • You are building agents that use tools.

Example

A subclass of CodeExecutor has three methods.
  • code returns the Python code to run for a row. The code usually comes from the row, e.g., from a column that a curator.LLM step wrote.
  • code_input is optional. It returns the text that the code reads with input().
  • code_output gets the row and the result of the run, and returns the output row. The result has the attributes stdout, stderr, message, and error. The value of message is "success", "timeout", or "error".
Calling a CodeExecutor returns a Hugging Face Dataset. Like curator.LLM, the code executor caches its results. If a run stops, you can start it again without losing the work that finished. A progress display shows how the run is going.

Execution settings

Pass execution_params when you call the executor. timeout is the most seconds one run can take. The default is 10.

Backends

The backend decides where the code runs. Curator uses the bespokelabs-sandbox package for this, and you choose the backend with the backend argument.
The local backend runs the code directly on your machine. It is fast and needs no setup, but it is the least safe choice for code you do not trust. Use a container or cloud backend for that code.
The old name multiprocessing still works and means local.

Local

Docker

Install Docker, e.g., Docker Desktop, and make sure it is running. Curator uses the python:3.12-slim image by default. To use a different image, set image in backend_params.

Ray

Use Ray when your dataset is too large to run on one machine. Set the RAY_ADDRESS environment variable to the address of your Ray cluster. If it is not set, Ray starts a local cluster.

E2B

E2B is a paid service. Create an account on the E2B website, then set your key.

Backend settings

More examples

The code execution examples on GitHub include a chart generator and a pipeline that renders math videos. If you have questions, ask in the Bespoke Labs Discord.