Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] When code_exectution_mode flag is set to unsafe and allow_code_execution its true, its doing docker validation #1983

Open
lasagna0 opened this issue Jan 27, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@lasagna0
Copy link

Description

Hi!

I’m using version 0.98.0 of CrewAI (the current version as I write this), and I noticed an issue when creating an agent with code execution enabled in unsafe mode. The agent unnecessarily tries to check for Docker, even though Docker isn’t required unless it’s explicitly going to be used.

For example:

analysis_agent = Agent(
    llm=llm,
    role="Analista de datos",
    goal="XXXX",
    backstory="XXX.",
    memory=True,
    # tools=[CodeInterpreterTool(unsafe_mode=True)],
    allow_code_execution=True,
    code_execution_mode="unsafe",
    verbose=True,
    max_retry_limit=5,
    verbose_tools=True,
    memory_config={
        "provider": "mem0",
        "config": {
            "user_id": "david",
        },
    }
)

I get the following error:

CalledProcessError                        Traceback (most recent call last)
File c:\Users\dsanchez\.conda\envs\FSD_env\lib\site-packages\crewai\agent.py:445, in Agent._validate_docker_installation(self)
    [444] try:
--> [445]     subprocess.run(
    [446]         ["docker", "info"],
    [447]         check=True,
    [448]         stdout=subprocess.PIPE,
    [449]         stderr=subprocess.PIPE,
    [450]     )
    [451] except subprocess.CalledProcessError:

File c:\Users\dsanchez\.conda\envs\FSD_env\lib\subprocess.py:526, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    [525]     if check and retcode:
--> [526]         raise CalledProcessError(retcode, process.args,
    [527]                                  output=stdout, stderr=stderr)
    [528] return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['docker', 'info']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
Cell In[2], [line 15]
     [12] from crewai_tools import CodeInterpreterTool
...
--> [452]     raise RuntimeError(
    [453]         f"Docker is not running. Please start Docker to use code execution with agent: {self.role}"
    [454]     )

RuntimeError: Docker is not running. Please start Docker to use code execution with agent: Analista de datos

This behavior doesn’t make sense because the validation for Docker is happening even when it’s unnecessary.

The problem is caused by this part of agent.py:

if self.allow_code_execution:
    self._validate_docker_installation()

It would make more sense if it were written as:

if self.allow_code_execution and self.code_execution_mode == "safe":
    self._validate_docker_installation()

This way, the validation for Docker would only occur when safe mode is explicitly enabled, aligning with the intended logic.

Steps to Reproduce

  1. Create an agent using the following configuration:
  2. Set allow_code_execution=True.
  3. Set code_execution_mode="unsafe".
  4. Ensure Docker is not installed or not running on your system.
  5. Run the code to instantiate the agent

The agent attempts to validate Docker installation via _validate_docker_installation(), even though Docker is not required when code_execution_mode="unsafe".
This results in an error if Docker is not running:
python
Copiar código
RuntimeError: Docker is not running. Please start Docker to use code execution with agent: Analista de datos

Expected behavior

  • Docker validation (_validate_docker_installation) should only occur when code_execution_mode="safe".
  • When code_execution_mode="unsafe", Docker validation should not be triggered, allowing the agent to run without issues.
  • The code should execute successfully in unsafe mode, even if Docker is not installed or running.

Screenshots/Code snippets

See general context

Operating System

Windows 11

Python Version

3.10

crewAI Version

0.98.0

crewAI Tools Version

0.32.1

Virtual Environment

Venv

Evidence

Image

Possible Solution

It would make more sense if it were written as:

if self.allow_code_execution and self.code_execution_mode == "safe":
    self._validate_docker_installation()

Additional context

NA

@lasagna0 lasagna0 added the bug Something isn't working label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant