-
Notifications
You must be signed in to change notification settings - Fork 60
Add snippet to readme #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add snippet to readme #194
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ArthurKamalov The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Welcome @ArthurKamalov! |
|
Hi @ArthurKamalov. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
✅ Deploy Preview for agent-sandbox canceled.
|
|
/ok-to-test |
barney-s
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this Python SDK example to the README. It's a great starting point for users. I have a few minor suggestions to make the snippet more robust and clearer, mostly around error handling and explaining the assumptions made in the example.
| try: | ||
| with Sandbox( | ||
| template_name="python-runtime-template", | ||
| namespace="ai-agents" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a hardcoded namespace like ai-agents might cause the example to fail for users who don't have this namespace created or don't have permissions to access it. Consider adding a comment mentioning that this namespace must exist, or suggest a more common default like default.
| print(f"Read content: {content}") | ||
| except Exception as e: | ||
| print(f"An error occurred: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching the generic Exception is a bit broad. If the SDK has its own exception types (e.g., for connection errors, sandbox creation failures), it would be better to catch those specifically. If not, a comment explaining that this is simplified for the example would be helpful.
| print(f"Stdout: {result.stdout.strip()}") | ||
| # 2. Write and read files | ||
| sandbox.write("test.txt", "This is a test file.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The write() method appears to take a string, while the read() method returns bytes that need decoding. This asymmetry in the API could be confusing. It would be clearer if the example showed encoding the string before writing, e.g., sandbox.write("test.txt", "This is a test file.".encode('utf-8')), to make the process more explicit.
| print("--- Sandbox is Ready! ---") | ||
| # 1. Run a command inside the secure sandbox | ||
| result = sandbox.run("echo 'Hello from inside the sandbox!'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example doesn't check if the command executed successfully. The result object from sandbox.run() should be checked for an error or a non-zero exit code to ensure the command didn't fail silently. A robust example should include error handling for the execution result.
| # The SDK abstracts all YAML into a simple context manager | ||
| try: | ||
| with Sandbox( | ||
| template_name="python-runtime-template", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the namespace, the template_name is hardcoded. It would be beneficial to add a small note explaining that this template must be available on the cluster for the example to work.
| For a more programatic approach you can use the [SDK](https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md) like the following: | ||
| ```python | ||
| from agentic_sandbox import Sandbox | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The link to the SDK points to the README on the main branch. This could become outdated. Consider linking to the directory /clients/python/agentic-sandbox-client/ instead, which is a more stable reference.
| This will create a new Sandbox named `my-sandbox` running the image you specify. You can then access the Sandbox using its stable hostname, `my-sandbox`. | ||
|
|
||
| For more complex examples, including how to use the extensions, please see the [examples/](examples/) and [extensions/examples/](extensions/examples/) directories. | ||
| For a more programatic approach you can use the [SDK](https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md) like the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use relative links so that it moves with git commits
| This will create a new Sandbox named `my-sandbox` running the image you specify. You can then access the Sandbox using its stable hostname, `my-sandbox`. | ||
|
|
||
| For more complex examples, including how to use the extensions, please see the [examples/](examples/) and [extensions/examples/](extensions/examples/) directories. | ||
| For a more programatic approach you can use the [SDK](https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md) like the following: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
| For a more programatic approach you can use the [SDK](https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md) like the following: | |
| For a more programmatic approach you can use the [SDK](https://github.com/kubernetes-sigs/agent-sandbox/blob/main/clients/python/agentic-sandbox-client/README.md) like the following: |
| namespace="ai-agents" | ||
| ) as sandbox: | ||
| print("--- Sandbox is Ready! ---") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove these prints, as this makes the example more verbose than necessary, and the focus should be on showing the syntax.
This PR adds a snippet with an example of SDK usage in the README file.