Skip to main content

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

  1. AWS credentials configured either through environment variables, AWS CLI, or IAM roles
  2. VPC with subnets and security groups configured for Fargate tasks
  3. 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:

  1. ECS Cluster (default name: autogen-executor-cluster)
  2. IAM Role (name: ecsTaskExecutionRoleAutoGenFargate)
  3. CloudWatch Log Group (name: /ecs/autogen-task)

Security Considerations

  1. Each code execution runs in its own isolated container
  2. Containers are terminated after code execution
  3. Resources are isolated within your VPC
  4. Task execution role follows principle of least privilege
  5. All container logs are captured in CloudWatch

Cost Considerations

This executor uses AWS Fargate, which bills based on:

  1. vCPU and memory used per second
  2. CloudWatch logs storage and ingestion
  3. 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.

Metadata

Release files for autogen-fargate-executor 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autogen-fargate-executor 0.1.1
File Size Uploaded
autogen_fargate_executor-0.1.1.tar.gz 6.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autogen-fargate-executor 0.1.1
File Interpreter ABI Platform
autogen_fargate_executor-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / autogen_fargate_executor-0.1.1.tar.gz

Download URL autogen_fargate_executor-0.1.1.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
48a3ceb3a9f7ba0b8a8e0775b4c5064640ac9316879e865a8db9685fb517d348
BLAKE2b-256 checksum
How to use checksums
0f09273fb1069bd9610a1d510dd7519468ec9d876059923cfa122aa3ec699ae9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / autogen_fargate_executor-0.1.1-py3-none-any.whl

Download URL autogen_fargate_executor-0.1.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc9461d46b55fa5bd15833db541ef5c95ee75538b4df541a2fa37ede18cf533b
BLAKE2b-256 checksum
How to use checksums
972197f2d67075d2fa888c44dff3065db415df6bb192d510d6b565ec1c3247ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page