-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -59,7 +59,37 @@ spec: | |||||
|
|
||||||
| 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: | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo
Suggested change
|
||||||
| ```python | ||||||
| from agentic_sandbox import Sandbox | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The link to the SDK points to the README on the |
||||||
| # The SDK abstracts all YAML into a simple context manager | ||||||
| try: | ||||||
| with Sandbox( | ||||||
| template_name="python-runtime-template", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the namespace, the |
||||||
| namespace="ai-agents" | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using a hardcoded namespace like |
||||||
| ) as sandbox: | ||||||
|
|
||||||
| print("--- Sandbox is Ready! ---") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
|
|
||||||
| # 1. Run a command inside the secure sandbox | ||||||
| result = sandbox.run("echo 'Hello from inside the sandbox!'") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example doesn't check if the command executed successfully. The |
||||||
| print(f"Stdout: {result.stdout.strip()}") | ||||||
|
|
||||||
| # 2. Write and read files | ||||||
| sandbox.write("test.txt", "This is a test file.") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||
| content = sandbox.read("test.txt").decode('utf-8') | ||||||
| print(f"Read content: {content}") | ||||||
|
|
||||||
| except Exception as e: | ||||||
| print(f"An error occurred: {e}") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching the generic |
||||||
|
|
||||||
| # The 'with' block automatically handles cleanup | ||||||
| print("--- Sandbox Cleaned Up ---") | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
| For more complex examples, including how to use the extensions, please see the [examples/](https://github.com/kubernetes-sigs/agent-sandbox/blob/main/examples/) and [extensions/examples/](https://github.com/kubernetes-sigs/agent-sandbox/blob/main/extensions/examples/) directories. | ||||||
|
|
||||||
| ## Motivation | ||||||
|
|
||||||
|
|
||||||
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