Skip to main content

replit-code-exec

An interface to interact with Replit's code-exec API.

This is an interface for the simpler use cases of https://replit.com/@luisreplit/eval-python, which is a stateless API that is optimized to be called from AI Agents so that they can perform numerical reasoning through the evaluation of generated Python code. In general, this allows the execution of an untrusted snippet of Python code and returns whatever is printed to standard output / standard error as the result. The execution is done inside an ephemeral unprivileged container created on the fly running in Replit Deployments using https://github.com/omegaup/omegajail as code sandbox.

To set up your own copy of the API server, you need to follow these easy 2-3 steps (the second is optional):

  1. Open the https://replit.com/@luisreplit/eval-python in your browser and Fork it to your account.
  2. (Optional): if you want to change the Docker container, run evalctl image ${DOCKER_IMAGE} (e.g. evalctl image python:3 or evalctl image replco/python-kitchen-sink:latest).
    • Open .replit and change the EVAL_FILENAME, EVAL_RUN_COMMAND, EVAL_ENV to suite the new container, if needed.
  3. Deploy the Repl! (just pressing Run is not enough)
    • This is only compatible with the Autoscale Deployments.
    • Make sure you set the EVAL_TOKEN_AUTH Deployments secrets when doing so for authentication.

Sample usage

Here is a small example of this library being used as a small math solver using OpenAI API:

import openai
import replit_code_exec

code_exec = replit_code_exec.build_code_exec(...)

def solve_math(prompt: str, model: str = 'gpt-3.5-turbo-0613') -> str:
    completion = openai.ChatCompletion.create(
        model=model,
        temperature=0.7,
        functions=[code_exec.openai_schema],
        function_call={"name": "code_exec"},
        messages=[
            {
                "role": "system",
                "content": ("You are an assistant that knows how to solve math " +
                            "problems by converting them into Python programs."),
            },
            {
                "role": "user",
                "content": ("Please solve the following problem by creating a Python " +
                            "program that prints the solution to standard output using " +
                            "`print()`: " + prompt),
            },
        ],
    )
    return code_exec.from_response(completion)

Release files for replit-code-exec 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for replit-code-exec 0.0.1
File Size Uploaded
replit_code_exec-0.0.1.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for replit-code-exec 0.0.1
File Interpreter ABI Platform
replit_code_exec-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / replit_code_exec-0.0.1.tar.gz

Download URL replit_code_exec-0.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e27d549609ffe07711be7fbe547d88ed58df73992f5bf048de25433179d5c1a6
BLAKE2b-256 checksum
How to use checksums
ec61b9aa903da3ff72f24a9bf327c9adfd630818bcba4e454f4a328b17aac937
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-1030-gcp

Release files / replit_code_exec-0.0.1-py3-none-any.whl

Download URL replit_code_exec-0.0.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8e5bc7de88a65ac2d42ece5549d1a1744db430bc2b2e2489dce80254f7a4fb3d
BLAKE2b-256 checksum
How to use checksums
1df614206db1d797c915b948b400922cb55682f612e24e82f85c56f563e8fe90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.10.6 Linux/5.19.0-1030-gcp

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page