# Run Function in Virtual Machine does not change ai.vars

**URL:** <https://community.mindstudio.ai/t/run-function-in-virtual-machine-does-not-change-ai-vars/1929>\
**Category:** Support\
**Created:** [January 23, 2026, 8:53pm UTC](https://community.mindstudio.ai/t/run-function-in-virtual-machine-does-not-change-ai-vars/1929 "2026-01-23T20:53:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pj16](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@pj16](https://community.mindstudio.ai/u/pj16)\
**Post date:** [January 23, 2026, 8:53pm UTC](https://community.mindstudio.ai/t/run-function-in-virtual-machine-does-not-change-ai-vars/1929/1 "2026-01-23T20:53:53Z")

</div>

I am using Run Function to execute a prepared query on a remote database (MySQL). I am running it in the Virtual Machine since I must import the mysql2 package. The function successfully retrieves the data but when I assign an extracted string to a variable ( ai.vars.rawtext) it is not available in subsequent blocks through {{rawtext}}. The console.log statements inside the function show that ai.vars.rawtext is updated with the extracted string. But a display to user block shows {{rawtext}} to be its original value (from before the Run Function block). Is this a bug?

---

<div class="post-metadata">

**Author:** ![pj16](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@pj16](https://community.mindstudio.ai/u/pj16)\
**Post date:** [January 24, 2026, 9:51pm UTC](https://community.mindstudio.ai/t/run-function-in-virtual-machine-does-not-change-ai-vars/1929/2 "2026-01-24T21:51:49Z")

</div>

I see this is related to a different post [https://community.mindstudio.ai/t/cloudrunner-not-persisting-returned-variables-between-function-and-display-blocks/1782](https://community.mindstudio.ai/t/cloudrunner-not-persisting-returned-variables-between-function-and-display-blocks/1782). I have two run functions in my workflow, one to fetch input from the database and a second to save the output to the database. So, if ai.vars is cleared every time there is a run function block that might explain the lack of persistence.

---

<div class="post-metadata">

**Author:** ![Alex\_MindStudio](https://yyz2.discourse-cdn.com/flex008/user_avatar/community.mindstudio.ai/alex_mindstudio/32/27_2.png) [@Alex\_MindStudio](https://community.mindstudio.ai/u/Alex_MindStudio)\
**Post date:** [January 26, 2026, 4:46pm UTC](https://community.mindstudio.ai/t/run-function-in-virtual-machine-does-not-change-ai-vars/1929/3 "2026-01-26T16:46:03Z")

</div>

Hi @pj16,

That’s correct, the values are cleared, although you can pass values back into the workflow by assigning them to Output variables that you define in the block configuration.

Here’s a remix link to a sample Agent that uses two Custom Functions:  
[https://app.mindstudio.ai/agents/rdearmas–sample-agent-with-two-custom-functions-102f3d3e/remix](https://app.mindstudio.ai/agents/rdearmas--sample-agent-with-two-custom-functions-102f3d3e/remix)

Let me know if you have any questions!

---

<div class="post-metadata">

**Author:** ![pj16](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@pj16](https://community.mindstudio.ai/u/pj16)\
**Post date:** [January 26, 2026, 5:11pm UTC](https://community.mindstudio.ai/t/run-function-in-virtual-machine-does-not-change-ai-vars/1929/4 "2026-01-26T17:11:19Z")

</div>

Alex, Thank you for this response. It is good to see that there is a method for passing variables back to the workflow in this situation. Thanks for the link to the detailed solution. I found another workaround by passing in my data as part of webhookParams so I will stick with that for now. I appreciate the fast helpful response. My MindStudio project is a success.

Peter
