Skip to main content

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

  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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autogen_fargate_executor-0.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

autogen_fargate_executor-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file autogen_fargate_executor-0.1.1.tar.gz.

File metadata

File hashes

Hashes for autogen_fargate_executor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 48a3ceb3a9f7ba0b8a8e0775b4c5064640ac9316879e865a8db9685fb517d348
MD5 91e92806a972d0537be0085e24855d38
BLAKE2b-256 0f09273fb1069bd9610a1d510dd7519468ec9d876059923cfa122aa3ec699ae9

See more details on using hashes here.

Provenance

File details

Details for the file autogen_fargate_executor-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for autogen_fargate_executor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc9461d46b55fa5bd15833db541ef5c95ee75538b4df541a2fa37ede18cf533b
MD5 467f778ab77e1aac4caeeee0ee84b1f8
BLAKE2b-256 972197f2d67075d2fa888c44dff3065db415df6bb192d510d6b565ec1c3247ce

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page