ProgramInterpreterSpecification

Models & Types · AiDotNet.Configuration

Names the executable and argument template used to run one language inside the program sandbox.

For Beginners

To run a Python file you type python myfile.py. This class stores those two halves separately: the program to launch (python) and the arguments to give it ("{source}", where {source} stands for whichever temporary file the sandbox just wrote). Because it is only a template, you can point it at a specific interpreter on your machine, add flags such as -X utf8, or plug in a language this library has never heard of, without changing any code.

How It Works

A specification is a command line with holes in it. RunArgumentTemplate is expanded by replacing {source} with the full path of the file the sandbox wrote and {workspace} with the directory that holds it; both replacements are shell-quoted for the target platform, so a workspace path containing spaces is handled correctly and a path can never break out of its argument. Nothing else in the template is interpreted, so any flags the interpreter needs can be written literally.

CompileArgumentTemplate is the separate command that compiles or type-checks without running. Leaving it null is a statement of fact rather than a gap: a request that sets CompileOnly against a language with no compile command is refused instead of quietly executing the program, because silently running code that the caller asked only to compile is exactly the failure this sandbox exists to prevent.

Constructors

Constructor Summary
ProgramInterpreterSpecification(string executable, string runArgumentTemplate, string compileArgumentTemplate) Initializes an interpreter specification.

Properties

Property Summary
bool SupportsCompileOnly { get; } Gets whether this specification can satisfy a compile-only request.
string CompileArgumentTemplate { get; } Gets the argument template used to compile a program without running it, when one exists.
string Executable { get; } Gets the interpreter or compiler to launch.
string RunArgumentTemplate { get; } Gets the argument template used to run a program.

Methods

Method Summary
string Expand(string template, string sourcePath, string workspacePath, bool quoteWithDoubleQuotes) Expands a template against one workspace, quoting both substituted paths.
string QuoteForCommandLine(string value) Wraps a value in double quotes, escaping embedded quotes and trailing backslashes.
string QuoteForPosixShell(string value) Wraps a value in POSIX single quotes so a shell treats it as one literal token.

Fields

Field Summary
string SourcePlaceholder The placeholder replaced by the quoted full path of the written source file.
string WorkspacePlaceholder The placeholder replaced by the quoted full path of the isolated workspace directory.