2025-05-23 13:53:44 +02:00
|
|
|
from daytona_sdk import CreateSandboxParams, Daytona
|
|
|
|
|
|
2025-05-29 14:20:03 +02:00
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
daytona = Daytona()
|
|
|
|
|
|
|
|
|
|
params = CreateSandboxParams(
|
|
|
|
|
language="python",
|
|
|
|
|
)
|
|
|
|
|
sandbox = daytona.create(params)
|
|
|
|
|
|
|
|
|
|
# Run the code securely inside the sandbox
|
|
|
|
|
response = sandbox.process.code_run('print("Hello World!")')
|
|
|
|
|
if response.exit_code != 0:
|
|
|
|
|
print(f"Error: {response.exit_code} {response.result}")
|
|
|
|
|
else:
|
|
|
|
|
print(response.result)
|
|
|
|
|
|
|
|
|
|
# Execute an os command in the sandbox
|
|
|
|
|
response = sandbox.process.exec('echo "Hello World from exec!"', cwd="/home/daytona", timeout=10)
|
|
|
|
|
if response.exit_code != 0:
|
|
|
|
|
print(f"Error: {response.exit_code} {response.result}")
|
|
|
|
|
else:
|
|
|
|
|
print(response.result)
|
|
|
|
|
|
|
|
|
|
daytona.delete(sandbox)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|