crewAIInc/crewAI · error · ImportError

Could not import daytona.CodeRunParams while building argv/e

Error message

Could not import daytona.CodeRunParams while building argv/env for sandbox.process.code_run. This usually means the installed 'daytona' SDK is too old or incompatible. Upgrade with: pip install -U 'crewai-tools[daytona]'

What it means

DaytonaCodeExecutionTool._build_code_run_params imports daytona.CodeRunParams from the Daytona SDK only when the caller supplies argv or env. If that import fails, the tool raises ImportError with an explicit remediation message, chaining the original ImportError. It means the installed daytona package predates CodeRunParams (or is broken), so per-call argv/env cannot be forwarded to sandbox.process.code_run.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/daytona_sandbox_tool/daytona_python_tool.py:71

            return {
                "exit_code": getattr(response, "exit_code", None),
                "result": getattr(response, "result", None),
                "artifacts": getattr(response, "artifacts", None),
            }
        finally:
            self._release_sandbox(sandbox, should_delete)

    def _build_code_run_params(
        self,
        argv: list[str] | None,
        env: dict[str, str] | None,
    ) -> Any | None:
        if argv is None and env is None:
            return None
        try:
            from daytona import CodeRunParams
        except ImportError as exc:
            raise ImportError(
                "Could not import daytona.CodeRunParams while building "
                "argv/env for sandbox.process.code_run. This usually means the "
                "installed 'daytona' SDK is too old or incompatible. Upgrade "
                "with: pip install -U 'crewai-tools[daytona]'"
            ) from exc
        kwargs: dict[str, Any] = {}
        if argv is not None:
            kwargs["argv"] = argv
        if env is not None:
            kwargs["env"] = env
        return CodeRunParams(**kwargs)

View on GitHub (pinned to 754d7323be)

Solutions

  1. Upgrade the SDK: pip install -U 'crewai-tools[daytona]' (or uv add 'crewai-tools[daytona]').
  2. If you must not upgrade, drop the argv/env arguments — plain code execution works without CodeRunParams.
  3. Verify with python -c "from daytona import CodeRunParams" that the symbol now resolves.
  4. Check pip show daytona for the installed version against the SDK changelog if problems persist.

Example fix

# before: old SDK + argv/env
uv pip install 'daytona==0.5.0'
tool._run(code='print(1)', argv=['python', '-u'])

# after
uv pip install -U 'crewai-tools[daytona]'
tool._run(code='print(1)', argv=['python', '-u'])
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util

def daytona_supports_code_run_params() -> bool:
    return importlib.util.find_spec('daytona') is not None and _has_symbol()

def _has_symbol() -> bool:
    try:
        import daytona  # noqa: F401
        from daytona import CodeRunParams  # noqa: F401
        return True
    except ImportError:
        return False

# gate the feature
if argv or env:
    assert daytona_supports_code_run_params(), 'upgrade: pip install -U "crewai-tools[daytona]"'

Try / catch

try:
    tool._run(code=src, argv=argv, env=env)
except ImportError as e:
    if 'CodeRunParams' in str(e):
        result = tool._run(code=src)  # degrade: no argv/env forwarding
    else:
        raise

Prevention

When it happens

Trigger: Instantiating/calling the python execution tool with argv=['python','-u'] or env={'FOO':'1'} while an old daytona SDK (< the version introducing CodeRunParams) is installed; a partially installed/corrupted daytona package where the symbol is missing.

Common situations: Pinning daytona to an old version in requirements; environments where crewai-tools was installed without the [daytona] extra pulling a current SDK; using argv/env features against an SDK that never had them.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/5c21e784f4cc1087. Report an issue: GitHub.