E2B

Learn how to use the E2B node in StackAI to execute code in a secure, sandboxed environment. Discover available actions, input/output details, and best practices.

What is E2B?

The E2B node in StackAI allows you to execute code in a secure, sandboxed environment. This is ideal for running scripts, automating tasks, or processing data without exposing your main system to risk. E2B is designed for flexibility, supporting a wide range of coding and automation scenarios.


How to Use the E2B Node

To use the E2B node, add it to your StackAI workflow and configure it to execute your desired code. You can pass inputs from other nodes, specify code to run, and retrieve outputs for further processing. E2B is especially useful for custom logic, data transformation, or integrating with APIs not natively supported by StackAI.


Example of Usage

Suppose you want to process user input, run a Python script, and return the result:

  1. Add an Input node to collect user data.

  2. Connect the Input node to the E2B node.

  3. In the E2B node, specify the code you want to execute, referencing the input as needed.

  4. Connect the E2B node to an Output node to display the result.


Available Actions for E2B

Below are the most commonly used actions for the E2B node:

1. Run Code (run_code_e2b)

Description: Executes custom code in a sandboxed environment and returns the output.

Inputs

Name
Description
Required
Example

code

The code to execute (string)

Yes

print("Hello, World!")

language

Programming language (string)

Yes

python

inputs

Input variables (object/dictionary)

No

{"x": 5, "y": 10}

Showing 1-3 of 3 items

Configurations

Name
Description
Required
Example

connection_id

Connection ID for E2B (if required)

No

Showing 1-1 of 1 items

Outputs

Name
Description
Required
Example

result

Output of the executed code

Yes

Hello, World!

logs

Execution logs (if any)

No

...

error

Error message (if execution fails)

No

SyntaxError...

Showing 1-3 of 3 items

Example

Input:

{
  "code": "return x + y",
  "language": "python",
  "inputs": {"x": 5, "y": 10}
}

Output:

{
  "result": 15,
  "logs": "",
  "error": null
}

Best Practices

  • Always validate your code before running to avoid errors.

  • Use input variables to make your code reusable and dynamic.

  • Check the output and error fields to handle execution results gracefully.

  • For sensitive or resource-intensive tasks, ensure your code is optimized and secure.


Summary

The E2B node in StackAI is a powerful tool for executing custom code securely within your workflows. By leveraging its flexible input and output options, you can automate complex tasks, process data, and extend StackAI’s capabilities to fit your unique needs.

Last updated

Was this helpful?