Bird
0
0

Consider this Python code snippet using a sandbox to run a risky operation:

medium📝 Predict Output Q13 of 15
Agentic AI - Agent Safety and Guardrails
Consider this Python code snippet using a sandbox to run a risky operation:
import sandbox
sandbox.start()
result = sandbox.run('2 + 2')
sandbox.stop()
print(result)

What will be printed?
A4
B'2 + 2'
CError: sandbox.run not defined
DNone
Step-by-Step Solution
Solution:
  1. Step 1: Understand sandbox.run behavior

    The sandbox.run method executes the string expression safely inside the sandbox.
  2. Step 2: Evaluate the expression '2 + 2'

    Evaluating '2 + 2' returns the integer 4, which is stored in result.
  3. Final Answer:

    4 -> Option A
  4. Quick Check:

    Sandbox runs code safely, output = 4 [OK]
Quick Trick: Sandbox.run executes string code safely and returns result [OK]
Common Mistakes:
  • Thinking sandbox.run returns the string itself
  • Assuming sandbox.run is undefined
  • Expecting None instead of result

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes