Metadata
Sandbox metadata
Section titled “Sandbox metadata”Metadata is a way to attach arbitrary key-value pairs for a sandbox.
This is useful in various scenarios, for example:
- Associate a sandbox with a user session.
- Store custom user data for a sandbox like API keys.
- Associate a sandbox with a user ID and connect to it later.
You specify metadata when creating a sandbox and can access it later through listing running sandboxes with Sandbox.list() method.
The metadata parameter is a dictionary of key-value pairs.
Tip: Tip: See List Sandboxes for more information.
from agentbox import Sandbox
sandbox = Sandbox(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
template="wemmodr8mb2uk3kn7exw",
timeout=60,
metadata={
"user_id": "12345",
})
# List running sandboxes and access metadata.
running_sandboxes = Sandbox.list(api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx")
print(running_sandboxes[0].metadata)
# Will print:
# {
# 'user_id': '12345',
# }
from agentbox import AsyncSandbox
sandbox = await AsyncSandbox.create(
api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx",
template="wemmodr8mb2uk3kn7exw",
timeout=60,
metadata={
"user_id": "12345",
})
# List running sandboxes and access metadata.
running_sandboxes = await Sandbox.list(api_key="ab_xxxxxxxxxxxxxxxxxxxxxxxxx")
print(running_sandboxes[0].metadata)
# Will print:
# {
# 'user_id': '12345',
# }
Filtering sandboxes by metadata
Section titled “Filtering sandboxes by metadata”You can also filter sandboxes by metadata, you can find more about it here