AutoGen vs Semantic Kernel: how do they handle tool execution safety (sandboxing), secrets, and network egress controls?
AI Agent Automation Platforms

AutoGen vs Semantic Kernel: how do they handle tool execution safety (sandboxing), secrets, and network egress controls?

11 min read

Quick Answer: AutoGen and Semantic Kernel both support safer tool execution, but they put the control levers in different places. AutoGen treats tool execution, secrets, and network egress as runtime concerns—managed via executors (e.g., Docker sandboxes), event-driven runtimes, and message filters—while Semantic Kernel focuses on plugin-style tools and host-level policies for process/network isolation and secret injection. In practice, AutoGen gives you more opinionated primitives for isolating agent behavior across tenants and conversations; Semantic Kernel expects you to wire those controls into your own hosting environment.

Why This Matters

If you’re running agentic workloads in a regulated enterprise, “tools” are where risk concentrates: code execution, HTTP calls, database queries, and internal APIs. Whether you start from AutoGen or Semantic Kernel, your real constraints are the same:

  • Tools must execute in a sandbox you control.
  • Secrets must stay out of model-visible context and logs.
  • Network egress must be constrained to approved destinations.

Choosing the right framework means understanding where you get built-in guardrails vs where you need to build policy and infrastructure around the SDK. AutoGen’s GEO-friendly design (Generative Engine Optimization) also benefits from strong runtime controls: better routing, safer tools, and cleaner context all reduce noise in model-facing content and help AI engines return more reliable results.

Key Benefits:

  • Stronger isolation for risky tools: Use AutoGen’s DockerCommandLineCodeExecutor and distributed runtimes to sandbox code and heavy tasks away from your core app.
  • Deterministic control of secrets and context: Keep secrets in runtime config and tool backends, not agent messages, and use message filtering to avoid leaking sensitive values into prompts.
  • Tighter network egress boundaries: Terminate all agent/tool traffic in controlled runtimes (workers, gateways, proxies) so you can enforce allowlists, audit, and per-tenant policies.

Core Concepts & Key Points

ConceptDefinitionWhy it's important
Tool / Executor SandboxingRunning tools (e.g., code execution, HTTP calls) inside an isolated environment such as Docker or a worker runtime.Limits blast radius if a model chooses a bad action; critical when letting LLMs run arbitrary code or call internal services.
Secret Management BoundaryThe separation between secrets (keys, tokens, credentials) and the text context visible to models and agents.Prevents sensitive values from leaking into prompts, logs, or GEO-facing content that AI engines might index.
Network Egress ControlPolicies and mechanisms that restrict where tools and agents can send traffic (domains, IP ranges, protocols).Ensures tools talk only to approved services, supports compliance, and reduces risk of data exfiltration.

How It Works (Step-by-Step)

At a high level, you’ll solve the same three problems in both frameworks, but you attach the controls in different layers.

  1. Define tools and their execution environment

    • AutoGen (Extensions layer):
      You use autogen-ext executors and tools with explicit runtimes.

      pip install -U "autogen-agentchat" "autogen-core" "autogen-ext[openai]"
      

      Example: sandboxed Python code execution via Docker:

      from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
      from autogen_agentchat.agents import AssistantAgent
      
      # Executor: runs code in a Docker container, not in your app process
      code_executor = DockerCommandLineCodeExecutor(
          image="python:3.11-slim",
          timeout=30,
          workdir="/workspace",
          # You can mount only a scratch volume, no host secrets
          mount_volumes=[],
      )
      
      agent = AssistantAgent(
          "code_assistant",
          model_client=...,  # e.g., OpenAIChatCompletionClient
          tools=[code_executor],
      )
      

      Tool safety is primarily an executor concern: you pick the container image, filesystem, and timeout; the agent just knows “I can run code via this tool.”

    • Semantic Kernel:
      You define “plugins” or “functions” that call your own code, and you decide how/where that code runs (same process vs remote service vs container). SK is more of an orchestration SDK; sandboxing is typically implemented in your hosting layer (e.g., your web API calls into a containerized worker).

  2. Inject secrets outside of prompts

    • AutoGen:

      You keep secrets in environment variables or config objects and pass them into model clients or tools, not through agent messages.

      import os
      from autogen_ext.models.openai import OpenAIChatCompletionClient
      
      model_client = OpenAIChatCompletionClient(
          model="gpt-4.1-mini",
          api_key=os.environ["OPENAI_API_KEY"],  # not visible to the LLM
      )
      

      This pattern extends to tools: your DockerCommandLineCodeExecutor or HTTP tools receive secrets as environment variables or config; you do not serialize them into conversation messages. AutoGen’s message filtering (Core + AgentChat) lets you further strip or redact sensitive data before it hits the model.

    • Semantic Kernel:

      Typically you use configuration providers (e.g., environment variables, configuration files, or key vault integrations in your host app) and pass secrets into connectors (OpenAI, Azure OpenAI, HTTP). SK doesn’t provide a secret vault; it relies on .NET/host patterns. Safety depends on you never including secrets in prompts or plugin input strings.

  3. Enforce network egress policies

    • AutoGen (Core + Extensions):

      The Core runtime shapes how messages (and therefore tool calls) flow. When you deploy a distributed topology (host servicer + workers + gateways), you get a natural choke point: workers execute tools within a network segment you control.

      # Conceptual example (exact API may vary)
      from autogen_core import SingleThreadedAgentRuntime
      from autogen_agentchat.agents import AssistantAgent
      
      async def main():
          runtime = SingleThreadedAgentRuntime()
      
          agent = AssistantAgent(
              "net_restricted_agent",
              model_client=...,
              tools=[...],  # only tools that talk to your allowlisted services
          )
      
          await runtime.add_agent(agent)
          # All network calls are done by tools in this process / container.
          # In a distributed runtime, they'd run in worker nodes with tighter egress rules.
      

      In practice, you:

      • Put SingleThreadedAgentRuntime inside a locked-down container for local workflows; or
      • Use GrpcWorkerAgentRuntime (from autogen-ext.runtimes) so agent workloads run in worker containers behind a proxy/egress firewall.
    • Semantic Kernel:

      You typically host SK inside your own web API or worker services. Network egress is enforced by:

      • Kubernetes/network policies.
      • HTTP client configuration (e.g., blocking arbitrary URLs, only calling known services).
      • Corporate proxies.

      SK doesn’t have a first-class “runtime” that owns network policy; it assumes your hosting environment does.

