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
45.3k stars 6.36k forks source link

Code block cannot be executed correctly in javascript language #7699

Open shadididi opened 2 weeks ago

shadididi commented 2 weeks ago

Self Checks

Dify version

0.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Docker version 26.1.3, build b72abbb

  1. follow the guide to start dify service in docker;
  2. create a workflow;
  3. add a code block, and return the input parameter as output;
    function main({arg1}) {
    return {
        result: arg1
    }
    }
    image
  4. run it

✔️ Expected Behavior

code block works as expected that returns the correct value of the input parameter

❌ Actual Behavior

code block throws a error error: operation not permitted

image

I have tried to execute code in python and it works fine.

dosubot[bot] commented 2 weeks ago

@shadididi Hello there! 👋 I'm here to help you with bug reports, answer questions, and guide you to become a contributor. Let's tackle this together!

I found similar issues and discussions related to the "operation not permitted" error in JavaScript code blocks within Dify workflows. Here are some relevant threads and their suggested solutions:

  1. Similar Issues and Discussions:

  2. Suggested Solutions:

    • File Permissions: Ensure that the directories and files mounted into the Docker containers have the correct permissions. The user inside the container should have the necessary permissions to read/write to these directories.
    • Update Docker Compose File: Ensure that the volumes section in your docker-compose.yaml file correctly maps the host directories to the container directories and that the permissions are set correctly.
    • Set Correct Permissions on Host: Use the chmod command to set the correct permissions on the host directories.
    • Run Docker Containers as a Specific User: Try running the Docker containers as a specific user who has the necessary permissions.
    • Convert Files to Unix Format: If you are using Windows, convert certain files to Unix format to avoid permission issues.
  3. JavaScript Code Execution Constraints: The "operation not permitted" error in your JavaScript code block is likely due to the restrictions and validations imposed by the DifySandbox environment. Here are some potential reasons:

    • String Length Validation: Ensure that the length of any string output does not exceed dify_config.CODE_MAX_STRING_ARRAY_LENGTH.
    • Number Range Validation: Ensure that any numeric output is within the range defined by dify_config.CODE_MAX_NUMBER and dify_config.CODE_MIN_NUMBER.
    • Precision Validation: Ensure that the precision of floating-point numbers does not exceed dify_config.CODE_MAX_PRECISION.
    • Depth Validation: Ensure that the depth of nested objects does not exceed dify_config.CODE_MAX_DEPTH.
    • Array Length Validation: Ensure that the length of arrays does not exceed the configured limits (dify_config.CODE_MAX_NUMBER_ARRAY_LENGTH, dify_config.CODE_MAX_STRING_ARRAY_LENGTH, dify_config.CODE_MAX_OBJECT_ARRAY_LENGTH).

Review the constraints defined in the dify_config and ensure that your JavaScript code adheres to these constraints. Additionally, ensure that your code does not attempt to perform any restricted operations that are not permitted in the sandboxed environment [1][2][3].

To continue talking to Dosu, mention @dosu.

moyueheng commented 2 weeks ago

I was unable to reproduce it using version 0.7.2.

image image
shadididi commented 2 weeks ago

I was unable to reproduce it using version 0.7.2. image

image

that was confusing, just doesn't work in JS. I manually download the source file with tag 0.7.2 in my Mac, and just enter the docker dir of the project, execute docker compose up -d. Are there some steps that I missed?

sulgweb commented 2 weeks ago
image

same error. mac m1 pro,dify verision 0.7.2,Docker version 26.1.3, build b72abbb

moyueheng commented 2 weeks ago

I was unable to reproduce it using version 0.7.2. image

image

that was confusing, just doesn't work in JS. I manually download the source file with tag 0.7.2 in my Mac, and just enter the docker dir of the project, execute docker compose up -d. Are there some steps that I missed?

My deployment method is consistent with yours. My environment is Ubuntu 20.04, docker 26.0.0. dify 0.7.2

image
jojotechs commented 2 weeks ago

same version same issue here

crazywoola commented 1 week ago

Cant reproduce this as well, what's yours' sandbox version. Please try to upgrade to 0.2.6 @jojotechs @sulgweb @shadididi

shadididi commented 1 week ago

Cant reproduce this as well, what's yours' sandbox version. Please try to upgrade to 0.2.6 @jojotechs @sulgweb @shadididi

sandbox version is already 0.2.6

Yeuoly commented 1 week ago

Sorry for the confusion, but I can not reproduce this issue after several tries, and basic checks for nodejs all passes on Github actions, I have no idea which permission missed on your machine.

shadididi commented 6 days ago

Sorry for the confusion, but I can not reproduce this issue after several tries, and basic checks for nodejs all passes on Github actions, I have no idea which permission missed on your machine.

Have you tried in Mac machines ? I noticed that others have same problem in Mac m1 pro.

Yeuoly commented 5 days ago

Sorry for the confusion, but I can not reproduce this issue after several tries, and basic checks for nodejs all passes on Github actions, I have no idea which permission missed on your machine.

Have you tried in Mac machines ? I noticed that others have same problem in Mac m1 pro.

I'm currently using Mac M2, maybe it's an issue related to chips? I'm not sure, I do not have a machine with M1 right now.

walkwolf commented 3 days ago

I have same problom on mac m1 after update to 0.7.3. sandbox image: langgenius/dify-sandbox:0.2.7