Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/01_create_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Create and manage a sandbox"""

import os
import sys
import random
import string

Expand All @@ -12,7 +13,7 @@ def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand All @@ -32,12 +33,14 @@ def main():
result = sandbox.exec("echo 'Sandbox is ready!'")
print(result.stdout.strip())

return 0
except Exception as e:
print(f"Error: {e}")
return 1
finally:
if sandbox:
sandbox.delete()


if __name__ == "__main__":
main()
sys.exit(main())
8 changes: 6 additions & 2 deletions examples/01_create_sandbox_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"""Create and manage a sandbox (async variant)"""

import asyncio
import sys
import os
import sys
import random
import string

Expand All @@ -13,7 +15,7 @@ async def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand All @@ -33,12 +35,14 @@ async def main():
result = await sandbox.exec("echo 'Sandbox is ready!'")
print(result.stdout.strip())

return 0
except Exception as e:
print(f"Error: {e}")
return 1
finally:
if sandbox:
await sandbox.delete()


if __name__ == "__main__":
asyncio.run(main())
sys.exit(asyncio.run(main()))
7 changes: 5 additions & 2 deletions examples/02_create_sandbox_with_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
import os
import sys
import random
import string
import time
Expand Down Expand Up @@ -74,7 +75,7 @@ def main(run_long_tests=False):
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand Down Expand Up @@ -135,10 +136,12 @@ def main(run_long_tests=False):
tracker.record("Multiple health checks (5x)", multi_check_duration, "long_tests")
print(f" ✓ took {multi_check_duration:.1f}s")

return 0
except Exception as e:
print(f"\n✗ Error occurred: {e}")
import traceback
traceback.print_exc()
return 1
finally:
if sandbox:
print(" → Deleting sandbox...")
Expand All @@ -165,4 +168,4 @@ def main(run_long_tests=False):
)

args = parser.parse_args()
main(run_long_tests=args.long)
sys.exit(main(run_long_tests=args.long))
8 changes: 6 additions & 2 deletions examples/02_create_sandbox_with_timing_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import argparse
import asyncio
import sys
import os
import sys
import random
import string
import time
Expand Down Expand Up @@ -78,7 +80,7 @@ async def main(run_long_tests=False):
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand Down Expand Up @@ -143,11 +145,13 @@ async def main(run_long_tests=False):
)
print(f" ✓ took {multi_check_duration:.1f}s")

return 0
except Exception as e:
print(f"\n✗ Error occurred: {e}")
import traceback

traceback.print_exc()
return 1
finally:
if sandbox:
print(" → Deleting sandbox...")
Expand All @@ -174,4 +178,4 @@ async def main(run_long_tests=False):
)

args = parser.parse_args()
asyncio.run(main(run_long_tests=args.long))
sys.exit(asyncio.run(main(run_long_tests=args.long)))
8 changes: 5 additions & 3 deletions examples/03_basic_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Basic command execution"""

import os

import sys

import random
import string
Expand All @@ -13,7 +13,7 @@ def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand Down Expand Up @@ -43,12 +43,14 @@ def main():
)
print(result.stdout.strip())

return 0
except Exception as e:
print(f"Error: {e}")
return 1
finally:
if sandbox:
sandbox.delete()


if __name__ == "__main__":
main()
sys.exit(main())
6 changes: 4 additions & 2 deletions examples/03_basic_commands_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand Down Expand Up @@ -44,12 +44,14 @@ async def main():
)
print(result.stdout.strip())

return 0
except Exception as e:
print(f"Error: {e}")
return 1
finally:
if sandbox:
await sandbox.delete()


if __name__ == "__main__":
asyncio.run(main())
sys.exit(asyncio.run(main()))
7 changes: 5 additions & 2 deletions examples/04_streaming_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Streaming command output"""

import os
import sys


import random
Expand All @@ -13,7 +14,7 @@ def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand Down Expand Up @@ -50,12 +51,14 @@ def main():
on_stdout=lambda data: print(data.strip()),
)

return 0
except Exception as e:
print(f"Error: {e}")
return 1
finally:
if sandbox:
sandbox.delete()


if __name__ == "__main__":
main()
sys.exit(main())
8 changes: 6 additions & 2 deletions examples/04_streaming_output_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"""Streaming command output (async variant)"""

import asyncio
import sys
import os
import sys


import random
Expand All @@ -14,7 +16,7 @@ async def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand Down Expand Up @@ -51,12 +53,14 @@ async def main():
on_stdout=lambda data: print(data.strip()),
)

return 0
except Exception as e:
print(f"Error: {e}")
return 1
finally:
if sandbox:
await sandbox.delete()


if __name__ == "__main__":
asyncio.run(main())
sys.exit(asyncio.run(main()))
8 changes: 6 additions & 2 deletions examples/05_environment_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Environment variables in commands"""

import os
import sys


import random
Expand All @@ -13,7 +14,7 @@ def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand All @@ -37,12 +38,15 @@ def main():
)
print(result.stdout.strip())

return 0
except Exception as e:
print(f"Error: {e}")
return 1

finally:
if sandbox:
sandbox.delete()


if __name__ == "__main__":
main()
sys.exit(main())
9 changes: 7 additions & 2 deletions examples/05_environment_variables_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"""Environment variables in commands (async variant)"""

import asyncio
import sys
import os
import sys


import random
Expand All @@ -14,7 +16,7 @@ async def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand All @@ -38,12 +40,15 @@ async def main():
)
print(result.stdout.strip())

return 0
except Exception as e:
print(f"Error: {e}")
return 1

finally:
if sandbox:
await sandbox.delete()


if __name__ == "__main__":
asyncio.run(main())
sys.exit(asyncio.run(main()))
9 changes: 7 additions & 2 deletions examples/06_working_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""Working directory for commands"""

import os
import sys


import random
Expand All @@ -13,7 +14,7 @@ def main():
api_token = os.getenv("KOYEB_API_TOKEN")
if not api_token:
print("Error: KOYEB_API_TOKEN not set")
return
return 1

sandbox = None
suffix = "".join(random.choices(string.ascii_lowercase + string.digits, k=8))
Expand Down Expand Up @@ -41,12 +42,16 @@ def main():
result = sandbox.exec("cat src/main.py", cwd="/tmp/my_project")
print(result.stdout.strip())

return 0

except Exception as e:
print(f"Error: {e}")
return 1

finally:
if sandbox:
sandbox.delete()


if __name__ == "__main__":
main()
sys.exit(main())
Loading
Loading