Skip to main content

Package to run crew.ai generated code in a docker instance

Project description

crew-python-runner

Allows crew.ai agents to run python code in dockerized containers.

LLM code should not be run locally on your system, but we would like the ability of crew.ai agents to run Python code so they can see that it works.

crew_python_runner will take your agents code and run it in a Docker instance, so you can be sure that nothing bad will happen to your code.

Installation

You will need Docker installed on your system

pip install crew_python_runner

Note that crew_python_runner has a dependency on crewai[tools], which has quite a lot of dependencies; this is likely not an issue if you have crewai already in your virtual environment.

Setup

On importing, a docker container will start running in the background. The first time this happens, it may have to download the docker image that it uses (python:3.11) so it is suggested you run the command

python -c "import crew_python_runner"

Before using the library, as otherwise you may see a delay in usage. Alternatively, pull the image from docker yourself on the command line

docker image pull python:3.11

Usage

To use as a crew.ai tool:

from crew_python_runner import runner

# this is just an example - setup your agent however you like
programmer = Agent(
    role='Senior Python Programmer',
    goal='Write simple, well crafted and bug-free Python code',
    backstory='You are a skilled Python programmer with a passion for writing working Python code',
    tools=[python_runner])

If you want to test it yourself:

from crew_python_runner import runner
result = runner.run_python('print("Hello, World!"))

This returns a class with 2 variables, error_code, an integer, and output, a string of the python output. In this case error_code will be 0 (meaning no error) and output will be Hello, World!.

Future Enhancements

  • Another tool giving coder agents the ability to pip install packages.
  • The tool will auto-restart the docker instance if it falls over (which could be because of rogue code).
  • The ability to log all code and results.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

crew_python_runner-0.2.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file crew_python_runner-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for crew_python_runner-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdf2b39e98d2f61d095a40093a1438e57efc42f8adad05eb8f633a6edb601ca4
MD5 c52a7583cf006b9c58d07216c0549c56
BLAKE2b-256 0e64048e86fdb2fc702fc92f1a167ff82f6c90dfd4c17aaa5ef0099e2a7937b7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page