This directory contains comprehensive examples demonstrating various features of the AgentBay Python SDK.
examples/
├── _async/ # Async examples (Source of Truth)
│ ├── browser-use/
│ ├── codespace/
│ ├── common-features/
│ ├── computer-use/
│ └── mobile-use/
└── _sync/ # Sync examples (Auto-generated)
├── browser-use/
├── codespace/
├── common-features/
├── computer-use/
└── mobile-use/
_async/: Contains asynchronous examples usingAsyncAgentBayandasync/awaitsyntax_sync/: Contains synchronous examples usingAgentBay(auto-generated from async versions)
Both versions provide the same functionality. Choose based on your project requirements:
- Use async for modern async/await applications
- Use sync for traditional synchronous applications
Located in browser-use/browser/ and browser-use/extension/
Basic Browser Operations:
browser_screenshot.py- Taking screenshotsbrowser_viewport.py- Managing viewport sizesbrowser_type_example.py- Different browser types
Navigation and Interaction:
navigation_and_interaction.py- Browser navigation and element interactionpage_analysis.py- Page metadata and content extractionmulti_tab_management.py- Managing multiple browser tabs
Advanced Browser Features:
javascript_execution.py- Executing JavaScript in browser contextauthentication_flow.py- Handling authentication and login flowsresponsive_testing.py- Testing responsive design across viewportsnetwork_monitoring.py- Monitoring network requests and responsespopup_handling.py- Managing popups and dialogsiframe_handling.py- Working with iframes
File Operations:
file_upload_download.py- File upload/download operations
Browser Automation:
form_automation.py- Automated form fillingweb_scraping.py- Web scraping techniquescookies_management.py- Cookie managementlocal_storage_management.py- Local storage operationsscreenshot_comparison.py- Screenshot comparison
Browser Configuration:
browser_fingerprint_*.py- Browser fingerprintingbrowser_context_cookie_persistence.py- Cookie persistencebrowser-proxies.py- Proxy configurationbrowser_command_args.py- Browser command argumentsbrowser_replay.py- Browser session replay
Extension Development:
basic_extension_usage.py- Basic extension usageextension_development_workflow.py- Extension developmentextension_testing_automation.py- Extension testing
Real-world Examples:
search_agentbay_doc*.py- Documentation search examplesgame_*.py- Game automation examples- Various domain-specific examples
Located in codespace/
Development Environments:
python_development.py- Python environment setup and package managementnodejs_development.py- Node.js environment and npm operations
Version Control:
git_operations.py- Git repository initialization and commits
Containerization:
docker_operations.py- Docker container management
Data Management:
database_operations.py- SQLite database operations
Text Processing:
text_processing.py- Text manipulation with grep/sed/awk
System Operations:
system_monitoring.py- System resource monitoringfile_compression.py- File compression and archiving
Web Development:
web_server_setup.py- HTTP server setup and configuration
Build Systems:
build_automation.py- Build automation with Makefiles
Code Execution:
code_execution_example.py- Code execution patternsjupyter_context_persistence.py- Jupyter-like Python context persistence across consecutiverun_code()calls within the same session
Located in common-features/basics/ and common-features/advanced/
Basic Operations:
session_creation/- Creating and managing sessionscommand_execution_patterns.py- Various command execution patternsfile_operations_patterns.py- File operation patternsfile_system/- File system operationssession_info.py- Session information retrievalworking_directory.py- Working directory managementenvironment_setup.py- Environment variable configurationprocess_management.py- Process monitoring and managementdata_transfer.py- Data transfer operations
Session Management:
list_sessions/- Listing sessionsget/- Getting session informationsession_pause_resume/- Pausing and resuming sessionslabel_management/- Managing session labels
Data Persistence:
data_persistence/- Context synchronization and data persistencecontext_management/- Context managementarchive-upload-mode-example/- Archive upload modes
Advanced Features:
concurrent_sessions.py- Managing multiple sessions concurrentlyresource_cleanup.py- Proper resource cleanup patternserror_recovery.py- Error handling and recoveryerror_handling/- Comprehensive error handlingbatch_operations/- Batch operationsparallel_execution/- Parallel execution patternsmulti_session_management/- Multi-session coordination
Testing and Monitoring:
api_testing/- API testing patternsnetwork_testing/- Network diagnosticslogging_monitoring/- Logging and monitoringperformance_monitoring/- Performance monitoringscreenshot_download/- Screenshot operations
Infrastructure:
environment_variables/- Environment variable managementretry_mechanism/- Retry patterns with circuit breakersession_pooling/- Session pooling for efficiencyoss_management/- OSS operations
Filesystem:
filesystem_example/- Advanced filesystem operationsmcp_tool_direct_call/- MCP tool direct calls
Agent Integration:
agent_module/- Agent module usage
Located in computer-use/computer/
windows_app_management_example.py- Windows application management
Located in mobile-use/
mobile_get_adb_url_example.py- Getting ADB connection URLmobile_system/- Mobile system operations
pip install agentbayAsync version:
python python/docs/examples/_async/codespace/python_development.pySync version:
python python/docs/examples/_sync/codespace/python_development.pyMost examples require the AGENTBAY_API_KEY environment variable:
export AGENTBAY_API_KEY="your_api_key_here"import asyncio
from agentbay import AsyncAgentBay
from agentbay import CreateSessionParams
async def main():
client = AsyncAgentBay()
session = None
try:
# Create session
session_result = await client.create(
CreateSessionParams(image_id="linux_latest")
)
session = session_result.session
# Your code here
result = await session.command.execute_command("echo 'Hello'")
print(result.output)
finally:
if session:
await client.delete(session)
if __name__ == "__main__":
asyncio.run(main())from agentbay import AgentBay
from agentbay import CreateSessionParams
def main():
client = AgentBay()
session = None
try:
# Create session
session_result = client.create(
CreateSessionParams(image_id="linux_latest")
)
session = session_result.session
# Your code here
result = session.command.execute_command("echo 'Hello'")
print(result.output)
finally:
if session:
client.delete(session)
if __name__ == "__main__":
main()When adding new examples:
- Always create async version first in
_async/directory - Run the generation script to create sync version:
cd python make generate-examples-sync - Verify both versions work correctly
- Update this README with the new example
The sync examples are auto-generated from async examples. To regenerate:
cd python
python scripts/generate_sync.pyOr use the Makefile:
cd python
make generate-examples-sync- Check the API Documentation
- Visit the Guides
- See the Quickstart
These examples are part of the AgentBay SDK and follow the same license.