AWS Fargate code executor for AutoGen - Run code securely and scale beyond local resources
Project description
AutoGen Fargate Executor
A code execution backend for AutoGen that runs code in AWS Fargate containers. This executor allows you to run untrusted code in isolated containers, making it suitable for production environments where code execution needs to be sandboxed.
Author
Iman Kamyabi
Email: engkamyabi@gmail.com
Features
- Executes code in isolated AWS Fargate containers
- Automatic creation of required AWS resources (ECS cluster, IAM roles, CloudWatch log groups)
- Support for installing pip dependencies
- Support for custom environment variables
- Support for requirements.txt file
- Integration with AutoGen's code execution interface
Installation
pip install autogen-fargate-executor
Or using Poetry:
poetry add autogen-fargate-executor
Prerequisites
- AWS credentials configured either through environment variables, AWS CLI, or IAM roles
- VPC with subnets and security groups configured for Fargate tasks
- Required AWS permissions to create:
- IAM roles and policies
- ECS clusters and tasks
- CloudWatch log groups
Usage
Basic Usage with AutoGen
from autogen_fargate_executor import FargateCodeExecutor
from autogen import ConversableAgent
# Initialize executor
executor = FargateCodeExecutor(
image_uri='python:3.11',
subnet_ids=['subnet-xxx'],
security_groups=['sg-xxx'],
)
# Create AutoGen agent with Fargate executor
agent = ConversableAgent(
name="CodeExecutor",
llm_config=False,
code_execution_config={"executor": executor},
is_termination_msg=lambda msg: "TERMINATE" in msg.get("content", "").strip().upper(),
)
Advanced Configuration
executor = FargateCodeExecutor(
region_name='us-west-2', # AWS region
image_uri='python:3.11', # Docker image to use
subnet_ids=['subnet-xxx'], # List of subnet IDs
security_groups=['sg-xxx'], # List of security group IDs
cluster_name='my-cluster', # Optional custom cluster name
cpu='512', # CPU units for Fargate task
memory='1024', # Memory (MB) for Fargate task
timeout_seconds=600, # Maximum execution time
requirements_file='requirements.txt', # Optional requirements file
pip_dependencies=['pandas', 'requests'], # Optional pip packages
environment_variables={ # Optional environment variables
'API_KEY': 'xxx',
'DEBUG': 'true'
}
)
AWS Resources
The executor will automatically create and manage these AWS resources:
- ECS Cluster (default name: autogen-executor-cluster)
- IAM Role (name: ecsTaskExecutionRoleAutoGenFargate)
- CloudWatch Log Group (name: /ecs/autogen-task)
Security Considerations
- Each code execution runs in its own isolated container
- Containers are terminated after code execution
- Resources are isolated within your VPC
- Task execution role follows principle of least privilege
- All container logs are captured in CloudWatch
Cost Considerations
This executor uses AWS Fargate, which bills based on:
- vCPU and memory used per second
- CloudWatch logs storage and ingestion
- Data transfer costs
Consider configuring appropriate CPU and memory settings based on your workload.
Development
Running Tests
poetry install
poetry run pytest tests/
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file autogen_fargate_executor-0.1.1.tar.gz
.
File metadata
- Download URL: autogen_fargate_executor-0.1.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48a3ceb3a9f7ba0b8a8e0775b4c5064640ac9316879e865a8db9685fb517d348 |
|
MD5 | 91e92806a972d0537be0085e24855d38 |
|
BLAKE2b-256 | 0f09273fb1069bd9610a1d510dd7519468ec9d876059923cfa122aa3ec699ae9 |
File details
Details for the file autogen_fargate_executor-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: autogen_fargate_executor-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc9461d46b55fa5bd15833db541ef5c95ee75538b4df541a2fa37ede18cf533b |
|
MD5 | 467f778ab77e1aac4caeeee0ee84b1f8 |
|
BLAKE2b-256 | 972197f2d67075d2fa888c44dff3065db415df6bb192d510d6b565ec1c3247ce |