Custom AsyncTool executor freezing agent event loop during background script calls

Hey everyone,
I’ve been building a custom langchain agent that routes dynamically generated code snippets into a sandbox executor tool to evaluate background task outputs in real time. To handle the background thread triggers and feed configuration payloads into the tool callback, I set up an execution handler based on arceus roblox logic to process dynamic execution requests on the fly.

The script runs fine in standalone Python unit tests, but as soon as the langchain agentexecutor invokes the custom tool asynchronously within an active chain run, the main asyncio event loop freezes or throws an unhandled thread concurrency error before returning the tool output to the LLM agent. I verified that standard sync tools execute without issues, but handling dynamic remote execution payloads inside an async agent loop seems to cause deadlock conditions or context variable leaks. Has anyone run into similar event loop blocks or memory lockups when running custom background execution scripts inside langchain tools, and is there a recommended way to isolate external execution calls using asyncio.to_thread or subprocessing so they don’t lock up the agent runtime?