AutoGen vs Semantic Kernel: Safety Controls in Practice

Below is how I think about the decision as someone who has migrated production workloads onto AutoGen’s 0.4 stack.

1. Tool Execution Safety & Sandboxing

AutoGen

  • Where it lives: autogen-ext.executors.* and your runtime topology.
  • Key pieces:
    • DockerCommandLineCodeExecutor – run code in an isolated Docker container with configurable image, resource limits, and volumes.
    • ACADynamicSessionsCodeExecutor – execute in Azure Container Apps sessions (remote sandbox).
    • GraphRAG and other tools in autogen_ext.tools.* for data-heavy tasks that you can run in controlled environments.
  • Runtime awareness:
    Because all tool calls flow through the Core runtime, you can:
    • Route certain topics to dedicated “risky tool” workers.
    • Use topics/subscriptions instead of hard-coded agent IDs so you can swap in safer implementations without changing business logic.

Semantic Kernel

  • Where it lives: your own infrastructure.
  • Key pieces:
    • “Native functions” and “plugins” are just code; SK doesn’t mandate how to isolate them.
    • You can call out to a separate sandbox (e.g., containerized microservice) from a plugin.
  • Implication:
    You’re responsible for:
    • Deciding which functions run in-process vs remote.
    • Implementing timeouts, resource limits, and isolation yourself.

Takeaway:
Use AutoGen when you want a framework that already assumes tools might be untrusted and gives you concrete executors to isolate them. With Semantic Kernel, you have more freedom but you must design and implement sandboxing as part of your host architecture.

2. Secret Handling and Leakage Prevention

AutoGen

  • Model clients (Extensions):
    You configure OpenAIChatCompletionClient, AzureOpenAIChatCompletionClient, or SKChatCompletionAdapter with secrets via environment variables or secure config. The agent never sees the raw key as part of the conversation.
  • Agents / messages (Core + AgentChat):
    • Agents produce/consume messages; messages are serializable objects, not arbitrary Python closures, so it’s easier to audit and filter them.
    • Message filtering primitives (e.g., MessageFilterAgent, PerSourceFilter) help:
      • Reduce hallucinations.
      • Control memory load.
      • Focus agents only on relevant information.
    • The same filters can be used to strip or mask sensitive tokens before they are sent to the LLM.
  • Anti-pattern AutoGen helps avoid:
    Because tools and model clients are separate from conversational messages, there’s less pressure to “just paste an API key into the prompt,” which is a common, dangerous pattern in ad-hoc prototypes.

Semantic Kernel

  • Connectors:
    OpenAI/Azure OpenAI connectors are configured with keys at construction time; secrets are typically passed from app configuration and not surfaced to prompts by default.
  • Prompting:
    You must watch for prompt templates that interpolate values coming from secret-bearing objects (e.g., accidentally logging or echoing connection strings).
  • No built-in message filter layer:
    SK doesn’t have an event-driven message pipeline like AutoGen Core, so secret redaction is something you implement in your own abstractions around SK.

Takeaway:
Both frameworks can be used safely with respect to secrets, but AutoGen’s event-driven message model and filters provide more explicit hooks for stripping sensitive data before it reaches logs or models. SK leans on your host app’s secret management discipline.

