Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:8beeeaaat Touchdesigner mcp Remote Code Execution

From Leeroopedia
Knowledge Sources
Domains Code_Execution, Remote_Procedure_Call
Last Updated 2026-10-28 22:13 GMT

Overview

A discipline for executing arbitrary code on a remote runtime from a controlled namespace, distinguishing between structured method calls (safe, attribute-resolution) and free-form scripts (flexible, full Textport-equivalent namespace) with single-line `eval` and multi-line `exec` semantics.

Description

When an AI agent needs to act on a live node graph, it does so by sending code to the runtime. Two execution modes serve different needs:

  • Structured method call: resolve a node by path, verify the method attribute exists and is callable, then invoke it with positional and keyword arguments. The result is JSON-serialized. This is the safe mode — the caller names a specific attribute, and the runtime validates it before calling.
  • Free-form script: execute a full Python script string in a namespace that mirrors the runtime's interactive Textport. Single-line expressions are `eval`'d (returning a value); multi-line scripts are `exec`'d with last-line result extraction. This is the flexible mode — the agent writes arbitrary Python, and the runtime captures stdout, stderr, and a `result` variable.

The key design problem is namespace construction. The script namespace must mirror the Textport so code is copy-paste compatible: `op`, `ops`, `me`, `parent`, `project`, `td`, and all `__main__` globals (absTime, OP type names, `tdu`, `ui`, etc.) are injected. A `result` sentinel distinguishes "no return value set" from "result is None."

Usage

Use the structured method call mode when:

  • The operation is a single, known method on a node (e.g. `inputConnectors[0].connect(target)`).
  • You want validation that the method exists and is callable before invoking.

Use the free-form script mode when:

  • The operation is multi-step or conditional and cannot be expressed as a single method call.
  • You need to probe the API surface interactively (e.g. `print(dir(op('/project1/text1')))`).
  • You need to write a verified script using signatures confirmed by prior lookup steps.

Theoretical Basis

Method call flow:

# Abstract algorithm description (NOT real implementation)
node = resolve(node_path)          # td.op(node_path); validate
if not hasattr(node, method):
    return error("method not found")
attr = getattr(node, method)
if not callable(attr):
    return error("not callable")
result = attr(*args, **kwargs)
return serialize(result)

Script execution flow:

# Abstract algorithm description (NOT real implementation)
namespace = {
    "op": td.op, "ops": td.ops, "me": ..., "parent": ...,
    "project": ..., "td": td,
    "result": no_result_sentinel,
}
namespace.update(__main__ globals)  # Textport compatibility

if is_single_line(script):
    try:
        namespace["result"] = eval(script, namespace)
    except SyntaxError:
        exec(script, namespace)  # statements like "import x"
else:
    exec(script, namespace)
    if result is no_result_sentinel:
        # try extracting last-line expression
        last_expr = script.strip().split("\n")[-1]
        namespace["result"] = eval(last_expr, namespace)

return {result, stdout, stderr}

The `no_result_sentinel` is a module-level `object()` — its identity check (`is`) distinguishes "unset" from `None`, which is a valid return value.

Practical Guide

When choosing between the two modes:

  • Prefer the structured method call for single, known operations — it validates before executing.
  • Use the script mode for probing (run `dir()` or `type()` calls to explore the API).
  • Always wrap scripts in try/finally for cleanup (e.g. destroy temporary nodes).
  • Set the `result` variable explicitly to return a value; otherwise the last-line expression is attempted.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment