langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
53.43k stars 7.8k forks source link

"operation not permitted", execute a os command using python os and subprocess modules #10002

Closed jiusi9 closed 1 month ago

jiusi9 commented 1 month ago

Self Checks

Dify version

0.10.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

import os, subprocess package, but can not be executed. It always report "operation not permitted"

def main(command):
    import os, subprocess
    cmd = command

    try:
        print(cmd)
        output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
        print("Output:")
        result = output.decode('utf-8')
    except subprocess.CalledProcessError as e:
        result = f"Error executing grpcurl command: {e.output.decode('utf-8')}"

image

Can not allow to execute some OS command?

✔️ Expected Behavior

Hope to execute os command on sandbox containers.

❌ Actual Behavior

No response

dosubot[bot] commented 1 month ago

The issue you're encountering with executing OS commands using Python's os and subprocess modules in Dify's self-hosted Docker environment is likely due to security restrictions. Dify employs several security measures to prevent unauthorized execution of OS commands:

  1. Seccomp Whitelist Policy: This policy allows only specific system calls, which can prevent the execution of certain OS commands [1].

  2. File System Isolation: The environment is isolated, limiting the ability to execute commands that could affect the host system [1].

  3. Network Isolation: Separate network configurations further restrict unauthorized access [1].

These measures are in place to ensure a secure execution environment. If you need to execute specific commands, you might need to adjust the security settings or explore alternative approaches that comply with these restrictions.

To continue talking to Dosu, mention @dosu.

jiusi9 commented 1 month ago
def main() -> dict:
    import os
    hostname = os.popen("hostname")
    aaa = os.read(hostname)

    return {
        "result": hostname,
    }

image

crazywoola commented 1 month ago

See dify-sandbox's faq.