Secure Code Execution

Execute code securely using nsjail sandboxing. Works with Skills Knowledge Base to guide agent on code execution patterns.

Secure Code Execution

AI-generated

Summary

Execute code securely within an isolated sandbox using nsjail with configurable language, resource limits, network access, and import restrictions, returning the program's output and execution details.

Inputs

  • Default Language — Choose the default language (Python, JavaScript, Bash, or Auto-detect) to execute code if the code's language is not explicitly specified.
  • Max Execution Time (seconds) — Set the maximum allowed time in seconds for the code to run before termination.
  • Max Memory (MB) — Limit the maximum memory usage in megabytes for the code execution environment.
  • Enable Network Access — Optionally enable or disable network access during code execution (disabled by default for security).
  • Max Code Length (characters) — Specify the maximum allowed character length of the code to be executed.
  • Allowed Imports (Python) — Provide a comma-separated list of allowed Python modules that the executed code may import; leaving empty permits all imports but reduces security.
  • Enable Code Validation — Enable or disable pre-execution validation that warns about potentially dangerous code patterns.
  • Enable Credential Injection — Allow injection of credentials as environment variables visible to the executed code; credentials themselves are not exposed directly in code.
  • Credential Injection Notice — Notice explaining credential injection requires credentials supplied via the agent in a specific format for environment variable injection.

Output shape

a single string output containing the executed code's standard output or error messages, including exit code and errors if execution fails

Outputs runtime stdout or stderr of the executed script, prepended with exit status on failure. Execution is sandboxed with nsjail, applying language-specific configuration, resource limits, and security constraints. Execution errors or code validation warnings may be logged as node errors or warnings.

Examples

Example 1: Execute Python code with restricted imports.

Set Default Language to Python, specify allowed imports, enforce max execution time and memory, disable network access, and enable validation.

Example 2: Run JavaScript code snippet securely with auto-detection.

Leave Default Language as auto, set max code length and resource limits, disable network, and enable code validation, receiving script output as result.

Discussion