Running Other Languages
OSL provides the ability to execute code in other programming languages, specifically Python and JavaScript. This feature requires explicit permission from the user for security reasons.
Permissions System
Before running code in another language, you must request and receive permission from the user.
Requesting Permission
Checking Permission Status
You can check if a permission has been granted by examining window.permissions
:
Python Integration
Getting Python Permission
Example Permission Check
Running Python Code
Once permission is granted, use the py
command to execute Python code:
Example Python Integration
JavaScript Integration
Getting JavaScript Permission
Running JavaScript Code
Once permission is granted, use the eval
command to execute JavaScript code:
Example JavaScript Integration
Best Practices
Permission Management
Always request permissions before attempting to run foreign code
Check permission status before each execution
Handle cases where permission is denied
Code Safety
Validate and sanitize any dynamic code before execution
Be cautious with user-provided code
Consider security implications of running foreign code
Error Handling
Check for execution errors
Provide fallback behavior when permissions are denied
Handle syntax errors in foreign code gracefully
Example: Language Integration
Important Notes
Permissions must be requested at runtime
Permissions can be revoked by the user
Python and JavaScript execution environments are isolated
Output from Python is captured in the
data
variableJavaScript console output appears in the browser's developer tools
Code execution in other languages may have performance implications
Always validate and sanitize any dynamic code before execution
Last updated
Was this helpful?