Skip to content

Sandboxes

Python Sandbox

{{ pythonSandbox | script: "Python code to run" | maxTime: "Max execution time"  }}

Parameters

  • Script: The Python code to run within the sandbox
  • Max Time: Max execution time in milliseconds

Returns

Returns the code output

The pythonSandbox allows you to execute Python code within the mAIstro environment. It is designed for running and testing dynamic Python scripts, especially those generated from prompts or templates. Ensure you use extractCode after an LLM call to handle valid code execution within the sandbox.

python_sandbox

Example Usage 1

Let's create a script to calculate a falling object velocity:

<< name: timeInput, prompt: "Enter time in seconds:">>
{{ LLM  | prompt: "Write Python to calculate the velocity of an object after free fall for a given time which is: << name: timeInput, prompt: false >>. Make sure to output just the code with no explanations" | cache: "true" }}=>{{ extractCode  }}=>{{ variable  | name: "code" }}
{{ pythonSandbox  | script: "<< name: code, prompt: false >>" | maxTime: "1000" }}=>{{ variable  | name: "codeResult" | mode: "" | value: "" }}
The velocity of an object after free fall for << name: timeInput, prompt: false >> seconds is << name: codeResult, prompt: false >>

Will yield something like:

The velocity of an object after free fall for 10 seconds is 98 m/s
Example Usage 2

Let's create a script to calculate circle area based on its radius:

<< name: radiusInput, prompt: "Enter the radius of the circle:">>
{{ LLM  | prompt: "Write Python to calculate the area of a circle given the radius: << name: radiusInput, prompt: false >>. Make sure to output just the code with no explanations" | cache: "true" }}=>{{ extractCode  }}=>{{ variable  | name: "code" }}
{{ pythonSandbox  | script: "<< name: code, prompt: false >>" | maxTime: "1000" }}=>{{ variable  | name: "codeResult" | mode: "" | value: "" }}
The area of the circle with radius << name: radiusInput, prompt: false >> is << name: codeResult, prompt: false >>

Will yield something like:

The area of the circle with radius 12 is 452.3893421169302

JavaScript Sandbox

{{ javascriptSandbox | script: "JavaScript code to run" | maxTime: "Max execution time"    }}

Parameters

  • Script: The JavaScript code to run within the sandbox
  • Max Time: Max execution time in milliseconds

Returns

Returns the code output

The javascriptSandbox enables the execution of JavaScript code within the mAIstro environment. It is optimized for testing dynamic JavaScript, especially code generated from prompts or templates. Leverage native JavaScript features like the fetch API for making asynchronous requests and handling data from external sources. As with the Python Sandbox, use extractCode after LLM calls to ensure the code is properly extracted and executed.

javascript_sandbox

Example Usage 1

Let's fetch some data from an external API:

{{ LLM  | prompt: "Write JavaScript to fetch data from the the Json Placeholder endpoint. https://jsonplaceholder.typicode.com/todos/1" | cache: "true" }}=>{{ extractCode  }}=>{{ variable  | name: "code" }}
{{ javascriptSandbox  | script: "<< name: code, prompt: false >>" | maxTime: "1000" }}=>{{ variable  | name: "codeResult" }}
<< name: codeResult, prompt: false >>

Will yield something like:

{ "userId": 1, "id": 1, "title": "delectus aut autem", "completed": false }
Example Usage 2

Let's use browser localStorage to store a user input value:

<< name: storageKey, prompt: "Enter a key to store in localStorage:">>
<< name: storageValue, prompt: "Enter a value to store in localStorage:">>
{{ LLM  | prompt: "Write JavaScript to store << name: storageValue, prompt: false >> in localStorage under the key << name: storageKey, prompt: false >>, and then retrieve and log it to the console. Make sure to output just the code with no explanations" | cache: "true" }}=>{{ extractCode  }}=>{{ variable  | name: "code" }}
{{ javascriptSandbox  | script: "<< name: code, prompt: false >>" | maxTime: "1000" }}=>{{ variable  | name: "codeResult" }}
The value in '<< name: storageKey, prompt: false >>' localStorage key is '<< name: codeResult, prompt: false >>'
Will yield something like:

The value in 'name' localStorage key is 'JohnDoe'