dify icon indicating copy to clipboard operation
dify copied to clipboard

Code block cannot be executed correctly in javascript language

Open shadididi opened this issue 1 year ago • 12 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [X] Please do not modify this template :) and fill in all the required fields.

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 5. 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.

shadididi avatar Aug 27 '24 07:08 shadididi

@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.

dosubot[bot] avatar Aug 27 '24 07:08 dosubot[bot]

I was unable to reproduce it using version 0.7.2. image

image

moyueheng avatar Aug 27 '24 09:08 moyueheng

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?

shadididi avatar Aug 27 '24 09:08 shadididi

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

sulgweb avatar Aug 27 '24 09:08 sulgweb

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

moyueheng avatar Aug 27 '24 10:08 moyueheng

same version same issue here

jojotechs avatar Aug 28 '24 14:08 jojotechs

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

crazywoola avatar Sep 06 '24 05:09 crazywoola

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

shadididi avatar Sep 06 '24 06:09 shadididi

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.

Yeuoly avatar Sep 06 '24 10:09 Yeuoly

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.

shadididi avatar Sep 07 '24 08:09 shadididi

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.

Yeuoly avatar Sep 08 '24 09:09 Yeuoly

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

walkwolf avatar Sep 10 '24 05:09 walkwolf

@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@shadididi 你好!👋 我可以帮你处理错误报告、解答问题,并指导你成为一名贡献者。让我们一起解决问题吧!

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:我发现了一些与Dify工作流中JavaScript代码块出现“操作不允许”错误相关的类似问题和讨论。以下是一些相关的帖子及其建议的解决方案:

  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.文件权限:确保挂载到Docker容器中的目录和文件具有正确的权限。容器内的用户应具备对这些目录进行读写的必要权限。
    • 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.更新Docker Compose文件:确保docker-compose.yaml文件中的volumes部分正确将主机目录映射到容器目录,并且权限设置正确。
    • Set Correct Permissions on Host: Use the chmod command to set the correct permissions on the host directories.在主机上设置正确的权限:使用chmod命令在主机目录上设置正确的权限。
    • Run Docker Containers as a Specific User: Try running the Docker containers as a specific user who has the necessary permissions.以特定用户身份运行Docker容器:尝试以具有必要权限的特定用户身份运行Docker容器。
    • Convert Files to Unix Format: If you are using Windows, convert certain files to Unix format to avoid permission issues.将文件转换为Unix格式:如果您使用的是Windows,请将某些文件转换为Unix格式,以避免权限问题。
  3. JavaScript Code Execution Constraints:JavaScript代码执行限制: The "operation not permitted" error in your JavaScript code block is likely due to the restrictions and validations imposed by the 你的JavaScript代码块中出现的“操作不被允许”错误可能是由于所施加的限制和验证导致的。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.字符串长度验证:确保任何字符串输出的长度不超过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.数字范围验证:确保任何数字输出都在dify_config.CODE_MAX_NUMBERdify_config.CODE_MIN_NUMBER定义的范围内。
    • Precision Validation: Ensure that the precision of floating-point numbers does not exceed dify_config.CODE_MAX_PRECISION.精度验证:确保浮点数的精度不超过dify_config.CODE_MAX_PRECISION
    • Depth Validation: Ensure that the depth of nested objects does not exceed dify_config.CODE_MAX_DEPTH.深度验证:确保嵌套对象的深度不超过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).数组长度验证:确保数组的长度不超过配置的限制(dify_config.CODE_MAX_NUMBER_ARRAY_LENGTHdify_config.CODE_MAX_STRING_ARRAY_LENGTHdify_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].检查dify_config中定义的约束条件,并确保你的JavaScript代码遵守这些约束。此外,确保你的代码不会尝试执行沙箱环境中不允许的任何受限操作[1][2][3]

To continue talking to Dosu, mention @dosu.要继续与Dosu交谈,请提及@dosu

Image

I am very confused as to why such a simple Python script occasionally throws an "error: operation not permitted" error, which clearly should not involve system calls.

Although this is an occasional problem, it will cause a large workflow to be terminated frequently, which is a very bad experience.

here is script

def main(lenStr: str):
    return {
        "result": int(lenStr),
    }

fengwk avatar Nov 18 '25 06:11 fengwk