Update block docs for: code_executor.md

This commit is contained in:
Bently
2025-01-12 12:40:56 +00:00
parent a3955385ec
commit dc777ce89a

View File

@@ -0,0 +1,48 @@
## Code Execution Block
### What it is
A secure sandbox environment that allows users to execute code in various programming languages with internet access.
### What it does
This block provides a safe way to run code snippets in different programming languages (Python, JavaScript, Bash, R, and Java) within an isolated environment. It can also set up the environment with specific requirements before running the code.
### How it works
The block creates an isolated sandbox environment using E2B's infrastructure. It first runs any setup commands (if provided) to prepare the environment, then executes the provided code in the specified programming language. The sandbox includes internet access and pre-installed package managers like pip and npm.
### Inputs
- Credentials: Your E2B API key required to access the sandbox environment
- Setup Commands: Optional shell commands to prepare the environment (e.g., installing packages or downloading files)
- Code: The actual code you want to execute
- Language: Choice of programming language (Python, JavaScript, Bash, R, or Java)
- Timeout: Maximum time in seconds allowed for code execution (default: 300 seconds)
- Template ID: Optional E2B sandbox template ID for customized environments with specific CPU and memory configurations
### Outputs
- Response: The main output or return value from the code execution
- Standard Output Logs: Any text printed to standard output during execution
- Standard Error Logs: Any error messages or warnings printed during execution
- Error: Detailed error message if the code execution fails
### Possible use cases
1. Testing code snippets in different programming languages without setting up local development environments
2. Running data analysis scripts that require specific packages or dependencies
3. Teaching programming by providing a safe environment for students to experiment
4. Automating code testing with different environment configurations
5. Running resource-intensive computations in an isolated environment
6. Executing potentially risky code safely without compromising local system security
### Additional Notes
- The sandbox environment is completely isolated, making it safe to run untrusted code
- Internet access allows for downloading packages and accessing online resources
- Pre-installed package managers (pip and npm) facilitate easy dependency management
- The environment can be customized using setup commands or template IDs
- All executions are automatically terminated after the specified timeout period
- The system supports file operations, though currently, file upload and download features are in development
### Best Practices
1. Always set appropriate timeout values based on your code's complexity
2. Use setup commands to ensure all required dependencies are installed
3. Consider using template IDs for consistently configured environments
4. Monitor standard output and error logs for debugging purposes
5. Handle potential errors by checking the error output field