Is it possible to execute typescript and javascript files using the existing code executors #6144
-
|
I want something like UnsafeLocalCodeExecutor that can only execute python and shell scripts but I want the functionality for typescript and javascript files |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
If you need JS/TS execution, Changing the code fence delimiter to The two practical routes are:
For example, the custom executor shape would be roughly: class NodeCodeExecutor(BaseCodeExecutor):
code_block_delimiters = [
("```javascript\n", "\n```"),
("```typescript\n", "\n```"),
]
def execute_code(self, invocation_context, code_execution_input):
# write code to a temp .js/.ts file, run node/tsx with timeout,
# return CodeExecutionResult(stdout=..., stderr=..., output_files=[])
...I would only extend the unsafe/local pattern for fully trusted code. A JS/TS executor has the same security problem as the Python unsafe executor, plus whatever filesystem/network access the local Node process has. If you want trusted local behavior, this is a clean custom executor path. If inputs can be untrusted, containerize before enabling execution. |
Beta Was this translation helpful? Give feedback.
If you need JS/TS execution,
UnsafeLocalCodeExecutorwill not do it out of the box because it is wired for Python execution. Code-fence changes alone will not switch the runtime.Changing the code fence delimiter to
javascriptortypescriptwould only change what blocks are extracted; it would not make the executor call Node,tsx,ts-node, etc.The two practical routes are:
BaseCodeExecutorand implementingexecute_code(...)to call your JS/TS runner withsubprocess.run(...).node,tsx, ornpx ts-nodeinstead of the current Python command.For example, the custom…