Execute commands, operate files, and run code in cloud environments
pip install wuying-agentbay-sdkBefore using the SDK, you need to:
- Register an Alibaba Cloud account: https://aliyun.com
- Get API credentials: AgentBay Console
- Set environment variable:
export AGENTBAY_API_KEY=your_api_key
from agentbay import AgentBay
# Create session
agent_bay = AgentBay()
result = agent_bay.create()
if result.success:
session = result.session
# Execute command
cmd_result = session.command.execute_command("ls -la")
print(cmd_result.output)
# File operations
session.file_system.write_file("/tmp/test.txt", "Hello World")
content = session.file_system.read_file("/tmp/test.txt")
print(content.content)- 📚 Quick Start Tutorial - Get started in 5 minutes
- 🎯 Core Concepts - Understand cloud environments and sessions
- 💡 Best Practices - Common patterns and tips
- 📖 Feature Guides - Complete feature introduction
- 🔧 Python API Reference - Detailed API documentation
- 💻 Python Examples - Complete example code
- ❓ FAQ - Quick answers
- 🔧 Troubleshooting - Problem diagnosis
# Create session
result = agent_bay.create()
if result.success:
session = result.session
# List sessions
sessions = agent_bay.list()
# Connect to existing session
session = agent_bay.connect("session_id")# Read/write files
session.file_system.write_file("/path/file.txt", "content")
content = session.file_system.read_file("/path/file.txt")
# List directory
files = session.file_system.list_directory("/path")# Execute command
result = session.command.execute_command("python script.py")
print(result.output)# Create context
context = agent_bay.context.get("my-project", create=True).context
# Create session with context
from agentbay.session_params import CreateSessionParams
from agentbay.context_sync import ContextSync, SyncPolicy
context_sync = ContextSync.new(context.id, "/mnt/data", SyncPolicy.default())
session = agent_bay.create(CreateSessionParams(context_syncs=[context_sync])).sessionThis project is licensed under the Apache License 2.0 - see the LICENSE file for details.