Managed Agents

Run agents on cloud infrastructure with automatic provisioning and management

See also: Five-Layer Agent Stack — Managed Agents sit outside the stack (where the agent runs).

Managed Agents run on cloud infrastructure, automatically provisioning compute resources and managing execution environments.

Diagram

Managed Agents Flow

📝 Request

☁️ Cloud Agent

🛠️ Compute Environment

📋 Execution

✅ Results

Quick Start

  1. Basic Usage
    python
    from praisonaiagents import Agent
    from praisonai.integrations.managed_agents import ManagedAgent
    
    agent = Agent(name="teacher", backend=ManagedAgent())
    result = agent.start("Write a Python script that prints Hello World and run it")
    print(result)
  2. With Configuration
    python
    from praisonaiagents import Agent
    from praisonai.integrations.managed_agents import ManagedAgent, ManagedConfig
    
    managed = ManagedAgent(
        config=ManagedConfig(
            model="claude-sonnet-4-6",
            system="You are a helpful assistant. Be concise.",
            name="MyAgent",
            packages={"pip": ["pandas", "numpy"]},
        ),
        compute="docker"  # required for package installation
    )
    agent = Agent(name="data-analyst", backend=managed)
    result = agent.start("Analyze this data: [1,2,3,4,5]", stream=True)

How It Works

Diagram
CloudManagedAgentAgentUserCloudManagedAgentAgentUserRequestExecuteProvision EnvironmentEnvironment ReadyRun CodeResultsResponseFinal Output

Security Model

Managed agents enforce sandbox-first security by default. Package installation requires a compute provider or explicit opt-out to prevent host system security risks.

  • Compute-bridged tools: execute_command, read_file, write_file, list_files automatically execute in sandbox when compute provider is attached
  • ManagedSandboxRequired: Exception raised when packages are specified without proper sandboxing (see Local Provider security details)
ComponentPurposeManaged By
Agent DefinitionModel, system prompt, toolsCloud Provider
EnvironmentCompute resources, packagesCloud Provider
SessionConversation context, stateCloud Provider
ExecutionCode running, tool usageCloud Provider

Compute Providers

Managed Agents support multiple compute providers for different use cases:


Configuration Options

ManagedConfig API Reference

Complete configuration options for managed agents

Key Configuration Fields

OptionTypeDefaultDescription
modelstr"claude-haiku-4-5"LLM model to use
systemstr"You are a helpful coding assistant."System prompt
toolsList[Dict][{"type": "agent_toolset_20260401"}]Available tools
packagesDict[str, List[str]]NonePackage dependencies. Requires compute provider by default (security details)
networkingDict[str, Any]{"type": "unrestricted"}Network access policy

Custom Backend Development

Build a custom managed backend by implementing the protocol:

python
# Build a custom managed backend by implementing this protocol
from praisonaiagents.managed import ManagedBackendProtocol

Common Patterns

Environment with Packages

python
from praisonaiagents import Agent
from praisonai.integrations.managed_agents import ManagedAgent, ManagedConfig

managed = ManagedAgent(
    config=ManagedConfig(
        model="claude-sonnet-4-6",
        packages={
            "pip": ["pandas", "matplotlib", "requests"],
            "npm": ["@types/node", "axios"]
        },
        networking={"type": "limited"}
    ),
    compute="docker"  # required for secure package installation
)
agent = Agent(name="data-scientist", backend=managed)

Session Persistence

python
# Save session state
managed = ManagedAgent(config=config)
agent = Agent(name="persistent", backend=managed)
agent.start("Remember: my favorite color is blue")
ids = managed.save_ids()

# Resume in another process
managed2 = ManagedAgent(config=config)
managed2.restore_ids(ids)
managed2.resume_session(ids["session_id"])
agent2 = Agent(name="resumed", backend=managed2)
result = agent2.start("What is my favorite color?")  # Knows: blue

Custom Tools

python
def handle_calculator(tool_name, tool_input):
    expr = tool_input.get("expression", "0")
    return str(eval(expr, {"__builtins__": {}}))

managed = ManagedAgent(
    config=ManagedConfig(
        tools=[{
            "type": "custom",
            "name": "calculator",
            "description": "Evaluate math expressions",
            "input_schema": {
                "type": "object",
                "properties": {"expression": {"type": "string"}},
                "required": ["expression"]
            }
        }]
    ),
    on_custom_tool=handle_calculator
)

Best Practices

Choose the Right Compute Provider
  • Local: Development and testing with existing infrastructure
  • Docker: Isolated, reproducible environments
  • E2B: Quick prototyping and sandboxed execution
  • Modal: High-performance, scalable workloads
  • Daytona: Development environments with persistence
  • Tenki: Disposable Linux microVMs, provisioned in seconds
Manage Sessions Effectively

Save session IDs for resuming conversations across process restarts. Use save_ids() and restore_ids() to maintain context between runs.

Configure Security Appropriately

Use networking: {"type": "limited"} for untrusted code execution. Enable only required packages to minimize attack surface. The new host_packages_ok flag and ManagedSandboxRequired exception provide additional security controls – see Local Provider security details.

Monitor Resource Usage

Track token usage with retrieve_session() — returns a unified schema (id, status, title, usage) on all backends. See the SessionInfo Schema page for details.


Related