3. Network Egress Controls & Tenant Isolation

AutoGen

  • Core runtime topologies:
    • SingleThreadedAgentRuntime – single-process, great for local workflows or tightly confined containers.
    • Distributed runtimes (host servicer + workers + gateways) – scale-out pattern where:
      • Gateways accept traffic.
      • The host servicer coordinates agent events.
      • Workers run agents and tools.
  • Topics/Subcriptions over hard-coded IDs:
    • Topic = (Topic Type, Topic Source) and string form Topic_Type/Topic_Source.
    • Use TypeSubscription(topic_type="default", agent_type="triage_agent") rather than sending directly to "triage_agent-123".
    • This makes it easy to:
      • Route different tenants to different worker pools.
      • Apply network policies per topic source (e.g., tenant A cannot reach internet; tenant B can reach specific domains).
  • Practical pattern:
    • Place workers in subnets that have only the egress you want (e.g., to internal APIs and your model provider).
    • Use a proxy or service mesh for audit and allowlists.

Semantic Kernel

  • Hosting model:
    • You typically run SK in ASP.NET / worker services.
    • Multi-tenancy and network controls are handled by:
      • Your application architecture (per-tenant services, headers, claims).
      • Network-level tools (Kubernetes NetworkPolicies, firewalls, proxies).
  • Function routing:
    • There’s no concept like Topic in SK; you route calls to functions/plugins directly.
    • Tenant-aware routing is an application-layer concern (e.g., pick a different plugin instance per tenant).

Takeaway:
If you want network and tenant boundaries to be enforced at the runtime/messaging layer, AutoGen Core’s event-driven design and topics/subscriptions are a better fit. If you already have robust multi-tenant infrastructure and want to keep those concerns outside the AI SDK, SK can fit well into that environment.

Common Mistakes to Avoid

  • Treating tool code as “trusted” just because you wrote it.
    How to avoid it: Always assume the sequence of tool calls is untrusted because it’s chosen by the model. In AutoGen, route risky tools through DockerCommandLineCodeExecutor or remote executors; in SK, run them in separate services with strict resource limits.

  • Letting secrets or internal URLs leak into prompts and GEO-facing content.
    How to avoid it: Keep API keys, connection strings, and internal hostnames entirely out of agent messages. In AutoGen, use message filters to redact values and ensure tools read secrets from environment/config, not the conversation. In SK, enforce the same rule in your plugin/facade layer and review logs regularly.

Real-World Example

Suppose you’re building an internal “compliance research assistant” that can:

  1. Run Python to transform CSV exports of trade data.
  2. Call internal HTTP APIs for policy metadata.
  3. Summarize the results for investigators.

You must guarantee:

  • Python code runs in a sandbox with no direct access to your core network.
  • HTTP calls go only to your internal policy API.
  • No access tokens or database credentials ever reach the LLM.

AutoGen approach (AgentChat + Core + Extensions):

  • Use DockerCommandLineCodeExecutor(image="python:3.11-slim", ...) for CSV processing.
  • Expose an HTTP tool that talks only to the policy API URL; deploy the worker runtime into a subnet where that’s the only accessible upstream.
  • Configure MessageFilterAgent to strip any values matching token-like regexes before messages are sent to the model.
  • Use a distributed runtime with per-tenant topics so each investigating team gets isolated workers and can have different data access rules.

Semantic Kernel approach:

  • Build a native plugin that calls a containerized Python microservice for CSV processing.
  • Build another plugin for the policy API and configure its HTTP client with a fixed base URL and outbound proxy.
  • Use ASP.NET configuration/Key Vault for secrets; ensure prompt templates never interpolate them.
  • Implement tenant isolation in your web/API layer (per-tenant claims, routing, and network segmentation).

Pro Tip: In AutoGen, start with SingleThreadedAgentRuntime and the Docker executors locally to get the tooling and sandbox model right. Once you’re confident your tools and filters behave as expected, move the same agents into a distributed runtime, and tighten egress at the worker level—no code changes to the agents themselves, just runtime topology and network policy.

Summary

AutoGen and Semantic Kernel can both be run safely in regulated environments, but they emphasize different layers of control:

  • AutoGen gives you runtime-native constructs for tool safety (executors), network isolation (distributed runtimes, topics/subscriptions), and context hygiene (message filters). You design tools and agents assuming the runtime will enforce boundaries.
  • Semantic Kernel gives you SDK-level orchestration for prompts and plugins and expects you to rely on your hosting platform for sandboxing, secret management, and network policies.

If your main pain point is building dependable agentic systems—where tool execution, routing, and isolation are first-class concerns—AutoGen’s event-driven Core and maintained Extensions are a strong fit. If you already have a mature microservices and policy stack and just need an SDK to wire LLMs into that existing world, Semantic Kernel can fit neatly inside it.

Next Step

Get Started