Sandbox cannot import datetime module #2291

Closed
opened 2026-02-21 17:43:58 -05:00 by yindo · 0 comments
Owner

Originally created by @jamesliu668 on GitHub (Apr 17, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a quesion, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I created a flow with code node. If I put the python code like below, it will work.

def main() -> dict:

    return {
        "result": "2024/4/17 17:35:42"
    }

But if I put code like this:

from datetime import datetime
def main() -> dict:

    return {
        "result": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    }

The node will give out an error:

Traceback (most recent call last): File "", line 40, in File "", line 2, in ModuleNotFoundError: No module named 'datetime' error: exit status 255

✔️ Expected Behavior

Print the datetime result

Actual Behavior

No module named 'datetime' error

Originally created by @jamesliu668 on GitHub (Apr 17, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a quesion, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Pleas do not modify this template :) and fill in all the required fields. ### Dify version 0.6.3 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I created a flow with code node. If I put the python code like below, it will work. ``` def main() -> dict: return { "result": "2024/4/17 17:35:42" } ``` But if I put code like this: ``` from datetime import datetime def main() -> dict: return { "result": datetime.now().strftime("%Y-%m-%d %H:%M:%S") } ``` The node will give out an error: > Traceback (most recent call last): File "<string>", line 40, in <module> File "<string>", line 2, in <module> ModuleNotFoundError: No module named 'datetime' error: exit status 255 ### ✔️ Expected Behavior Print the datetime result ### ❌ Actual Behavior No module named 'datetime' error
yindo added the 🐞 bug label 2026-02-21 17:43:58 -05:00
yindo closed this issue 2026-02-21 17:43:59 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#2291